Repository avatar
AI Tools
v0.3.0
active

subharness

io.github.rjstone/subharness

Run subagents on any model opencode can reach, from many coding agents.

Documentation

subharness

version skills check tests license

Run subagents on any model opencode can reach, from Claude Code, Codex, Gemini CLI, Copilot, Cursor, Grok Build and other coding agents. Your agent stays the orchestrator and hands a task to a cheaper or different model, using tools shaped like its own subagent tools.

  • Any model opencode knows: pick one per task by its provider/model id or by loose words ("kimi k3"), or set a default.
  • Read-only by default. Editing happens in a separate git worktree; you review the changes and merge them yourself.
  • Background runs: start several tasks, wait for them, stop them, or continue a finished one with its history. Several windows share one task list.
  • Feels native: in each harness the tools mirror its own subagent tools (see "Tools in each harness").

subharness is a plugin (an MCP server plus a skill that tells the model when to use it). The server is also on npm as subharness-mcp for any other MCP client.

Install

HarnessStatusInstall
Claude Codetested/plugin marketplace add rjstone/plugin-marketplace, then /plugin install subharness@rjstone
Codexinstallscodex plugin marketplace add rjstone/plugin-marketplace, then codex plugin add subharness@rjstone
Copilot CLIinstallscopilot plugin marketplace add rjstone/plugin-marketplace, then copilot plugin install subharness@rjstone
Gemini CLIinstallsgemini extensions install https://github.com/rjstone/subharness-plugin
Antigravityinstallsagy plugin install https://github.com/rjstone/subharness-plugin
Grok Build Terminal UIinstallsgrok plugin install https://github.com/rjstone/subharness-plugin --trust
Cursor / Grok Build Agents Windowinstallscopy a clone to ~/.cursor/plugins/local/subharness, then reload the window
Kiroinstallskiro-cli powers install <path to a clone> (or, untested: Powers panel > Add Custom Power > https://github.com/rjstone/subharness-plugin)
Augment Auggieinstallsauggie plugin marketplace add rjstone/plugin-marketplace, then enable subharness@rjstone
Devinuntesteddevin plugins install rjstone/subharness-plugin
VS Codeuntestedsetting chat.plugins.marketplaces: ["rjstone/plugin-marketplace"]
Cline, Amp, other MCP clientsmanualsee "Other MCP clients" below

tested = used for real work; installs = the plugin installs, but it hasn't been run with a model in that harness yet; untested = built from the harness's docs. Per-harness notes are in REFERENCE.md.

The marketplace lines use rjstone/plugin-marketplace, which installs the latest release. To follow main instead, add rjstone/subharness-plugin as the marketplace and install subharness@subharness.

Other MCP clients

Add the server by hand; it runs from npm:

{
  "mcpServers": {
    "subharness": { "command": "npx", "args": ["-y", "subharness-mcp"] }
  }
}
  • Cline CLI: cline mcp add subharness --yes -- npx -y subharness-mcp, then set "timeout": 600 on the entry (Cline's default is 60 seconds per call).
  • Amp: amp mcp add subharness -- npx -y subharness-mcp.

The skill isn't installed this way, but the tools' descriptions explain how to use them. Also listed in the MCP Registry as io.github.rjstone/subharness.

Requirements

  • Node 22.18 or later.
  • opencode v2 on the PATH.
  • Keys for the providers you want, as environment variables (see "Keys and providers"). opencode's own models (OpenCode Zen, OpenCode Go) work as usual.
  • Tested on Linux; macOS and Windows are untested.

Using it

Ask your agent in plain words, for example:

Have a subagent on kimi k3 review src/parser.ts for bugs.

Start two background agents, one on glm and one on deepseek, to draft tests for lib/, each in its own worktree.

The agent picks the tools; the skill tells it how. Ask it to list the models if you're not sure what's available.

Tools in each harness

The server presents its tools in the shape of the host's own subagent tools, so the model uses them the way it uses its native subagents. Every shape can do the same things: choose a model, run read-only or in a worktree, run in the background, wait, stop, list tasks and list models.

ShapeHarnessesTools
genericClaude Code, Kiro, Amp, anything elseagent, send_message, wait, stop, list, models
geminiGemini CLIinvoke_agent, wait, stop, list, models
codexCodexspawn_agent, send_input, wait_agent, close_agent, list_agents, models
copilotCopilot CLI, VS Codetask, read_agent, write_agent, list_agents, stop_agent, models
cursorCursorTask, wait, stop, list, models
augmentAugment Auggieagent, get-subagent-result, steer-subagent, stop, list, models
devinDevinrun_subagent, read_subagent, stop, list, models
antigravityAntigravityinvoke_subagent, send_message, manage_subagents, wait, models
clineClinespawn_agent, wait, stop, list, models
grokGrok Buildspawn_subagent, get_command_or_subagent_output, kill_command_or_subagent, models

The shape is detected automatically. For Devin, set SUBHARNESS_CLIENT_TYPE=devin; any harness can be overridden the same way. Parameters and detection: REFERENCE.md.

What subagents may do

  • Read-only (default): read and search files inside the project and run a few read-only commands (ls, cat, git log, git diff, ...). The read tool refuses key files and folders (.env, .ssh, .aws, .git/config and others), though grep has known gaps. No web access, no other MCP tools.
  • Editing (worktree): subharness creates a git worktree on a new subharness/... branch and the agent edits only there. Changes are left uncommitted for you to review and merge. Check the diff before you take it, especially files that run code (git hooks, package.json scripts, CI files).
  • No shell for editors unless you set SUBHARNESS_EDITOR_SHELL=true, and that shell is not sandboxed: use it only with models and prompts you trust.

These rules are enforced by opencode's permissions, not by the prompt. The exact rules and the known gaps are in REFERENCE.md.

Keys and providers

subharness runs its own private opencode server, which does not see keys saved with opencode auth login. Give keys as environment variables (OPENROUTER_API_KEY and so on) or in your opencode config as "apiKey": "{env:MY_KEY}". The private server gets a limited environment: basics such as PATH and HOME, proxy settings, and provider variables (names ending in _API_KEY, _API_TOKEN, _BASE_URL and a few more); pass others with SUBHARNESS_PASS_ENV. opencode's free models are rate-limited, and subharness doesn't switch models for you when one is.

Setup script

To prepare a machine or a cloud container before the harness starts, configure everything with shell commands. subharness reads its environment and the global opencode config (~/.config/opencode/); project config is ignored.

# 1. opencode v2 on the PATH (or point SUBHARNESS_OPENCODE_BIN at it)
npm install -g @opencode/cli

# 2. Providers opencode doesn't ship, plus any per-provider settings. Providers it already knows
#    (see `opencode models`) need no entry unless you change something, such as a header.
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
cat > "${XDG_CONFIG_HOME:-$HOME/.config}/opencode/opencode.json" <<'EOF'
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "myprov": {
      "name": "My provider",
      "package": "aisdk:@ai-sdk/openai-compatible",
      "env": ["MYPROV_API_KEY"],
      "settings": { "baseURL": "https://api.example.com/v1" },
      "models": { "some-model": {} }
    },
    "openrouter": { "headers": { "X-Extra-Header": "value" } }
  }
}
EOF

