opencode-subagent-mcp
Summary: Run Claude Code subagents on cheaper opencode models through a private stdio MCP server while your main Claude Code session stays on Anthropic.
Launch subagents with a self-contained prompt, choosing model, cwd, subagent type, tools, permission mode, max turns, effort, worktree isolation, structured output, and background execution.
Continue finished or interrupted agents with
send_message, preserving full history and kept worktrees, even across MCP/Claude Code restarts.Wait for background agents with an optional timeout, stop running agents and return partial output, and list session agents plus available agent types.
Mirror native subagent behavior: fresh context with only the final report,
.claude/agents/*.mddefinitions, permission prompts/modes, worktree isolation, progress notifications, max-turns partial output, and JSON structured output.Delegate searches, refactors, bug fixes, tests, and research to cheaper models; the server starts and stops its own private
opencode serveinstance and does not proxy the main session.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@opencode-subagent-mcp Delegate fixing the failing tests in src/utils.test.ts to a cheaper opencode model"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
opencode-subagent-mcp
Run Claude Code subagents on cheaper opencode models — for example
opencode-go/deepseek-v4.1-flash (DeepSeek) from an opencode Go subscription — while Claude
Code itself keeps talking to Anthropic directly. Delegate searches, refactors, bug fixes, tests
and research to a model that costs a fraction of Opus or Sonnet, and keep the tools you already
use: background agents, resume via send_message, worktree isolation, .claude/agents
definitions, permission prompts and structured output.
It is a stdio MCP server. Your main Claude Code session is not proxied or routed
anywhere; the server only runs the subagents you delegate to it, on a private
opencode serve instance it starts itself.
Install
Requires Node 22+, git, and the opencode CLI logged in to the
providers you want (opencode auth login).
As a Claude Code plugin (also adds a skill that tells Claude when to delegate to opencode):
claude plugin marketplace add sebstaq/opencode-subagent-mcp
claude plugin install opencode-subagent-mcp@sebstaq-opencodeOr as a plain MCP server:
claude mcp add -s user opencode -- npx -y opencode-subagent-mcp@0.1.4Related MCP server: opencode-executor-mcp
What it runs and sends
It starts a private
opencode serveprocess on a random localhost port with a random password, and stops it when Claude Code exits. The password is generated for each run and only used between this server and that local process. The process inherits your environment so opencode can use the provider logins and API keys you already configured for it; this server never reads, stores or sends those credentials itself.The prompts you delegate, and the files and command output the subagent reads, go to the model provider you choose through opencode (by default opencode Go), under that provider's data retention terms. opencode keeps session history in its local database on your machine. Nothing else is sent anywhere; the server has no telemetry and makes no other network calls.
It reads
~/.claude/settings.json, the project's.claude/settings.jsonand.claude/settings.local.json, and.claude/agents/*.md(user and project) to mirror your permission rules and agent definitions, and~/.config/opencode-subagent-mcp/config.jsonif present.With
isolation: "worktree"it creates git worktrees under the project's.claude/worktrees/and removes them when they have no changes.
This is an independent project, not affiliated with Anthropic or the opencode team.
Tools
Tool | Native equivalent | What it does |
| Agent tool | Run a subagent; returns its final report, usage and worktree outcome |
| SendMessage | Continue a finished agent with its full history; also after a restart |
| background completion notification | Collect a |
| TaskStop | Abort a running agent and return what it produced |
| /agents | This session's agents, Claude agent definitions and opencode agents |
An agent_id keeps working after the MCP server or Claude Code restarts: wait and stop
return what happened to it, and send_message continues it. Agents from before a restart do not
appear in list until their id is used again, but they still exist in opencode's local session
store.
agent parameters: description, prompt, subagent_type, model, isolation: "worktree",
permission_mode, tools, disallowed_tools, max_turns, effort, output_schema,
run_in_background, cwd.
Parity with native subagents
Native behaviour | Here |
Fresh context, only the final message comes back | Same. Long output is truncated ( |
Runs in the project directory | Same (cwd from MCP roots, then |
| Same layout ( |
Permission prompts surface in the main session | opencode |
Permission modes |
|
Background agents with completion notification | Claude Code moves long MCP calls to the background automatically and notifies when they finish; |
Resume with full history |
|
| Used via |
| Same; status |
Progress in the UI | Tool calls are sent as MCP progress notifications |
Subagents cannot spawn subagents or ask the user questions | opencode's |
Structured output |
|
Known gaps: agents do not appear in Claude Code's /tasks agent view; there is no
fork-with-parent-context; the Workflow tool's agent() cannot target them; auto mode has no
safety classifier (it allows everything, including paths outside the project, except rules
you configured and a fixed list of destructive commands that ask: rm -r/-rf, git push --force, git reset --hard, git clean -f, git restore/git checkout --, curl | sh,
sudo, chmod -R/chown -R, dd, mkfs, npm/pnpm publish; opencode matches each
command in a chain separately); the parent's permission mode is not visible to MCP servers, so
the default comes from config; hooks, skills preloading, memory and per-agent MCP servers are not mapped.
Steering Claude
Claude Code picks between its native Agent tool and this one on its own, so routing is
unpredictable. To make opencode the default for delegated work that is cheap to verify, paste the snippet from docs/claude-md-snippet.md into
your global ~/.claude/CLAUDE.md.
Configuration
Optional ~/.config/opencode-subagent-mcp/config.json (or $OPENCODE_SUBAGENT_CONFIG):
{
"defaultModel": "opencode-go/deepseek-v4.1-flash",
"defaultPermissionMode": "auto",
"pure": true,
"opencodeBin": "opencode",
"maxConcurrent": 8,
"maxResultChars": 80000
}OPENCODE_SUBAGENT_MODEL and OPENCODE_SUBAGENT_MODE override the first two. pure starts
opencode without external plugins.
How it works
On first use the server starts opencode serve on a random loopback port with a random
password, subscribes to its event stream, and drives one opencode session per agent
(agent id = session id). Permission requests from opencode are answered through MCP
elicitation. The opencode process is stopped with the MCP server; leftovers from crashed
servers are reaped on the next start.
Development
pnpm check # typecheck, lint, format check, unit tests
pnpm smoke [provider/model] # end-to-end run against a real model in a temp repoLicense
MIT
Available Tools
5 toolsagentopencode subagentA
Launch a subagent that runs on an opencode model (default opencode-go/deepseek-v4.1-flash) in the current project. Mirrors the built-in Agent tool: give a self-contained task prompt; the agent starts with no conversation context and returns only its final report. subagent_type accepts Claude agent definitions from .claude/agents/ (their prompt, tools, permissionMode and maxTurns apply) or opencode agents (general, explore, plan, build). isolation 'worktree' runs it in a temporary git worktree off the default branch, removed if unchanged. The call blocks until the agent finishes (it is backgrounded automatically after a while); set run_in_background to return at once and collect the result with wait.
Inputs: prompt (required), description (required), cwd, model, +9 more.
listList opencode subagentsARead-only
List this session's opencode subagents and the available agent types. It shows agents started or used since this MCP server started; agents from before a restart are not listed but their agent_id still works with wait, send_message and stop.
Inputs: cwd.
send_messageContinue an opencode subagentA
Send a follow-up message to a finished opencode subagent by agent_id. It resumes with its full previous history (and its worktree, if one was kept) and returns its new final report. Also works for agent_ids from before a restart of the MCP server or Claude Code session, and for agents that were interrupted by such a restart.
Inputs: message (required), agent_id (required), max_turns, run_in_background.
stopStop an opencode subagentB
Abort a running opencode subagent. Returns what it produced so far. agent_ids from before a restart of the MCP server still work.
Inputs: agent_id (required).
waitWait for an opencode subagentA
Wait for a background opencode subagent and return its result. agent_ids from before a restart of the MCP server still work.
Inputs: agent_id (required), timeout_seconds.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool maps to a distinct lifecycle action: launch (agent), follow-up (send_message), await result (wait), abort (stop), enumerate (list). The overlap between wait (awaits a background agent) and send_message (resumes a finished agent and returns its report) is clearly disambiguated by their descriptions.
Names mix conventions: send_message is verb_noun, while wait, stop, and list are bare verbs and 'agent' is a bare noun. All are readable, but there is no single predictable pattern across the set.
Five tools cleanly cover the subagent lifecycle (launch, message, wait, stop, list) with no redundancy. This is well-scoped for the server's stated purpose.
The surface covers launch, resume, wait, stop, and list, which spans the full lifecycle. Minor gaps exist (e.g. no dedicated status/inspect or explicit cleanup of retained worktrees), but agents can work around them via list and send_message.
Maintenance
Related MCP Connectors
Discover available AI models and delegate analysis or code review from your existing agent.
Give spare Claude Code or Codex usage to open source. Your agent opens pull requests. No money.
Task tracking built for coding agents. Work is leased, so two agents never take the same SubTask.
Ask other AI models and generate images, speech, music and video from your coding agent.
Related MCP Servers
- AlicenseAqualityDmaintenanceLets your primary coding agent delegate grunt work to a cheaper model via OpenCode, enabling cost-effective task distribution.51MIT
- AlicenseNot gradedqualityDmaintenanceEnables Claude Code to delegate prompts to an OpenCode agent session for cheaper executor-role work, supporting different providers and session persistence.24,973 npmMIT
- AlicenseAqualityDmaintenanceLets Claude Code delegate coding tasks to external models running on a local opencode serve, preserving main agent tokens for planning and review.866 npm1MIT
- FlicenseNot gradedqualityAmaintenanceEnables Claude Code or any MCP client to delegate bounded tasks such as code review, boilerplate, and documentation to local or cloud OpenAI-compatible LLMs. This reduces token usage by keeping large source files out of the main model's context while allowing results to be reviewed by the orchestrator.-