Skip to content

Commit 3936057

Browse files
committed
refactor: strip MCP server, use agent activation instead
- Delete src/index.ts (MCP server with 6 tools) and .mcp.json - Remove @modelcontextprotocol/sdk and zod from dependencies - Remove dist/ from .gitignore (no more bundler output) - Rewrite README/AGENTS: no MCP, no build step, no dist/ - Rewrite SKILL.md and opencode-worker.md to use slash command and subagent activation instead of MCP tools - Update hooks to skip non-code docs (no ts files in src/ anymore) - net: -397 +77 = -320 lines (-50%)
1 parent 08c3f52 commit 3936057

12 files changed

Lines changed: 77 additions & 397 deletions

File tree

‎.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"homepage": "https://github.com/aashahin/claude-opencode-delegate",
77
"repository": "https://github.com/aashahin/claude-opencode-delegate",
88
"license": "MIT",
9-
"keywords": ["opencode", "delegate", "subagent", "mcp", "grok", "kimi", "glm", "qwen", "deepseek"]
9+
"keywords": ["opencode", "delegate", "subagent", "grok", "kimi", "glm", "qwen", "deepseek"]
1010
}

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ node_modules/
44
*.log
55
.bak*
66
*.bak.*
7-
dist/

‎.mcp.json‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎AGENTS.md‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
bun install # install deps (uses bun.lock)
77
bun test # run unit tests (fixture-based, no services needed)
88
bun run typecheck # TypeScript strict check (bun check)
9-
bun run build # bundle to dist/index.js
109
bun run lint # lint (eslint)
1110
bun run fmt # format check (prettier)
1211
bun run fmt:fix # auto-fix formatting (prettier)
1312
bun run verify # typecheck + test + lint + format (all-in-one)
14-
bun run start # run server from source (for interactive debugging)
1513
```
1614

1715
CI (`.github/workflows/ci.yml`) runs these in order: `install → verify`.
@@ -27,26 +25,21 @@ Configure after clone: `git config core.hooksPath hooks/`
2725

2826
## Architecture
2927

30-
Single-entry MCP server (`src/index.ts`) registering six tools: `list_models`, `delegate`,
31-
`delegate_async`, `task_result`, `task_list`, `task_cancel`, `list_sessions`.
32-
33-
Core modules:
28+
Claude Code plugin — no MCP server. Core modules:
3429

3530
| File | Role |
3631
| ------------- | ----------------------------------------------------------------------------------------- |
3732
| `config.ts` | Resolve `opencode` binary path, env-based defaults, bool/int helpers |
3833
| `models.ts` | Model listing (cached 5 min), loose-name → provider/model resolution, aggregator priority |
3934
| `opencode.ts` | Spawn `opencode run --format json`, fold JSON event stream into `EventCollector` |
40-
| `delegate.ts` | Build args, git-diff changed-files detection, format outcome for Claude |
35+
| `delegate.ts` | Build args, git-diff changed-files detection, format outcome |
4136
| `tasks.ts` | In-memory async task store (UUID keys, max 100 finished), prune oldest |
4237

4338
Tests mirror this structure: `test/models.test.ts` (resolution logic), `test/opencode.test.ts`
4439
(EventCollector + buildArgs). Fixtures are JSONL captured from real `opencode run` sessions.
4540

4641
## Gotchas
4742

48-
- **`dist/` is ignored** — changes to source must be bundled (`bun run build`) before release.
49-
Never run a production install from source alone.
5043
- **Model resolution rejects ambiguity.** `resolveModel("mimo", ...)` returns an error (not a
5144
guess) when multiple models tie. Tests assert this with `toStartWith("ERR:")`.
5245
- **`EventCollector` handles non-JSON.** If the stream emits non-JSON lines they fall through to
@@ -62,4 +55,3 @@ Tests mirror this structure: `test/models.test.ts` (resolution logic), `test/ope
6255

