OpenCode is an open-source AI coding agent that provides intelligent assistance for software development. It's designed as a terminal-based tool with a client-server architecture, allowing AI agents to interact with codebases through various interfaces.
Key Characteristics:
- 100% open source alternative to Claude Code
- Provider-agnostic (supports Claude, OpenAI, Google, local models, etc.)
- Built with terminal-first philosophy by neovim users
- Client/server architecture supporting multiple frontends
- Built-in LSP support and code analysis capabilities
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Frontends │ │ Core Server │ │ AI Providers │
│ │ │ │ │ │
│ • TUI (SolidJS) │◄──►│ (Hono/Bun) │◄──►│ • Anthropic │
│ • Desktop App │ │ │ │ • OpenAI │
│ • Web Client │ │ • Tool Registry │ │ • Google │
│ • VSCode Ext │ │ • Session Mgmt │ │ • Local Models │
│ • GitHub Action │ │ • Agent System │ │ • etc. │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- Server: Hono-based API server handling sessions, tools, and AI interactions
- Tools: Extensible system for file operations, code analysis, web access, etc.
- Agents: Different AI personalities with varying permissions and capabilities
- Sessions: Persistent conversation contexts with project state management
- Frontends: Multiple UI implementations using the same backend API
- Purpose: Core business logic, CLI tool, and HTTP server
- Key Files:
src/index.ts- CLI entry point with yargs command structuresrc/server/server.ts- Main Hono server with API routessrc/agent/- Agent definitions and configurationssrc/tool/- Tool implementations (edit, read, grep, etc.)src/cli/cmd/tui/- Terminal User Interface commandsbin/opencode- CLI binary entry point
- Purpose: SolidJS-based web dashboard for OpenCode management
- Tech: SolidJS, Vite, TailwindCSS
- Usage: Project management, session history, configuration
- Purpose: Tauri-based desktop application
- Tech: Tauri, SolidJS, wraps the web app
- Platforms: macOS, Windows, Linux
- Purpose: Astro-powered documentation website
- Tech: Astro, Starlight, MDX
- Deployment:
docs.opencode.ai
- Structure: Monorepo with subpackages:
app/- Main SolidJS console applicationfunction/- Cloudflare Workers API endpointscore/- Shared business logicmail/- Email functionalityresource/- Resource management
- Purpose: API endpoints for OpenCode cloud services
- Tech: Hono, Cloudflare Workers
- Routes: GitHub integration, authentication, etc.
- Purpose: Auto-generated client SDK from OpenAPI spec
- Exports:
./client,./server,./v2/* - Usage: For frontend integrations and third-party developers
- Purpose: Define plugin APIs and tool interfaces
- Exports: Plugin types and tool definitions
- Usage: For extending OpenCode with custom tools
- Purpose: Reusable SolidJS components
- Tech: SolidJS, TailwindCSS
- Usage: Shared across web and desktop apps
- Purpose: Common TypeScript utilities and helpers
- Exports: Error handling, types, validation schemas
- Purpose: Self-hosted enterprise deployment
- Features: SSO, team management, private models
- Purpose: Slack bot integration for team usage
- Tech: Slack API, Bolt framework
- Purpose: Development automation and build tooling
- vscode/ - Visual Studio Code extension
- Keyboard shortcuts:
Cmd+Esc(open),Cmd+Shift+Esc(new tab) - Terminal integration with filepath insertion
- Keyboard shortcuts:
app.ts- SST configuration for main API and web assetsconsole.ts- SST configuration for console app and databaseenterprise.ts- Enterprise deployment configurationstage.ts- Stage/environment settings
script/generate.ts- SDK generation from API specsscript/publish-*.ts- Package publishing automation.github/workflows/- CI/CD pipelines.husky/pre-push- Pre-push hooks (type checking, bun version)
sst.config.ts- SST deployment configurationturbo.json- Turborepo build orchestrationbun.lock- Bun package manager lock file
- Bun 1.3+: Primary runtime, package manager, and build tool
- TypeScript 5.8: Main development language with strict typing
- ESM: Pure ES modules throughout
- Hono: HTTP framework for API server
- Cloudflare Workers: Serverless deployment platform
- SST (Serverless Stack): Infrastructure as Code
- Durable Objects: For WebSocket connections and sync
- PlanetScale: Managed MySQL database
- Stripe: Payment processing
- SolidJS: Reactive UI framework
- OpenTUI: Terminal User Interface library
- Tauri: Desktop app framework
- Astro: Documentation site generator
- TailwindCSS 4: CSS framework and styling
- Vercel AI SDK: Unified AI provider interface
- Multiple Providers: Anthropic, OpenAI, Google, Groq, etc.
- MCP (Model Context Protocol): For external tool integration
- Turborepo: Monorepo build system
- Zod: Runtime validation and schema definitions
- Tree-sitter: Syntax highlighting and code parsing
- LSP: Language Server Protocol integration
# Main CLI command
opencode [command] [options]
# Key commands:
opencode dev # Start TUI in current directory
opencode serve --port 4096 # Start server mode
opencode attach http://... # Connect to remote server
opencode github run # GitHub Action integrationpackages/opencode/src/index.ts- CLI bootstrappackages/opencode/src/server/server.ts- HTTP serverpackages/function/src/api.ts- Cloud API functionspackages/console/app/src/entry.tsx- Web console
- TUI:
packages/opencode/src/cli/cmd/tui/ - Desktop:
packages/desktop/src-tauri/src/main.rs - Web:
packages/app/src/index.tsx - VSCode:
sdks/vscode/src/extension.ts
package.json- Workspace configuration and shared dependenciessst.config.ts- Infrastructure deployment configurationturbo.json- Monorepo build pipelinebun.lock- Dependency lock file
packages/opencode/src/server/server.ts- Main API serverpackages/opencode/src/agent/agent.ts- Agent systempackages/opencode/src/tool/registry.ts- Tool registrypackages/opencode/src/session/- Session management
script/generate.ts- SDK generation from OpenAPI specsscript/publish-complete.ts- Package publishing pipeline.github/workflows/deploy.yml- CI/CD deployment
README.md- Main project documentationCONTRIBUTING.md- Contribution guidelinesAGENTS.md- Agent development guidelinesSTYLE_GUIDE.md- Code style conventions
# Install dependencies
bun install
# Start development
bun dev # Starts TUI in packages/opencode
bun turbo typecheck # Type checking across all packages
# Testing
bun test # Run tests in packages/opencode
bun turbo build # Build all packages- Type Check:
bun turbo typecheckacross all packages - Build: Individual packages with dependency resolution
- Generate:
script/generate.tsfor SDK from API specs - Deploy:
sst deployto Cloudflare Workers
- Pre-push hooks: Type checking and bun version validation
- Style Guide: Minimalist approach, single-function patterns
- Error Handling: Result patterns, avoid exceptions in tools
- Logging: Structured logging with
Log.create({ service: "name" })
- Version: Managed in package.json files
- Publish: Automated through GitHub Actions
- Distribution: npm, Homebrew, package managers, GitHub releases
// Custom tool implementation
export const CustomTool = Tool.define({
name: "custom_tool",
description: "Custom functionality",
input: z.object({ /* schema */ }),
async execute(input, context) {
// Tool implementation
}
})// Custom agent definition
export const CustomAgent = {
name: "custom",
description: "Custom agent",
permission: {
edit: "allow",
bash: { "default": "allow" }
},
tools: { /* tool permissions */ },
prompt: "Custom system prompt"
}- Tools: Extend with custom functionality
- Providers: Add new AI providers
- Formatters: Add language-specific code formatting
- LSPs: Add new language server support
- TUI: Extend SolidJS components in
packages/opencode/src/cli/cmd/tui/ - Web App: Add routes and components in
packages/app/ - Desktop: Extend Tauri functionality
- AI/ML:
@ai-sdk/*packages for provider abstraction - Web Framework:
honofor API server - CLI:
yargsfor command-line interface - UI:
@opentui/*,solid-jsfor terminal and web UI - File Operations:
@parcel/watcher,chokidar,ignore - Code Analysis:
tree-sitter,vscode-languageserver-types
- Build Tools:
vite,esbuild,typescript - Testing: Built-in Bun test runner
- Linting:
prettier,huskyfor code quality - Infrastructure:
sst,@cloudflare/workers-types
- Database: PlanetScale MySQL
- Storage: Cloudflare R2 buckets
- Authentication: GitHub OAuth, Google OAuth
- Payment: Stripe for enterprise features
- Monitoring: Honeycomb for log processing
This repository represents a sophisticated, production-ready AI coding assistant with a clean architecture designed for extensibility and maintainability. The modular structure allows for easy development of new features, tools, and integrations while maintaining consistency across all components.