claudelegate

mcp
Guvenlik Denetimi
Uyari
Health Uyari
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 5 GitHub stars
Code Gecti
  • Code scan — Scanned 12 files during light audit, no dangerous patterns found
Permissions Gecti
  • Permissions — No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

Claude Code plugin: delegate coding tasks to any OpenCode model (Grok, Kimi, GLM, Qwen, DeepSeek, MiMo, local). Claude orchestrates, the model implements, Claude reviews the diff and runs the tests. Skill, agent and /opencode command.

README.md

Claudelegate

CI CodeQL Release npm GitHub release License: MIT

A Claude Code plugin that hands scoped coding work to any model in your OpenCode install, whether it runs locally (Ollama, llama.cpp), behind a proxy such as LiteLLM, or at a hosted provider. Claude plans and reviews while a cheaper model writes the code.

you    ▸ /opencode add input validation to the signup form
claude ▸ spawns opencode-worker (model: OpenCode default, mode: write)
worker ▸ MCP delegate → session ses_abc, 3 files changed, report
claude ▸ reads git diff, runs tests, reports which model did what and a verdict

Install

/plugin marketplace add lehcode/claudelegate
/plugin install claudelegate@lehcode

To use a local clone, add it as a directory marketplace: /plugin marketplace add /path/to/clone. After pulling changes, refresh the plugin (/plugin → update, or reinstall).

Requirements

Claudelegate is built for Claude Code. In claude.ai chat its hooks, agent and local MCP server don't load, so the skill and command there can't run anything. Cowork loads them only when the session runs on your own computer with the requirements below, but it hasn't been tested there.

  • OpenCode v2 or later with at least one provider configured (verified on 2.1.3)
  • Bun 1.1 or later, which runs the MCP server
  • jq on PATH
  • git

Example setup

Claudelegate can use any model that opencode models lists. The two setups below are illustrations: every host, model name and limit is a placeholder. Both serve a model called coder-32b from a llama.cpp llama-server on another machine (model-host), next to a local Ollama. Replace the names with your own.

Without a proxy

OpenCode talks to llama-server directly through an OpenAI-compatible provider. List every model the server exposes under models.

// ~/.config/opencode/opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "default_agent": "plan",
  "model": "llamacpp/coder-32b",
  "providers": {
    "llamacpp": {
      "package": "aisdk:@ai-sdk/openai-compatible",
      "name": "llama.cpp on model-host",
      "settings": { "baseURL": "http://model-host:8080/v1" },
      "models": {
        "coder-32b": { "name": "Coder 32B", "limit": { "context": 32768, "output": 8192 } },
      },
    },
  },
}

If llama-server runs with --api-key, add "apiKey": "{env:LLAMA_API_KEY}" to settings.

$ opencode models
llamacpp/coder-32b
ollama/coder:7b
ollama/coder:14b

With a LiteLLM proxy

LiteLLM runs next to OpenCode and forwards to llama-server. OpenCode gets one provider for everything behind the proxy, and the model ids are LiteLLM's model_name aliases.

# LiteLLM config.yaml
model_list:
  - model_name: coder-32b
    litellm_params:
      model: openai/coder-32b
      api_base: http://model-host:8080/v1
      api_key: none
// ~/.config/opencode/opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "default_agent": "plan",
  "model": "litellm/coder-32b",
  "providers": {
    "litellm": {
      "package": "aisdk:@ai-sdk/openai-compatible",
      "name": "LiteLLM",
      "settings": {
        "baseURL": "http://127.0.0.1:4000/v1",
        "apiKey": "{env:LITELLM_API_KEY}",
      },
      "models": {
        "coder-32b": {
          "name": "Coder 32B via LiteLLM",
          "limit": { "context": 32768, "output": 8192 },
        },
      },
    },
  },
}

opencode models then lists litellm/coder-32b instead of llamacpp/coder-32b. The Ollama models are the same.

Concern Without a proxy With LiteLLM
OpenCode providers One per server One for everything behind the proxy
Model ids llamacpp/coder-32b litellm/coder-32b
Adding or moving a model Edit opencode.jsonc Edit LiteLLM's model_list, then add the alias to models
Keys One per provider in opencode.jsonc One LiteLLM key; upstream keys stay in LiteLLM
Extras None LiteLLM's routing, fallbacks and spend logs