6356
- Slash command (`commands/opencode.md`) wraps the skill: `/opencode <model> -- <task>`
6457
- Claude Code plugin: install via `/plugin marketplace add aashahin/claude-opencode-delegate`
65-
- MCP server config: `.mcp.json` (uses `${CLAUDE_PLUGIN_ROOT}` placeholder for plugin installs)

‎README.md‎

Lines changed: 41 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,42 @@ the orchestrator. It plans the work, briefs the other model, reviews the diff, a
77
```
88
you ▸ use grok 4.7 from xAI in opencode to implement the CSV export, you review it
99
10-
claude ▸ delegate(model: "grok 4.7 from xAI", prompt: "<self-contained brief>")
11-
↳ xai/grok-4.7 edits src/export.ts, runs tests …
10+
claude ▸ spawn opencode-worker subagent with model "grok 4.7" and brief
11+
12+
opencode ▸ grok-4.7 edits src/export.ts, runs tests …
13+
1214
claude ▸ reviews git diff, runs `bun test`, and reports back
1315
```
1416

1517
It works in:
1618

17-
- **Claude Code** (CLI, IDE, desktop): you can ask directly, use `/opencode`, use the `opencode-worker` subagent, or use it from dynamic workflows.
18-
- **Claude Desktop** on Linux, macOS, or Windows, as a plain MCP server.
19+
- **Claude Code** (CLI, IDE, desktop): you can ask directly, use `/opencode`, use the
20+
`opencode-delegate` skill, or use the `opencode-worker` agent.
21+
- **Claude Desktop** on Linux, macOS, or Windows: use the skill/agent files directly or run
22+
OpenCode from the terminal.
1923

2024
## How it works
2125

2226
```
2327
Claude Code / Claude Desktop / subagent / workflow
24-
│ MCP (stdio)
28+
│ agent activation (skill, slash-command, subagent)
2529
▼
26-
opencode-delegate MCP server (Bun)
27-
│ spawns
30+
opencode-delegate skill/agent files
31+
│ guide Claude
2832
▼
2933
opencode run --format json -m <provider/model> [--auto] [--session …]
3034
```
3135

32-
The server shells out to the `opencode` CLI, so it uses your existing OpenCode auth, config, agents,
33-
MCP servers, and permission rules. It does not use a separate API.
36+
OpenCode is invoked directly via the slash command (`/opencode`) or the `opencode-worker` agent.
37+
No MCP server, no stdio transport, no bun bundler.
38+
39+
The `opencode` CLI uses your existing OpenCode auth, config, agents, and permission rules. It
40+
does not use a separate API.
3441

3542
## Requirements
3643

