Skip to content

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 url is omitted, AgentPool spawns opencode 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. Set url (and optional password) to connect to a running server instead.
  • Live SSE streaming: Each turn subscribes to GET /api/event, enqueues the prompt via POST /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.asked events route through AgentPool's InputProvider.get_tool_confirmation() and reply via POST /api/session/{id}/permission/{requestID}/reply. Interactive form.created requests route through InputProvider.get_elicitation() and reply via POST /api/session/{id}/form/{formID}/reply.
  • MCP toolset bridging: AgentPool tools and toolsets are exposed via an in-process Streamable HTTP MCP bridge (ToolManagerBridge) registered through /api/experimental/mcp/{server}, alongside any configured mcp_servers.
  • Session management & config options: list_sessions and load_session read and replay projected V2 session messages; mode (permissions), agent, thought_level (model variant), and model are 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

OpenCode V2 Agent Configuration (YAML)
type: opencode_v2  # Top-level discriminator for agent type.
url: null  # Base URL of an existing OpenCode V2 server.
password: null  # Basic-auth password for url (${VAR} references are expanded).
command: opencode  # Executable name or path used to launch opencode serve when url is not set.
startup_timeout: 15.0  # Seconds to wait for a managed opencode serve process to become ready.
headers: {}  # Additional HTTP headers sent with every API request (${VAR} expanded).
env_vars: {}  # Environment variables to set.
agent: null  # OpenCode agent ID to select on the session (uses the server default when omitted).
model: null  # Model to use, as provider/model or a bare model ID (resolved via /api/model).
variant: null  # Optional model variant (e.g. reasoning effort level supported by the model).
permission_mode: allow  # How permission requests are handled when permissions is not explicitly set.
permissions: null  # Optional explicit OpenCode V2 permission rules applied to created sessions.
tools: []  # AgentPool tools and toolsets to expose to OpenCode V2 via an in-process MCP bridge.
requires_tool_confirmation: per_tool  # How to handle tool confirmation:
hooks:  # Hooks for intercepting and customizing agent behavior at key lifecycle points.
  pre_run: []  # Hooks executed before agent.run() processes a prompt.
  post_run: []  # Hooks executed after agent.run() completes.
  pre_tool_use: []  # Hooks executed before a tool is called. Can block or modify the call.
  post_tool_use: []  # Hooks executed after a tool completes.
environment: null  # Execution environment config for the agent's own toolsets.
name: null  # Identifier for the node. Set from dict key, not from YAML.
display_name: null  # Human-readable display name for the node.
description: null  # Optional description of the agent / team.
triggers: []  # Event sources that activate this agent / team
connections: []  # Targets to forward results to.
mcp_servers: []  # List of MCP server configurations:
input_provider: null  # Provider for human-input-handling.
event_handlers: []  # Event handlers for processing agent stream events.

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

  • model accepts provider/model (including provider models whose own ID contains /, such as OpenRouter IDs) or a bare model ID resolved against /api/model.
  • permission_mode defaults to allow for programmatic use. Use ask for interactive tool confirmations or specify fine-grained glob rules via permissions.
  • When connecting to a remote server that uses basic authentication, set password: ${OPENCODE_PASSWORD} (or export OPENCODE_PASSWORD / OPENCODE_SERVER_PASSWORD).