🖥️ Caller application
- The application provides the user-facing or programmatic interface.
- Network calls use the generated Client.
- SDK Next embeds the same router and runtime in the caller process.
External resources
- Model endpoints run outside the OpenCode process, remotely or as separate local services.
- Workspace files and host processes are host resources, not server-process components.
- This is a dependency grouping, not a shared deployment boundary.
OpenCode V2
- Native runtime components, hosted as a server or embedded in a caller process.
- Prompt admission is durable; execution coordination is process-local.
- Model services and host workspace are dependencies outside this runtime component boundary.
🎨 Color convention
Responsibility-based node colors:
- blue: runtime
- teal: I/O
- purple: models
- amber: state,
- rose: callers
opencode
CodeThe open source coding agent.
👨💻Developer
Prompts and approval decisionsSubmits prompts and decides whether requested tool actions may proceed.
🌐 Global Session services
Owns Session identity, durable inbox/state/events and process-local execution coordination shared across Locations.
📍 Location services
Runner, model resolution, context sources, tools and permissions are scoped to the selected working-directory Location, not to an individual Session.
☁️ Model providers
OpenCode's native LLM transport can route requests to configured model providers.
Application
Native /api caller interfaceAccepts prompts and approval decisions, then calls the appropriate transport layer.
📦 Embedded SDK
sdk-next · OC running in-processComposes the generated Effect Client, Core and Server; custom fetch dispatches through the same HTTP router without a network hop.
📡 Live events
HTTP endpoint · SSE- Streams current event envelopes, including transient token deltas and approval requests.
- This bounded live feed has no durable replay cursor.
🔗 Generated Client
Network transport · HTTP + SSEEncodes current /api requests, returns decoded admission receipts and exposes SSE events to the caller.
⏪ Session replay
HTTP endpoint · Durable SSE- Replays and tails committed Session events after an aggregate-sequence cursor.
- Live-only deltas are excluded; finite history is also available.
🔌 Session API
HTTP handlers for admission, reads & controlsValidates current contracts and dispatches prompt admission, session reads/controls and Location-scoped approval replies.
🗄️ SQLite
Durable state · Local storage- Stores the event journal, prompt inbox, Session/message projections, context epochs and saved approval rules.
- Active drains and pending approval waits are not durable workflow ownership.
📁 Host workspace
Project files + Host processesProvides working-tree files, ambient instructions and command execution. Permission checks are not a shell sandbox, and host side effects are not atomic with tool-result persistence.
Anthropic
Model providerClaude models through Anthropic's native API.
🛠️ BuiltInTools
Built-in executors & permission checksResolve resources, enforce their own permission policy, then read/edit files, spawn host processes or call web tools.
🧭 System Context
Typed context sources & registryBuilds and refreshes workspace and agent context; required initial context must be available before a pending prompt is promoted.
📣 EventV2
Transactional journal + Live busCommits durable events with derived Session state and broadcasts live updates.
⚡ SessionExecution
Process-local coordination & Location routingSerializes each Session's drains, coalesces work notifications and settles ownership when a drain completes.
📥 SessionInput
Durable prompt inbox · admission & promotion- Admits normalized prompts with exact-retry reconciliation.
- Keeps inputs pending until promotion into visible history.
- Steer is default; queue waits until current continuation would end.
🧠 Model resolution & LLM transport
SessionRunnerModel + LLMClientResolves model/auth and lowers canonical requests onto supported native provider routes, returning normalized events for one provider turn. The runner—not an AI SDK tool loop—owns continuation.
OpenAI
Model providerGPT models through OpenAI's native API.
+ other providers
Configured model routesPopular built-in integrations include:
- Google Gemini, Amazon Bedrock, Azure OpenAI
- OpenRouter, xAI, GitHub Copilot
- Cloudflare AI Gateway / Workers AI
- OpenAI-compatible endpoints
🛡️ PermissionV2
Rules, approval requests & replies- Evaluates configured rules and saved project approvals.
- Holds pending requests in Location-local memory.
- Resolves once, always or reject decisions.
🔄 SessionRunner
Turns, tool settlement & continuationBuilds model turns, runs local tools, records outcomes and exits when there is no continuation or eligible pending input.
💬 SessionV2
Session facade · Effect- Admits prompts durably and exposes Session reads/control
- Model orchestration belongs to the runner.
📋 Session projections
SessionStore + SessionProjectorMaintains event-derived Session/message views and reloads them for placement, history reads and provider-turn continuation.
🧰 ToolRegistry
Tool definitions, dispatch & output bounding- Captures Location or application tool registrations.
- Validates calls and bounds model-facing output.
- Authorization belongs to each executor, not the registry.