opencode-subagent-mcp
A stdio MCP server that runs Claude Code subagents on cheaper opencode models (e.g. opencode-go/deepseek-v4.1-flash) while your main Claude Code session keeps talking to Anthropic directly.
Delegate work:
agentlaunches a subagent with a self-contained prompt on an opencode model; it starts with no conversation context and returns only its final report, usage and worktree outcome.Pick the model: pass
modelasprovider/model(defaultopencode-go/deepseek-v4.1-flash) andeffortfor reasoning effort/variant.Choose the agent type:
subagent_typeaccepts Claude definitions from.claude/agents/(prompt, tools, permissionMode, maxTurns apply) or opencode agents (general,explore,plan,build).Run in the background: set
run_in_backgroundand collect results withwait(optionaltimeout_seconds), or let long calls be backgrounded automatically with a completion notification.Continue agents:
send_messageresumes a finished agent byagent_idwith its full history — including after an MCP server or Claude Code restart.Stop agents:
stopaborts a running agent and returns whatever it produced so far.Discover agents:
listshows this session's subagents and available agent types.Isolate changes:
isolation: "worktree"runs the agent in a temporary git worktree off the default branch, removed if unchanged and kept with a commit/file summary otherwise.Control permissions:
permission_mode(default,acceptEdits,auto,bypassPermissions,plan) mapped to opencode rules; opencodeaskrules surface as MCP elicitation dialogs, and your Claudeallow/ask/denysettings apply.Restrict tools:
toolsallowlist anddisallowed_toolsdenylist (Claude or opencode tool names).Get structured output: pass a JSON Schema via
output_schemaand receivestructuredContent.Cap effort:
max_turnslimits a run and returns partial, resumable output onmax_turnsstatus.Set the working directory:
cwdoverrides the default project directory.Runs safely: spins up a private
opencode serveon a random loopback port with a random password, stopped with the MCP server; no telemetry and no other network calls.
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-mcpDelegate 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.3Related MCP server: opencode MCP server
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.
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Working directory (default: the project directory) | |
| model | No | opencode model as provider/model (default: opencode-go/deepseek-v4.1-flash) | |
| tools | No | Allowlist of tools (Claude or opencode names) | |
| effort | No | Model variant/reasoning effort, e.g. low, high, max | |
| prompt | Yes | The task for the agent to perform | |
| isolation | No | ||
| max_turns | No | ||
| description | Yes | Short (3-5 word) description of the task | |
| output_schema | No | JSON Schema the final answer must satisfy; returned as structured output | |
| subagent_type | No | Claude agent definition name or opencode agent name (default: general) | |
| permission_mode | No | Permission mode (default: auto) | |
| disallowed_tools | No | ||
| run_in_background | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations present, the description carries the full burden, and it delivers substantial disclosure: blocking behavior ('The call blocks until the agent finishes'), automatic backgrounding, the run_in_background escape hatch, worktree isolation semantics including cleanup ('removed if unchanged'), and the no-conversation-context behavior. These are exactly the non-obvious behavioral traits an agent needs and are not derivable from the schema.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Every sentence earns its place and the content is dense with no filler, but it is a single run-on paragraph that is hard to scan. The size is arguably justified by the tool's complexity, yet the lack of structure (no bullets, no separation of behavior vs parameters) makes it harder to parse than it should be.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a 13-parameter tool with no annotations and no output schema, the description covers the most critical non-obvious behaviors (blocking, backgrounding, isolation cleanup, subagent resolution, context isolation). It could add a bit on permission_mode behavior or how the final result is returned, but given the complexity, the coverage is close to complete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
At 69% schema coverage, the description meaningfully compensates for the schema on the hardest parameters: it explains what subagent_type accepts (Claude .claude/agents/ definitions vs opencode agents, with their prompt/tools/permissionMode/maxTurns applying), what isolation 'worktree' induces, and the run_in_background blocking trade-off. Some params (output_schema, max_turns, effort, tools) are left to the schema, but the description targets the most complex ones.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Opens with a specific verb+resource ('Launch a subagent that runs on an opencode model'), states the scope ('in the current project') and immediately distinguishes itself from siblings by invoking the built-in Agent tool it mirrors. The sibling set (send_message, wait, stop, list) is clearly different, so there is little chance of confusing this tool with an alternative.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Provides clear contextual guidance: instructs to 'give a self-contained task prompt' and explains that the agent 'starts with no conversation context and returns only its final report', which tells an agent when this tool is appropriate (standalone tasks) and what to expect. It references the built-in Agent tool as a mirror but stops short of explicit when-not-to-use or exclusion statements, which would push it to a 5.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations only declare readOnlyHint=true; the description adds substantive behavioral context beyond that — the listing is scoped to the current server lifetime, and IDs survive restarts even when entries vanish. This restriction is exactly the kind of trait annotations cannot express.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences, front-loaded with what is returned and then the important persistence caveat. No filler, though the second sentence is slightly dense.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
No output schema exists, and the description describes the payload only loosely ('shows agents started or used'). Combined with an unexplained cwd parameter, a caller still lacks the details needed to interpret the result or pass the optional argument correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
There is one parameter (cwd) with 0% schema description coverage, and the description never mentions it, so an agent cannot tell what cwd does or whether it is required. The description leaves the schema's gap unfilled.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb+resource ('List this session's opencode subagents and the available agent types'), which rescues the generic name 'list' and makes the tool's intent unambiguous. It does not explicitly distinguish itself from a sibling list-type tool, but it clarifies its relationship to wait/send_message/stop.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
It gives clear context for when to use it (discovering started/used agents and available agent types) and a useful exclusion: agents from before a restart are not listed, but their agent_id still works with wait, send_message and stop. It stops short of naming an alternative tool for finding pre-restart agents.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | ||
| agent_id | Yes | ||
| max_turns | No | ||
| run_in_background | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden and does disclose meaningful behavior: the subagent resumes with its full prior history, its worktree is preserved if one was kept, and the call returns a new final report. It also discloses cross-restart persistence, a real operational trait. It omits what max_turns does by default or that run_in_background makes the call async.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Three sentences, zero filler, with the core verb and the agent_id anchor front-loaded. The trailing restart sentence is a worthwhile edge case rather than padding, though it could be tightened.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a stateful, mutating tool with no annotations and no output schema, the description does tell the agent what comes back ("its new final report") and how state is restored. What's missing is the behavior of the two optional control parameters (max_turns, run_in_background), which materially change how the call behaves.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0% across 4 parameters, so the description must compensate. It clarifies `agent_id` semantics (finished agents, agents from before a restart) but says nothing about `max_turns` or `run_in_background`, leaving half the parameters entirely unexplained anywhere.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb and resource ("Send a follow-up message to a finished opencode subagent by agent_id") and immediately distinguishes itself from siblings like `agent` (which starts a new one) and `stop`/`wait`. An agent can tell exactly what this does without opening the schema.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description scopes usage clearly (a *finished* subagent) and adds a valuable edge case: agent_ids that predate an MCP/Claude Code restart or that were interrupted by one. However, it never explicitly names alternatives or states when *not* to use it (e.g., use `agent` for a fresh subagent, `stop` to cancel).
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are present, so the description carries the behavioral burden and does add real value: it says the call returns partial output produced so far and that IDs survive an MCP server restart. It does not state whether the abort is irreversible, whether it errors on finished agents, or any permission requirements, leaving gaps for a mutation-style tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Three short sentences, front-loaded with the action, then the return behavior, then the edge-case note. Nothing is padded; it is appropriately sized for a one-parameter tool.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
With no annotations and no output schema, the description covers the core action, the partial-result return, and the restart edge case. It still omits idempotency, failure modes when the agent is already stopped, and error semantics — meaningful gaps for a termination operation.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 0% and agent_id is undocumented in the schema, but the description adds genuine meaning about it — that IDs minted before a server restart remain valid. That is one useful semantic detail, though it does not fully document format or validity expectations for the single parameter.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (abort) and resource (running opencode subagent), and clarifies it stops an in-flight subagent rather than waiting on or messaging one. It stops short of explicitly naming which sibling to use instead, so it is clear but not sibling-routing.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The phrase 'running opencode subagent' implies the condition for use, but no alternative is named (e.g., when to use stop vs wait), and there is no guidance on what to do if the agent is not running or has already finished.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | Yes | ||
| timeout_seconds | No | Return early if still running |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. It usefully discloses a non-obvious behavioral trait — agent_ids survive an MCP server restart — but omits blocking/polling semantics, what happens when the agent never finishes or the id is invalid, and whether early timeout returns partial state.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two tightly-written sentences with zero padding; the core purpose is front-loaded and the restart caveat is a single qualifying clause rather than a paragraph. Every sentence earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple wait tool with no output schema and only two parameters, the definition covers the essential purpose and one non-obvious behavior. The remaining gap — error/failure and timeout-result semantics — is meaningful but small given the schema already explains early return.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
With two parameters and 50% schema coverage, timeout_seconds is already documented in the schema as an early-return mechanism. The description references agent_ids but adds no format, provenance, or semantics for agent_id beyond what the parameter name implies, so it neither compensates nor regresses.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb+resource ('Wait for a background opencode subagent and return its result'), which an agent can immediately distinguish from siblings like send_message, stop, list, and agent. The scope is unambiguous and the outcome (returns the result) is stated.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Usage is only implied: 'background' subagent suggests it is used when polling an asynchronously-started agent, but no explicit when-to-use, when-not-to-use, or alternative (e.g., vs. list or agent) is named. No exclusions or prerequisites are given.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
5 tool updates
v0.1.1- First observed
agent - First observed
list - First observed
send_message - First observed
stop - First observed
wait
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
- projectsOAuthcloud.tri2b
Task tracking built for coding agents. Work is leased, so two agents never take the same SubTask.
Pay-per-call ($0.01 USDC) model-routing for AI coding agents: which LLM to call, cost vs. quality.
Build and supervise fleets of agents from Claude Code, Codex or Cursor. Connects over OAuth.
No-data MCP handoff for local Claude Code to Codex harness moves. $49 lifetime.
Related MCP Servers
- AlicenseAqualityBmaintenanceLets your primary coding agent delegate grunt work to a cheaper model via OpenCode, enabling cost-effective task distribution.5MIT
- FlicenseNot gradedqualityCmaintenanceLets Claude Code offload cheap, mechanical tasks to opencode's free models for codebase summaries, exploration, web research, and bulk edits, saving paid tokens.-
- AlicenseNot gradedqualityBmaintenanceEnables Claude Code to delegate prompts to an OpenCode agent session for cheaper executor-role work, supporting different providers and session persistence.20,587 npmMIT
- AlicenseAqualityCmaintenanceLets Claude Code delegate coding tasks to external models running on a local opencode serve, preserving main agent tokens for planning and review.843 npm1MIT