Overview
The OpenCode bridge wraps theopencode CLI, providing access to a multi-provider code agent through Agent-Ctrl’s unified API. OpenCode is the most flexible bridge in terms of model selection — it supports provider-prefixed model IDs that let you use models from Anthropic, OpenAI, Google, and other providers through a single CLI tool. It exposes both token usage and cost data (as does the Pi bridge).
The bridge is implemented by OpenCodeBridge and configured through OpenCodeBridgeBuilder. Access the builder through the AgentCtrl facade:
Basic Usage
Model Selection
OpenCode uses provider-prefixed model IDs, giving you access to models from multiple providers through a single CLI. The format isprovider/model-name:
Named Agents
OpenCode supports named agents — preconfigured agent profiles that define specific behaviors, tools, and system prompts. UsewithAgent() to select one:
coder (for code-focused tasks) and task (for planning and general tasks).
File Attachments
UsewithFiles() to attach specific files to the prompt. The agent will have direct access to these files as context, without needing to discover and read them:
inDirectory() which sets the working directory, withFiles() explicitly includes specific files in the prompt context. This is useful when you want the agent to focus on particular files rather than browsing the project directory.
Session Title
UsewithTitle() to set a descriptive title for the session. The title appears in OpenCode’s session listing and makes it easier to identify sessions later:
Session Sharing
UseshareSession() to mark the session for sharing after completion. Shared sessions can be accessed by other users or tools, enabling collaborative workflows where multiple team members can review or continue an agent’s work:
Streaming with OpenCode
OpenCode streams output as JSON Lines containing text events, tool use events, step events, and error events. The bridge normalizes these into the standard callback API:Event Normalization
During streaming, OpenCode emits several event types that are normalized:TextEvent— Text content is delivered throughonText()with the text string.ToolUseEvent— Tool invocations are delivered throughonToolUse()with the tool name, input parameters, optional output, and call ID. TheisErrorflag is set based on whether the tool completed successfully.ErrorEvent— Error events are delivered throughonError()with the message, optional code, and raw data.StepStartEvent/StepFinishEvent— Step lifecycle events are processed internally and available through thewiretap()event system but not directly exposed through user callbacks.
Session Management
OpenCode maintains its own session system with session IDs. Agent-Ctrl extracts and normalizes these intoAgentSessionId value objects. Internally, OpenCode uses OpenCodeSessionId which is mapped to the unified AgentSessionId:
Usage and Cost Data
OpenCode provides comprehensive usage and cost reporting. Both token usage and cost data are available after execution.Token Usage
OpenCode’sTokenUsage includes all five token categories — input, output, cache read, cache write, and reasoning:
Cost Tracking
OpenCode exposes cost data (as does Pi). The cost is returned in USD:Data Availability
| Data Point | Available | Notes |
|---|---|---|
| Text output | Yes | Extracted from TextEvent stream events |
| Tool calls | Yes | Normalized from ToolUseEvent with call IDs and completion status |
| Session ID | Yes | Extracted from OpenCode session data |
| Token usage | Yes | Input, output, cache read, cache write, reasoning tokens |
| Cost | Yes | Cost in USD |
| Parse diagnostics | Yes | Malformed JSON line counts and samples |
Complete Example
Comparison with Other Bridges
| Feature | Claude Code | Codex | OpenCode | Pi | Gemini |
|---|---|---|---|---|---|
| System prompts | Yes (replace + append) | No | No | Yes (replace + append) | Yes (GEMINI.md file) |
| Permission modes | Yes (4 levels) | No | No | No | Yes (4 modes) |
| Turn limits | Yes | No | No | No | Yes (via settings) |
| Sandbox modes | No | Yes (3 levels) | No | No | Yes (Seatbelt/Docker/Podman/gVisor) |
| Image input | No | Yes | No | No | No |
| Thinking levels | No | No | No | Yes (6 levels) | No |
| Named agents | No | No | Yes | No | No |
| File attachments | No | No | Yes | Yes (@-prefix) | No |
| Extensions | No | No | No | Yes (TypeScript) | Yes |
| Skills | No | No | No | Yes | No |
| Tool control | No | No | No | Yes (select/disable) | Yes (allowlist) |
| MCP servers | No | No | No | No | Yes |
| Policy engine | No | No | No | No | Yes |
| Session sharing | No | No | Yes | No | No |
| Session titles | No | No | Yes | No | No |
| Ephemeral mode | No | No | No | Yes | No |
| API key override | No | No | No | Yes | No |
| Token usage | No | Yes (partial) | Yes (full) | Yes | Yes (with cache) |
| Cost tracking | No | No | Yes | Yes | No |
| Multi-provider models | No | No | Yes | Yes | No |