DOCUMENTATION

opencode-bridge v0.4.3

MCP server for multi-model consultation

Overview

opencode-bridge is an MCP server that gives Claude Code access to OpenCode's models (GPT-5, Gemini, and others) as a companion brain. It exposes 18 tools through the Model Context Protocol, enabling multi-model consultation, code review, planning, and brainstorming directly from Claude Code sessions.

Key Features

  • Multi-model access — consult GPT-5, Gemini, and other models via OpenCode CLI
  • Auto-framing — automatically detects the domain and frames OpenCode as a specialized expert
  • Adaptive code review — review strategy adapts to file size (small/medium/large/very large)
  • Chunked map-reduce — files over 2,000 lines are split into overlapping chunks, processed in parallel, then synthesized
  • Session management — persistent sessions with conversation history, model/agent switching, and export
  • 50+ language support — language detection for Python, JS, TS, Go, Rust, Java, C/C++, and many more

Installation

Prerequisites

Install the package

terminal
$ pip install opencode-bridge

Add to your MCP config

Add to ~/.claude/settings.json under mcpServers:

~/.claude/settings.json
{
  "mcpServers": {
    "opencode-bridge": {
      "command": "opencode-bridge"
    }
  }
}

Verify

Restart Claude Code. You should see opencode_* tools available. Test with:

# In Claude Code, ask Claude to:
Use opencode_health to check the server status

MCP Tools Reference 18 tools

Core Tools

opencode_discuss core

Send a message to OpenCode. Auto-detects the discussion domain and frames OpenCode as a specialized expert in that field.

Parameters

NameTypeRequiredDescription
messagestringyesYour message or question
filesstring[]noFile paths to attach for context. File metadata (language, lines, size) is automatically included.
domainstringnoOverride auto-detected domain. E.g., "security", "metagenomics", "quantitative finance"

On the first message in a session, the full auto-framing prompt is sent (domain detection, expert persona, collaborative rules). Follow-up messages use a lightweight continuation prompt.

Files over 2,000 lines trigger chunked processing automatically.

opencode_plan core

Start a planning discussion using the dedicated plan agent. Ideal for task decomposition and implementation strategy.

Parameters

NameTypeRequiredDescription
taskstringyesWhat to plan
filesstring[]noRelevant file paths for context
opencode_brainstorm core

Open-ended brainstorming on any topic. Gets a fresh perspective from a different model.

Parameters

NameTypeRequiredDescription
topicstringyesTopic to brainstorm about
opencode_review core

Review code for issues and improvements. Uses adaptive strategies based on file size. Supports multiple files and chunked processing for large codebases.

Parameters

NameTypeRequiredDescription
code_or_filestringyesCode snippet, file path, or multiple file paths (space or comma separated)
focusstringnoWhat to focus on. Default: "correctness, efficiency, bugs"

Review strategy adapts based on total line count:

SizeLinesStrategy
Small≤ 500Thorough line-by-line review: correctness, edge cases, error handling, naming, security
Medium501 – 1,500Structured review: summary, issues, design feedback, specific suggestions
Large1,501 – 5,000Architecture-first: overview, critical issues, design concerns, complexity hotspots, top 5 recommendations
Very Large> 5,000Same as large, with note to focus on patterns over individual lines

Files over 2,000 lines are automatically chunked. See Chunked Processing.

Session Tools

opencode_start session

Start a new discussion session with OpenCode.

Parameters

NameTypeRequiredDescription
session_idstringyesUnique identifier for this session
modelstringnoModel to use. Default: openai/gpt-5.2-codex
agentstringnoAgent to use: plan, build, explore, general. Default: plan
variantstringnoReasoning effort: minimal, low, medium, high, xhigh, max. Default: medium

Sessions are persisted to ~/.opencode-bridge/sessions/ as JSON files. They survive server restarts.

opencode_end session

End the current active session.

opencode_switch session

Switch to a different existing session.

Parameters

NameTypeRequiredDescription
session_idstringyesSession to switch to
opencode_sessions session

List all sessions (active and inactive) with their model, agent, and message count.

opencode_history session

Get conversation history for a session.

Parameters

NameTypeRequiredDescription
session_idstringnoSession ID. Default: active session
last_nintegernoNumber of messages to return. Default: 20
opencode_export session

Export a session transcript as markdown or JSON.

Parameters

NameTypeRequiredDescription
session_idstringnoSession to export. Default: active session
formatstringno"markdown" or "json". Default: "markdown"

Configuration Tools

opencode_models config

List available models from OpenCode (GPT-5, Claude, Gemini, etc.).

Parameters

NameTypeRequiredDescription
providerstringnoFilter by provider: "openai", "github-copilot", "anthropic"
opencode_agents config

List available agents: plan, build, explore, general.

opencode_model config

Change the model for the current session.

Parameters

NameTypeRequiredDescription
modelstringyesNew model ID, e.g. "openai/gpt-5.2-codex"
opencode_agent config

Change the agent for the current session.

Parameters

NameTypeRequiredDescription
agentstringyes"plan", "build", "explore", or "general"
opencode_variant config

Change the model variant (reasoning effort) for the current session.

Parameters

NameTypeRequiredDescription
variantstringyes"minimal", "low", "medium", "high", "xhigh", "max"
opencode_config config

Get current configuration (default model, agent, variant).

opencode_configure config

Set default model, agent, and/or variant. Persisted to ~/.opencode-bridge/config.json.

Parameters