37-
- [Bun](https://bun.sh) ≥ 1.1
38-
- [OpenCode](https://opencode.ai) v2+ with at least one provider set up. Check that `opencode models` lists something.
44+
- [OpenCode](https://opencode.ai) v2+ with at least one provider set up. Check that
45+
`opencode models` lists something.
3946

4047
## Install
4148

@@ -46,38 +53,8 @@ MCP servers, and permission rules. It does not use a separate API.
4653
/plugin install opencode-delegate@claude-opencode-delegate
4754
```
4855

49-
This gives you the MCP server, the **opencode-delegate** skill, the **opencode-worker** subagent, and
50-
the **/opencode** command.
51-
52-
### Claude Code: MCP server only
53-
54-
```bash
55-
git clone https://github.com/aashahin/claude-opencode-delegate ~/.local/share/claude-opencode-delegate
56-
claude mcp add opencode -s user -- bun ~/.local/share/claude-opencode-delegate/dist/index.js
57-
```
58-
59-
### Claude Desktop
60-
61-
Clone the repo as shown above. Then add the server to `~/.config/Claude/claude_desktop_config.json`
62-
on Linux, or to `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS:
63-
64-
```json
65-
{
66-
"mcpServers": {
67-
"opencode": {
68-
"command": "/home/YOU/.bun/bin/bun",
69-
"args": ["/home/YOU/.local/share/claude-opencode-delegate/dist/index.js"],
70-
"env": { "OPENCODE_DELEGATE_CWD": "/home/YOU/projects/my-app" }
71-
}
72-
}
73-
}
74-
```
75-
76-
Use absolute paths, because Desktop doesn't load your shell `PATH`. The server searches for
77-
`opencode` in `~/.opencode/bin`, `~/.bun/bin`, `~/.local/bin`, and `/usr/local/bin`. If yours is
78-
somewhere else, set `OPENCODE_BIN`. If your providers read API keys from environment variables (for
79-
example `XAI_API_KEY`), add those to `env` too, or add the keys with `opencode auth login`.
80-
Desktop has no project directory, so either set `OPENCODE_DELEGATE_CWD` or ask Claude to pass `cwd`.
56+
This gives you the **opencode-delegate** skill, the **opencode-worker** agent, and the
57+
**/opencode** command.
8158

8259
## Usage
8360

@@ -107,23 +84,15 @@ You can use exact ids (`opencode-go/grok-4.7`) or loose names (`grok 4.7`, `kimi
10784
Read-only tasks (`auto: false`) use the free `opencode/muse-spark-1.3-contributor-free`. You can
10885
change both with the env vars below.
10986

110-
### Tools
87+
### Slash command
11188

112-
| Tool | What it does |
113-
| ------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
114-
| `list_models` | Lists the `opencode models` output. Takes an optional `filter`. |
115-
| `delegate` | Runs a task and waits for it. Returns the response, `session_id`, token usage, tools used, and git changes. |
116-
| `delegate_async` | Same as `delegate`, but returns a `task_id` right away. Use it for long jobs and parallel fan-out. |
117-
| `task_result` / `task_list` / `task_cancel` | Collect results (with `wait_s`), list tasks, or stop a background task. |
118-
| `list_sessions` | Lists recent opencode sessions, so you can find one to continue. |
89+
`/opencode <model> -- <task>` — delegate to an OpenCode model. The slash command expands the
90+
brief, spawns an `opencode-worker` subagent, and waits for the result.
11991

120-
`delegate` and `delegate_async` take these arguments:
92+
### Agent
12193

122-
- `prompt` and `model`
123-
- `cwd` and `agent` (for example `build`, `plan`, or your own agents)
124-
- `files` to attach
125-
- `session_id`, `continue`, or `fork` to follow up in an earlier session
126-
- `auto`, `title`, and `timeout_s`
94+
The `opencode-worker` agent is a ready-made supervisor. Give it a model and task — it gathers
95+
context, writes the brief, delegates, verifies, iterates, and reports.
12796

12897
### Permissions
12998

@@ -134,35 +103,33 @@ every change it gets back.
134103

135104
### Using it from workflows
136105

137-
Workflow `agent()` calls and subagents can use the MCP tools directly or through the `opencode-worker`
138-
agent. If you fan out tasks that edit files, give each one its own `git worktree` so they don't
139-
conflict.
106+
Workflow `agent()` calls and subagents can use the `opencode-worker` agent directly. If you fan out
107+
tasks that edit files, give each one its own `git worktree` so they don't conflict.
140108

141109
## Configuration (env vars)
142110

143-
| Variable | Default | |
144-
| --------------------------------------- | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
145-
| `OPENCODE_BIN` | auto-detected | Path to the `opencode` executable. |
146-
| `OPENCODE_DELEGATE_DEFAULT_MODEL` | `opencode-go/muse-spark-1.3-contributor` | Model used when `model` is omitted. Set it to `""` to use opencode's own default. |
147-
| `OPENCODE_DELEGATE_READ_MODEL` | `opencode/muse-spark-1.3-contributor-free` | Model used when `model` is omitted and `auto` is false (reading files, reviews, questions). Free by default. |
148-
| `OPENCODE_DELEGATE_AUTO` | `true` | Default for `auto`. |
149-
| `OPENCODE_DELEGATE_TIMEOUT` | `1800` | Seconds before a run is killed. |
150-
| `OPENCODE_DELEGATE_MAX_OUTPUT` | `40000` | Maximum number of response characters returned to Claude. |
151-
| `OPENCODE_DELEGATE_CWD` | the server's cwd | Base directory for `cwd`. |
152-
| `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` | _(none)_ | Comma-separated provider order used when a model is offered by several providers, e.g. `xai,opencode-go`. Without it, the model maker's own provider beats resellers. |
111+
| Variable | Default | Description |
112+
| --------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
113+
| `OPENCODE_BIN` | auto-detected | Path to the `opencode` executable. |
114+
| `OPENCODE_DELEGATE_DEFAULT_MODEL` | `opencode-go/muse-spark-1.3-contributor` | Model used when `model` is omitted. Set it to `""` to use opencode's own default. |
115+
| `OPENCODE_DELEGATE_READ_MODEL` | `opencode/muse-spark-1.3-contributor-free` | Model used when `model` is omitted and `auto` is false (reading files, reviews, questions). Free by default. |
116+
| `OPENCODE_DELEGATE_AUTO` | `true` | Default for `auto`. |
117+
| `OPENCODE_DELEGATE_TIMEOUT` | `1800` | Seconds before a run is killed. |
118+
| `OPENCODE_DELEGATE_MAX_OUTPUT` | `40000` | Maximum number of response characters returned to Claude. |
119+
| `OPENCODE_DELEGATE_CWD` | the server's cwd | Base directory for `cwd`. |
120+
| `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` | _(none)_ | Comma-separated provider order used when a model is offered by several providers, e.g. `xai,opencode-go`. |
121+
| `OPENCODE_DELEGATE_THINKING` | `true` | Include `--thinking` so reasoning/thinking blocks appear in output. |
153122

154123
## Development
155124

156125
```bash
157126
bun install
158127
bun test # unit tests (fixtures captured from real `opencode run --format json`)
159128
bun run typecheck
160-
bun run build # bundles to dist/index.js, which is committed so installs need no build step
161-
bun run start # run the server from source
129+
bun run lint
130+
bun run fmt
162131
```
163132

164-
To debug interactively, use `bunx @modelcontextprotocol/inspector bun dist/index.js`.
165-
166133
## License
167134

168135
MIT

‎agents/opencode-worker.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ delegated model fails twice.
1515
test/build commands.
1616
3. **Write a self-contained brief**: goal, context and paths, constraints, acceptance criteria, and a
1717
short report of the changes at the end. The model cannot see your conversation.
18-
4. **Delegate** with the opencode MCP `delegate` tool (named `mcp__plugin_opencode-delegate_opencode__delegate`
19-
or `mcp__opencode__delegate`). If the result is an ambiguous-model error, pick the best candidate
20-
that fits the instructions. If the instructions name a provider, choose that provider.
18+
4. **Delegate** by spawning a subagent with the opencode `delegate` logic — use the model name and brief as the subagent prompt. If the result is an ambiguous-model error, pick the best candidate that fits the instructions. If the instructions name a provider, choose that provider.
2119
5. **Verify**: read the git changes it reports and run the tests or build.
2220
6. **Iterate** at most twice. Call `delegate` again with the same `session_id` and give concrete
2321
feedback on what is wrong.

‎commands/opencode.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ argument-hint: <model> -- <task>
55

66
Delegate this to an OpenCode model, following the opencode-delegate skill: $ARGUMENTS
77

8-
The text before `--` is the model name. Pass it to the tool unchanged, and the server will resolve
9-
it. If there is no `--`, work out the model name from the text, or leave the model out.
8+
The text before `--` is the model name. If there is no `--`, work out the model name from the
9+
text, or leave the model out.
1010

11-
The text after `--` is the task. Before you call `delegate`, expand it into a self-contained brief
11+
The text after `--` is the task. Before spawning the subagent, expand it into a self-contained brief
1212
using what you know about this project.
1313

14-
When it returns, review its git changes, run the relevant tests, and give me a summary. The summary
15-
should say which model did the work, what it changed, and your verdict.
14+
When the subagent returns, review its git changes, run the relevant tests, and give me a summary. The
15+
summary should say which model did the work, what it changed, and your verdict.

‎hooks/pre-commit‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -euo pipefail
33

44
# pre-commit: lint and format-check staged files only.
5-
# Skips if no staged files or only docs changed.
5+
# Skips if no staged files or only non-code docs changed.
66

77
echo "🔍 Running pre-commit hooks..."
88

@@ -23,14 +23,14 @@ else
2323
echo " (no formatable files staged, skipping)"
2424
fi
2525

26-
# 2. ESLint on staged .ts files only
27-
TS_FILES=$(echo "$STAGED" | grep -E '\.ts$' || true)
26+
# 2. ESLint on staged .ts files only (core lib only)
27+
TS_FILES=$(echo "$STAGED" | grep -E '^\s*src/.*\.ts$' || true)
2828
if [ -n "$TS_FILES" ]; then
2929
echo " 📋 ESLint on staged files..."
3030
npx eslint $TS_FILES
3131
echo " ✓ ESLint passed"
3232
else
33-
echo " (no .ts files staged, skipping)"
33+
echo " (no .ts files in src/ staged, skipping)"
3434
fi
3535

3636
echo "✅ Pre-commit hooks passed"

‎hooks/pre-push‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -euo pipefail
33

44
# pre-push: run full verify (typecheck, test, lint, format).
55
# Skips on dry-run or if CI is the proper gate.
6+
# No build step — no MCP bundler, just the core lib.
67

78
echo "🚀 Running pre-push hooks..."
89

‎package.json‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "claude-opencode-delegate",
33
"version": "0.1.0",
4-
"description": "MCP server + Claude Code plugin that lets Claude delegate tasks to any OpenCode model (Grok, Kimi, GLM, Qwen, DeepSeek…) while staying the orchestrator.",
4+
"description": "Claude Code plugin — delegate tasks to any OpenCode model (Grok, Kimi, GLM, Qwen, DeepSeek…) via agent activation, while Claude stays the orchestrator.",
55
"type": "module",
66
"license": "MIT",
77
"author": "aashahin",
@@ -12,38 +12,31 @@
1212
"keywords": [
1313
"claude",
1414
"claude-code",
15-
"claude-desktop",
16-
"mcp",
1715
"opencode",
1816
"subagent",
1917
"delegate"
2018
],
21-
"bin": {
22-
"claude-opencode-delegate": "dist/index.js"
23-
},
2419
"files": [
25-
"dist",
2620
"src",
21+
"skills",
22+
"agents",
23+
"commands",
24+
".claude-plugin",
2725
"README.md",
2826
"LICENSE"
2927
],
3028
"engines": {
3129
"bun": ">=1.1"
3230
},
3331
"scripts": {
34-
"start": "bun src/index.ts",
35-
"build": "bun build src/index.ts --target=bun --outfile=dist/index.js",
3632
"typecheck": "tsc --noEmit",
3733
"test": "bun test",
3834
"lint": "eslint . --max-warnings 0",
3935
"fmt": "prettier --check \"**/*.{ts,js,json,md,yml,yaml}\"",
4036
"fmt:fix": "prettier --write \"**/*.{ts,js,json,md,yml,yaml}\"",
4137
"verify": "bun run typecheck && bun test && bun run lint && bun run fmt"
4238
},
43-
"dependencies": {
44-
"@modelcontextprotocol/sdk": "^1.30.0",
45-
"zod": "^4.6.5"
46-
},
39+
"dependencies": {},
4740
"devDependencies": {
4841
"@eslint/js": "^10.0.1",
4942
"@types/bun": "^1.4.2",

0 commit comments

Comments
 (0)