You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2e2a22c
Browse filesBrowse the repository at this point in the historyBrowse files
Claude Code plugin with a bundled MCP server (`.mcp.json` → `dist/index.js`, built from `src/index.ts` with `bun run build`; commit the bundle, CI checks it is current). Core modules:
|`opencode.ts`| Spawn `opencode run --format json`, fold JSON event stream into `EventCollector`|
36
+
|`delegate.ts`| Build args, git-diff changed-files detection, format outcome |
37
+
|`tasks.ts`| In-memory async task store (UUID keys, max 100 finished), prune oldest |
37
38
38
39
Tests mirror this structure: `test/models.test.ts` (resolution logic), `test/opencode.test.ts`
39
-
(EventCollector + buildArgs). Fixtures are JSONL captured from real `opencode run` sessions.
40
+
(EventCollector + buildArgs), `test/mcp-server.test.ts` (spawns the server, checks `tools/list`). Fixtures are JSONL captured from real `opencode run` sessions.
| Hook |`scripts/route-to-opencode.sh`, `plugin-hooks/hooks.json`| PreToolUse `Agent\|Task`: rewrites only built-in subagent calls (general-purpose, claude, Explore, Plan, claude-code-guide, statusline-setup) to `opencode-worker` on Haiku (Explore/Plan/claude-code-guide forced read-only); custom, plugin, reviewer and SDD agents never routed; pass-through guards: `OPENCODE_DELEGATE_ROUTE=off`, missing opencode, `[no-opencode]`, no `jq`|
24
+
| MCP |`.mcp.json`, `src/index.ts`, `dist/index.js`|`opencode` MCP server (stdio, `bun ${CLAUDE_PLUGIN_ROOT}/dist/index.js`) exposing `delegate`, `delegate_async`, `task_result`, `task_list`, `task_cancel`, `list_models`, `list_sessions` to the main thread |
24
25
| Manifests |`.claude-plugin/plugin.json`, `marketplace.json`| Plugin identity; `plugin.json` carries homepage/repository shown by Claude Code |
25
26
26
-
`src/`is a library that no plugin surface imports since the MCP server was removed; only the tests exercise it. Its exports (`delegate`, `resolveModel`, `buildArgs`, `EventCollector`) are the reference for how `opencode run` must be invoked and how its JSON stream is parsed. Changing behaviour in `src/` does NOT change what the plugin does — the markdown files do. `opencode-worker` shells out to `opencode run` itself; keep its command consistent with `buildArgs`.
27
+
`src/`backs the MCP server (`src/index.ts`). The installed plugin cache has no `node_modules`, so what runs is the committed bundle `dist/index.js`: changing `src/` changes plugin behaviour only after `bun run build`, and CI fails if `dist/` is stale. Its exports (`delegate`, `resolveModel`, `buildArgs`, `EventCollector`) are also the reference for how `opencode run` must be invoked and how its JSON stream is parsed; `opencode-worker` shells out to `opencode run` itself, so keep its command consistent with `buildArgs`.
27
28
28
29
-`plugin-hooks/` holds the plugin's Claude Code hooks (registered via the `hooks` field in `plugin.json`); `hooks/` holds this repo's git hooks. Never put `hooks.json` in `hooks/`. The routing script is tested by `test/route-hook.test.ts`.
| MCP |`.mcp.json`, `dist/index.js`|`opencode` MCP server (bundled from `src/index.ts`): `delegate` and friends as main-thread tools |
20
21
21
-
No MCP server, no build step, no `dist/`. Claude Desktop is not supported.
22
+
The MCP server exposes seven tools: `delegate` (run and wait), `delegate_async` (background run, returns a task id), `task_result`, `task_list`, `task_cancel`, `list_models` and `list_sessions`. Claude can call `delegate` directly for implementation work without launching an agent. `dist/index.js` is a committed bundle (the installed plugin cache has no `node_modules`); rebuild it with `bun run build` after changing `src/`, CI fails if it is stale. Claude Desktop is not supported.
`.prettierignore` excludes local`.atl/`, `openspec/` and `odd/`. Tests are fixture-based and need no running services.
136
137
137
-
### Library (`src/`)
138
+
### MCP server and library (`src/`)
138
139
139
-
`src/` is a TypeScript library (`delegate`, `resolveModel`, `buildArgs`, `EventCollector`) left from the removed MCP server. No plugin surface imports it; only the tests exercise it, and it is the reference for how `opencode run` is invoked and its JSON stream parsed. Changing it does not change plugin behaviour. Its provider preference (direct provider over an aggregator, `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` first) applies only here, not to the worker. Variables read by `src/config.ts`:
140
+
`src/index.ts` is the MCP server entry point (`bun run start`, bundled to `dist/index.js` by `bun run build`); it builds on the `delegate`, `resolveModel`, `buildArgs`and `EventCollector` modules, which also document how `opencode run` is invoked and its JSON stream parsed. Changing `src/` changes the MCP tools, so rebuild and commit `dist/`. The provider preference (direct provider over an aggregator, `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` first) applies to the MCP server only, not to the worker. Variables read by `src/config.ts`:
Copy file name to clipboardExpand all lines: skills/opencode-delegate/SKILL.md
+19-6Lines changed: 19 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,29 @@ description: Delegate coding or analysis work to another model through OpenCode
5
5
6
6
# Delegating to OpenCode models
7
7
8
-
Use the `opencode` slash command (`/opencode <model> -- <task>`) or the `opencode-worker` agent to delegate tasks to an OpenCode model. The delegated model has its own tools (read, edit, shell), so it can implement code, not just answer. **You stay the orchestrator**: you hand over the task, and you review what comes back.
8
+
Use the `opencode`MCP tools, the `opencode`slash command (`/opencode <model> -- <task>`) or the `opencode-worker` agent to delegate tasks to an OpenCode model. The delegated model has its own tools (read, edit, shell), so it can implement code, not just answer. **You stay the orchestrator**: you hand over the task, and you review what comes back.
9
9
10
10
## Mechanism
11
11
12
-
The `opencode-worker` agent is the only mechanism. It is a thin forwarder that runs `opencode run --format json` directly and reports the session id, the reply and the changed files. It does not review, fix or retry.
12
+
The `opencode` MCP server runs `opencode run` in the project and returns the reply, session id, token usage and git changes. The `opencode-worker` agent is a thin forwarder that runs `opencode run --format json` directly and reports the same; it does not review, fix or retry.
|`list_models` (`filter?`) | Find the exact `provider/model` id. |
26
+
|`delegate`| Run a task and wait for the result. |
27
+
|`delegate_async` → `task_result` (`wait_s`) | Long tasks, or several models in parallel. Also `task_list`, `task_cancel`. |
28
+
|`list_sessions`| Find a `session_id` to continue. |
29
+
30
+
In a plugin install the tools are named like `mcp__plugin_opencode-delegate_opencode__delegate`. With a manual install they are `mcp__opencode__delegate`. The `prompt` must be a self-contained brief (the model cannot see this conversation); pass `auto: false` for read-only work, `session_id` to continue.
0 commit comments