# 3. Settings, exported in the shell that starts the harness (or a profile file it reads)
export SUBHARNESS_MODEL=myprov/some-model
export SUBHARNESS_PREFERRED_PROVIDERS=myprov,opencode
export SUBHARNESS_MAX_TASKS=2

# 4. Check what opencode sees (a private server, like subharness uses)
opencode models --standalone | grep '^myprov/'

Keep keys out of the script and the config file: set them in your secret store or the environment's settings. More notes (cloud sessions, proxies, model ids): REFERENCE.md.

Settings

Set these in the MCP server's environment (for Claude Code, the shell you start it from). The most useful ones:

VariableDefaultMeaning
SUBHARNESS_MODELopencode's defaultdefault model for every agent
SUBHARNESS_READ_MODELnonedefault model for read-only runs
SUBHARNESS_PREFERRED_PROVIDERSnoneproviders preferred when a loose model name matches several
SUBHARNESS_MAX_TASKS4tasks running at once; more are queued
SUBHARNESS_EDITOR_SHELLfalsegive editing agents a shell (not sandboxed)
SUBHARNESS_PASS_ENVnoneextra variables for the private opencode server (MY_KEY,CORP_*)
SUBHARNESS_SERVERprivateprivate, shared (opencode's background service) or an http(s):// URL
SUBHARNESS_CLIENT_TYPEdetectedforce a tool shape (generic, codex, devin, ...)

Timeouts, step limits, the state folder and the rest: REFERENCE.md.

Credits

Code and ideas adapted from aashahin/claude-opencode-delegate (MIT) and PacAnimal/opencode-subagent-for-claude (MIT). Tool shape informed by sebstaq/opencode-subagent-mcp.

Licence

MIT. See LICENSE.

NPM
subharness-mcp
Install Command
npm install subharness-mcp
Runtime: npx