Default model

Claudelegate passes no model, so OpenCode runs the model set in opencode.jsonc (litellm/coder-32b with the proxy, llamacpp/coder-32b without it). Change the default there, not in Claudelegate.

Permissions in delegated runs

Delegated runs use your OpenCode permission rules. This example asks by default and allows reads:

"permissions": [
  { "action": "*", "resource": "*", "effect": "ask" },
  { "action": "read", "resource": "*", "effect": "allow" },
  { "action": "read", "resource": "/**/.env.*", "effect": "deny" },
  { "action": "shell", "resource": "git status *", "effect": "allow" },
  { "action": "shell", "resource": "git push *", "effect": "ask" },
  { "action": "subagent", "resource": "*", "effect": "allow" }
]
Rule effect Read-only (--agent plan) Write (--agent build --auto)
allow Runs Runs
ask Rejected Approved
deny Refused Refused
subagent, any effect Refused; Claudelegate appends a deny Refused

--auto approves every ask rule, so in write mode git push * above would run. Use deny for anything a delegated run must never do. default_agent: plan doesn't block writes, because write mode passes --agent build.

Usage

Say "Use opencode to add tests for src/date.ts." Or use the slash command: /opencode <task>, for example /opencode write unit tests for src/date.ts. OpenCode runs its configured default model. You can also spawn the claudelegate:opencode-worker agent from a workflow with the task in its prompt. Claude does this on its own for ordinary implementation work. To override the model for one task, see Modes and Models.

How it works

flowchart LR
    C[Claude] -->|model + task + mode| W[opencode-worker]
    W -->|brief| M["MCP delegate"]
    M -->|opencode run, JSON events| W
    W -->|"verifies git changes + tests, iterates ≤2, report <200 words"| C
    C -->|reviews diff, runs tests| C
    C -.->|feedback + session id, new worker| W

The main thread spawns the background opencode-worker (Haiku, no edit tools). The worker resolves model and mode (read-only tasks pass auto: false), writes a self-contained brief, calls the MCP delegate tool, checks the git diff and runs tests or build, retries at most twice with the same session, otherwise reports reject. Its report has model, session id, changed files, verification and verdict, under 200 words. A timed-out run isn't retried; the worker reports the session id so you can continue.

The main thread never calls delegate itself: a hook denies it. For each delegate call, the MCP server runs:

