Clients
Everything you interact with. All clients talk to the same local HTTP server over HTTP + SSE.
Core runtime (packages/core)
The engine: durable sessions, the agent loop, tools, and permissions. Built on Effect, event-sourced, persisted to SQLite.
Models & LLM
How models are chosen and how provider traffic flows.
Model providers
External LLM endpoints and gateways the runtime reaches with a resolved credential. OpenCode Zen/Go are first-party; the rest are direct provider plugins or OpenAI-compatible gateways.
Server & API
HTTP + SSE layer every client talks to.
MCP servers
External Model Context Protocol tool servers merged into the session tool set (filesystem, GitHub, etc.).
opencode (repo)
CodeMonorepo (Bun workspaces) on branch `dev`. Key packages: `packages/core` (runtime), `packages/opencode` (CLI/entrypoint), `packages/server` (HTTP API), `packages/tui` (terminal UI), `packages/llm` (native LLM client).
The open source coding agent.
Plugins
Extend opencode with tools, hooks (chat.message, tool.execute, permission.ask), providers, and config. npm-installed from opencode.json.
Agent loop (SessionRunner)
One provider turn at a time:
select agent, assemble system context, resolve model, call llm.stream, settle tool calls, then reload history and loop.
Headless CLI
opencode run — one-shot, non-interactive prompts that stream events to stdout.
Used for scripting and CI.
Desktop app
Electron app.
Spawns the headless server as a sidecar utility process and renders the web UI in a BrowserWindow.
HTTP server
Embedded server (opencode serve or embedded in TUI/desktop). Serves session, agent, tool, provider, permission, event routes with Basic auth + CORS. Effect HttpRouter backed by Core services.
LLM runtime
Default: Vercel AI SDK (streamText) adapting stream parts to LLMEvents. Opt-in: native @opencode-ai/llm route client (protocols: openai, anthropic, gemini, bedrock...).
Model catalog
CatalogV2 — merges the models.dev catalog, config providers, integrations, and credentials. Computes available models, the default, and a small model for chores.
Permissions
PermissionV2 — tools assert before acting.
Edits, writes, and bash ask the user by default; wildcard rules and saved rules are evaluated per call.
Project instance
Per-directory context loaded on each request: worktree / git project, loaded configuration, plugins, agents, MCP clients, LSP state, and active sessions.
Shared protocol
Single source of truth API contract (packages/protocol). OpenAPI spec at /openapi.json; server routes and generated clients both derive from it.
Anthropic
Direct provider plugin (@ai-sdk/anthropic). Connects with an API key or a Claude Pro/Max login.
OpenCode Go
Low-cost subscription tier billed through the OpenCode console (Stripe product 'ZenLite', name 'OpenCode Go'). UI tagline: 'Low-cost subscription for everyone'.
OpenAI
Direct provider plugin (@ai-sdk/openai). Connects with an API key or a ChatGPT account via OAuth integration.
+25 more providers
Google/Vertex, Groq, Mistral, Amazon Bedrock, OpenRouter, Perplexity, Together AI, X.AI, Azure, GitHub Copilot, Cloudflare, Cerebras, DeepInfra, Nvidia, ... Most ride @ai-sdk/* packages or OpenAI-compatible endpoints.
OpenCode Zen
First-party model gateway (provider id opencode). One API key unlocks curated coding models (Claude, GPT, Gemini, GLM...). Provider config fetched from the OpenCode console (opencode.ai/zen).
Session engine
SessionV2 — durable conversation state.
Admits prompts as durable events, projects messages, manages context epochs + compaction, handles interrupt/revert.
SQLite (durable store)
Drizzle + SQLite under ~/.local/share/opencode. Stores events, sessions, messages, context snapshots — event-sourced backbone.
System context
Versioned, refreshable context sources:
AGENTS.md instruction files (walked up from the project), environment info, date, skills.
Tool registry
Built-in tools: bash, read, write, edit, apply_patch, glob, grep, webfetch, websearch, todowrite, question, skill.
Materializes tool definitions and settles calls (decode → execute → bound output).
TUI (terminal)
Default experience (opencode).
SolidJS + OpenTUI app that opens a typed SDK client and subscribes to the server's SSE event stream.
Web app
opencode web — browser UI (packages/app).
Same server, same SDK client, rendered in the browser or the Electron shell.