NameTypeRequiredDescription
modelstringnoDefault model
agentstringnoDefault agent
variantstringnoDefault variant
opencode_health config

Health check. Returns server status, session count, uptime, OpenCode binary path, and active session info.

Auto-Framing System

When Claude sends a message via opencode_discuss, the bridge automatically constructs a structured prompt that makes OpenCode adopt an expert persona in the relevant domain.

How it works

  1. The bridge receives the message and any attached files
  2. File metadata is extracted (language, lines, size, category) and included as context
  3. A companion prompt is assembled that instructs OpenCode to:
    • Detect the specific domain of expertise
    • Adopt the persona of a senior practitioner
    • Think out loud and share reasoning
    • Challenge assumptions and lay out trade-offs
    • Propose alternatives
  4. OpenCode responds with domain identification and structured analysis

Response structure

Each auto-framed response follows this pattern:

[Domain: Architecture & System Design] [Confidence: 99%]

1. Recommendation with rationale
2. Key trade-offs
3. Risks or blind spots
4. Open questions worth exploring

Domain override

You can hint a specific domain via the domain parameter on opencode_discuss. This biases the framing without forcing it. Useful for niche fields:

# Claude will call:
opencode_discuss(
  message="How should I handle OTU clustering at 97%?",
  domain="metagenomics"
)

Follow-up messages

After the first message in a session, subsequent messages use a lightweight continuation prompt that preserves the expert context without re-sending the full framing instructions.

Chunked Processing

Files over 2,000 lines are automatically processed using a map-reduce pattern: split into overlapping chunks, each analyzed independently in parallel, then results synthesized into a single coherent response.

Parameters

ParameterDefaultDescription
CHUNK_THRESHOLD2,000 linesFiles above this trigger chunking
CHUNK_SIZE800 linesLines per chunk
CHUNK_OVERLAP20 linesOverlap between adjacent chunks for context continuity
MAX_PARALLEL_CHUNKS6Maximum concurrent chunk processing (semaphore limit)
MAX_TOTAL_CHUNKS20Safety cap on total chunks per file

Boundary snapping

Chunks don't cut at arbitrary line numbers. The splitter looks for natural code boundaries near the target cut point:

  • Blank lines
  • Function/class/method definitions (def, class, function, func, fn, pub fn, impl, module, package)
  • Closing braces (})
  • Comment lines (//, #, /*, */)

This is language-agnostic — it works for Python, JavaScript, Go, Rust, Java, C/C++, and more.

Pipeline

  1. Split — file is divided into overlapping chunks with boundary snapping
  2. Map — each chunk is sent to OpenCode independently (stateless, no session flag) with a focused prompt containing chunk metadata (index, line range, total chunks)
  3. Reduce — all chunk analyses are sent to a synthesis prompt that merges them into one coherent response

Error handling

If some chunks fail, the synthesis still proceeds with available results. Failed chunks are marked in the synthesis prompt. If all chunks fail, raw error messages are returned. If synthesis fails, individual chunk analyses are concatenated as fallback.

Supported tools

Chunked processing is triggered by both opencode_discuss (when files are attached) and opencode_review (when file paths point to large files).

Code Review Strategies

The opencode_review tool adapts its review strategy based on the total line count of submitted files.

Small ≤ 500 lines

Thorough review covering correctness, edge cases, error handling, code clarity, naming, and security concerns. Concrete suggestions for improvement.

Medium 501–1,500 lines

Structured review: summary, issues found (bugs, security, edge cases), design feedback (structure, patterns, abstractions), specific suggestions with code examples.

Large 1,501–5,000 lines

Architecture-first: overview of structure and data flow, critical issues, design concerns, complexity hotspots, top 5 most impactful improvements. Focus on patterns over individual lines.

Very Large > 5,000 lines

Same as large strategy. Files over 2,000 lines are additionally chunked for parallel processing.

Language detection

opencode-bridge detects 50+ languages by file extension and includes language metadata in review prompts. Supported languages include:

Python JavaScript TypeScript Go Rust Java C/C++ C# Ruby PHP Swift Kotlin Scala Elixir Haskell Zig Dart Vue Svelte +30 more

Session Management

Sessions provide persistent conversation context with OpenCode. Each session tracks its model, agent, variant, and full message history.

Storage

Sessions are saved as JSON files in ~/.opencode-bridge/sessions/. They persist across server restarts.

Lifecycle

  1. opencode_start — creates a new session with ID, model, agent, variant
  2. opencode_discuss / opencode_plan / etc. — messages are added to the active session
  3. opencode_switch — switch between existing sessions
  4. opencode_export — export transcript as markdown or JSON
  5. opencode_end — end the active session

Auto-start

If no session is active when opencode_discuss is called, a session is started automatically with default settings.

Configuration

Defaults are stored in ~/.opencode-bridge/config.json and can be modified with opencode_configure.

~/.opencode-bridge/config.json
{
  "model": "openai/gpt-5.2-codex",
  "agent": "plan",
  "variant": "medium"
}

Options

KeyValuesDefault
modelAny OpenCode model IDopenai/gpt-5.2-codex
agentplan, build, explore, generalplan
variantminimal, low, medium, high, xhigh, maxmedium

Environment Variables

VariableDescriptionDefault
OPENCODE_MODELOverride default modelopenai/gpt-5.2-codex
OPENCODE_AGENTOverride default agentplan
OPENCODE_VARIANTOverride default variantmedium

Environment variables take precedence over config file values.