opencode run --format json --standalone --agent build --auto [-m provider/model[#variant]] [--session <id>] --title "<title>" -- "<prompt>" </dev/null

The run uses your existing OpenCode auth, config, agents and permission rules. The server also sets OPENCODE_CONFIG_CONTENT to deny OpenCode's subagent permission, so the model does the work in its own session. --standalone is needed because the background OpenCode service ignores the client's environment.

What the plugin runs and sends

Component Runs Data leaving the machine
MCP server (bun dist/index.js) opencode run, opencode models, opencode session list, git status --porcelain in the target directory None by itself: no network calls, no telemetry
opencode run Your OpenCode install, with your config, auth and permission rules The task prompt, attached files, and any repository content the model reads, sent to the provider configured in OpenCode for the chosen model (a hosted API or your own endpoint, such as a local server)
Routing hook scripts/route-to-opencode.sh (jq, command -v opencode) None; it rewrites built-in subagent calls to claudelegate:opencode-worker (see Automatic routing)
Main-thread guard hook scripts/guard-main-thread-mcp.sh (jq) None; it denies delegate and delegate_async from the main thread

In write mode OpenCode runs with --auto, so the delegated model edits files and runs commands in the target directory without asking. Read-only mode omits --auto. Review the diff before you commit.

Automatic routing

Built-in subagents (general-purpose, claude, Explore, Plan, claude-code-guide, statusline-setup) are rewritten to claudelegate:opencode-worker on Haiku. Explore, Plan and claude-code-guide become read-only. Custom, project, user, plugin, reviewer and SDD agents stay on Claude.

To opt out, set OPENCODE_DELEGATE_ROUTE to 0, false, no or off (this also disables the main-thread guard), or put [no-opencode] in a single prompt. Routing is also skipped when opencode or jq can't be found.

A hook denies delegate and delegate_async calls from the main thread. Calls from inside a subagent pass because Claude Code sends agent_id only there. The MCP server sends instructions that make delegation the default.

Modes and Models

Mode When OpenCode flags
write (default) Code, fix, refactor --agent build --auto
read-only Review, question, summary, second opinion --agent plan (no --auto)
Input Behaviour
none -m omitted; OpenCode uses its configured default model
exact provider/model Used as is
loose name (grok 4.7) Resolved against opencode models; a named version must match exactly (4.7 never becomes 4.6)
ambiguous loose name delegate returns the candidates and the worker picks the one that fits the task best
provider/model#variant Variant preserved, for example xai/grok-4.7#high

The plugin has no built-in default models. Write mode passes --agent build because default_agent is often plan, and --auto, so OpenCode approves its own permission requests and edits files and runs commands without asking. Without --auto headless runs reject permission requests automatically, which makes plan safe. The </dev/null redirect is required: with an open stdin pipe, opencode run waits forever.

Continuing and parallel work

Continue by spawning claudelegate:opencode-worker again with the session id and precise feedback. The run is killed after OPENCODE_DELEGATE_TIMEOUT seconds (1800 by default). Parallel writers share the working directory, so use separate git worktrees (git worktree add) or non-overlapping files. To compare models, give the same task to each in its own worktree and diff the results.

Configuration

Variable Default Description
OPENCODE_BIN opencode Path to the opencode executable; when unset, the MCP server searches PATH and common install dirs and the routing hook uses opencode from PATH
OPENCODE_DELEGATE_ROUTE on 0, false, no or off disables automatic routing and the main-thread guard
OPENCODE_DELEGATE_DEFAULT_MODEL unset Model when none is given; unset or empty means OpenCode's configured default
OPENCODE_DELEGATE_AUTO true Default for auto; 0, false, no, off disable it
OPENCODE_DELEGATE_TIMEOUT 1800 Seconds before a run is killed
OPENCODE_DELEGATE_MAX_OUTPUT 40000 Response character limit
OPENCODE_DELEGATE_THINKING true Include reasoning blocks in output
OPENCODE_DELEGATE_CWD process cwd Base working directory
OPENCODE_DELEGATE_PREFERRED_PROVIDERS none Comma-separated provider order when a model has more than one provider

The variables are read by the MCP server unless noted. These are the only variables the plugin honours.

Standalone server

The MCP server also runs outside Claude Code (needs Bun). Register it in any MCP client with command bunx and args ["@lehcode/claudelegate"], as in examples/claude_desktop_config.json, or with command bun and args ["/path/to/clone/dist/index.js"] for a local clone.

Development

bun install
bun run verify                     # typecheck + test + lint + format
bun test test/models.test.ts       # one file
bun test -t "<name>"               # filter by test name
git config core.hooksPath hooks/   # pre-commit (staged lint/format), pre-push (verify)

Tests are fixture-based and need no running services.

src/

src/index.ts is the MCP server entry point, dist/index.js is a committed bundle built with bun run build, and CI fails if it's stale, so rebuild and commit dist/ after changing src/. The plugin cache has no node_modules, which is why the bundle is committed.

Releasing

Automated by release-please (.github/workflows/release.yml). Conventional commits merged to main open or update a release PR that bumps package.json, .claude-plugin/plugin.json and .claude-plugin/marketplace.json and writes CHANGELOG.md. Merging it creates the vX.Y.Z tag and GitHub release. Never edit versions by hand.

Release PRs are opened with the RELEASE_PLEASE_TOKEN secret (PAT or app token with contents and pull-requests write), because PRs made with the default GITHUB_TOKEN don't trigger CI.

The same run publishes the release to npm when the repository variable NPM_PUBLISH is true; set it to false to pause publishing. The publish job uses npm trusted publishing (OIDC, no token, provenance automatic), with the trusted publisher on npmjs.com set to repository lehcode/claudelegate, workflow release.yml. If it fails with E403 right after the trusted publisher was added or changed, re-run the failed job (gh run rerun <run-id> --failed).

License

MIT. See LICENSE.

Yorumlar (0)

Sonuc bulunamadi