OpenCode V2 agents connect to an OpenCode v2.3+ HTTP/SSE server (aligned with OpenCode v2.4.1 via opencode_v2_sdk), either by spawning a private opencode serve process automatically or by connecting to an already-running OpenCode V2 server (such as opencode serve or agentpool serve-opencode).
How it works¶
- Managed or remote server: When
urlis omitted, AgentPool spawnsopencode serve --hostname 127.0.0.1 --port <free-port>with an ephemeral basic-auth password, waits for/api/info, and shuts it down cleanly on exit. Seturl(and optionalpassword) to connect to a running server instead. - Live SSE streaming: Each turn subscribes to
GET /api/event, enqueues the prompt viaPOST /api/session/{id}/prompt, and translates V2 step, reasoning, text, tool, compaction, retry, and toast events into AgentPool's stream events. - Permissions and forms: When
permission_mode: ask,permission.askedevents route through AgentPool'sInputProvider.get_tool_confirmation()and reply viaPOST /api/session/{id}/permission/{requestID}/reply. Interactiveform.createdrequests route throughInputProvider.get_elicitation()and reply viaPOST /api/session/{id}/form/{formID}/reply. - MCP toolset bridging: AgentPool
toolsand toolsets are exposed via an in-process Streamable HTTP MCP bridge (ToolManagerBridge) registered through/api/experimental/mcp/{server}, alongside any configuredmcp_servers. - Session management & config options:
list_sessionsandload_sessionread and replay projected V2 session messages;mode(permissions),agent,thought_level(model variant), andmodelare exposed as switchable config options.
Configuration Reference¶
OpenCode V2 Agent Configuration¶
Configuration for OpenCode V2 (v2.3+) agents.
Talks to an OpenCode V2 HTTP/SSE server (opencode serve or any compatible
OpenCode V2 endpoint such as agentpool serve-opencode). When url is
omitted, AgentPool spawns and manages a private opencode serve process
automatically.
Example:
agents:
opencode_local:
type: opencode_v2
model: anthropic/claude-sonnet-4-5
variant: high
permission_mode: ask
tools:
- type: agent_management
opencode_remote:
type: opencode_v2
url: http://127.0.0.1:4096
password: ${OPENCODE_PASSWORD}
agent: build
permission_mode: allow
Basic Usage¶
agents:
# Spawn and manage a private `opencode serve` process automatically
opencode_local:
type: opencode_v2
model: anthropic/claude-sonnet-4-5
variant: high
permission_mode: ask
tools:
- type: subagent
# Connect to an existing OpenCode V2 server
opencode_remote:
type: opencode_v2
url: http://127.0.0.1:4096
password: ${OPENCODE_PASSWORD}
agent: build
permission_mode: allow
Configuration Notes¶
modelacceptsprovider/model(including provider models whose own ID contains/, such as OpenRouter IDs) or a bare model ID resolved against/api/model.permission_modedefaults toallowfor programmatic use. Useaskfor interactive tool confirmations or specify fine-grained glob rules viapermissions.- When connecting to a remote server that uses basic authentication, set
password: ${OPENCODE_PASSWORD}(or exportOPENCODE_PASSWORD/OPENCODE_SERVER_PASSWORD).