claude-code-delegate-local
English · Español
Table of contents
- What it solves
- Features
- Quick install
- Choose a gateway
- Configuration
- Tools exposed
- Backends and model families
- Completion notifications
- Concurrency pools and failover
- 3-tier agent lookup
- Dual-format backend routing
- Best practices
- Further reading
- Recent changes
- Contributing
- License
What it solves
delegate-local is an MCP server for Claude Code. Keep Claude Code as the orchestrator and send individual tasks to a local model, a cloud API, Codex CLI, Google Antigravity CLI, or a DeepSeek Harness launcher.
Features
- Run Markdown agents with file tools and optional shell execution through an HTTP backend.
- Run independent Markdown agents in a synchronous batch, or submit CLI jobs and watch them in the background.
- Check backend health and discover agent definitions from the orchestrator.
Quick install
Use Python 3.11 or later, uv, and Claude Code. Choose a gateway below, then run these commands from the repository checkout with the gateway environment flags added to the registration command.
uv sync --locked
claude mcp add delegate-local \
--scope user \
-- uv run --directory "$(pwd)" python server.py
Restart Claude Code after registration or changes to the MCP server. Install the watcher on your PATH with uv tool install --force .. Check that the shell used by Claude Code can run delegate-wait --help.
Choose a gateway
| Gateway | When to choose it | What to configure |
|---|---|---|
| Bifrost (recommended) | Go gateway designed for low latency. This project uses Bifrost in production. | Base URL, optional local URL, API mode, and virtual keys if required. |
| LiteLLM (code default) | Python proxy with a wide provider list. | Messages endpoint and proxy key if required. Start with the LiteLLM YAML example. |
Set the variables below in the Claude Code MCP server environment using --env NAME=value when registering the server. Set DELEGATE_LOCAL_MODEL if you need to select a different default model alias. The alias must exist on the configured backend.
Bifrost
DELEGATE_GATEWAY=bifrost
DELEGATE_BIFROST_URL=https://bifrost.example.invalid
DELEGATE_BIFROST_API=litellm
DELEGATE_BIFROST_URLis required. Both URL variables accept HTTP(S) URLs with a host and no embedded credentials.local-*andornith*aliases useDELEGATE_BIFROST_LOCAL_URLwhen set, otherwise they useDELEGATE_BIFROST_URL. They useDELEGATE_BIFROST_VK_LOCALfor authentication. All other aliases useDELEGATE_BIFROST_URLandDELEGATE_BIFROST_VK_CODE. Set the relevant virtual keys if your gateway requires them. Requests send a configured key as both a Bearer token andx-api-key.- With a base URL, the default
DELEGATE_BIFROST_API=litellmsends Anthropic messages to/litellm/v1/messagesand OpenAI-format aliases to/litellm/v1/chat/completions. A base ending in/litellmgets/v1/messagesappended, and a full/v1/messagesendpoint is used as supplied for Anthropic messages. SetDELEGATE_BIFROST_API=openaito send all gateway-routed models to/v1/chat/completionson the selected base, with compatibility suffixes removed. DELEGATE_BIFROST_LOCAL_MAX_TOKENScaps output tokens for local aliases. It defaults to16384and accepts integers from1to1000000.
Use the Bifrost environment example for optional settings. The companion Bifrost kit provides ready-made configuration and installers for macOS and WSL2.
LiteLLM
DELEGATE_GATEWAY=litellm
DELEGATE_LOCAL_URL=http://localhost:4000/v1/messages
# DELEGATE_LOCAL_KEY=<proxy-key>
LiteLLM is selected when the selector is unset or blank. DELEGATE_LOCAL_URL defaults to the endpoint above. Anthropic-format requests use that endpoint directly. OpenAI-format aliases use /v1/chat/completions on the base derived from it. Set DELEGATE_LOCAL_KEY if your proxy requires authentication. Requests send it as both a Bearer token and x-api-key. Configure provider credentials in the proxy environment.
Startup selection and health checks
Optionally set DELEGATE_GATEWAY_FILE to a nonempty path to override DELEGATE_GATEWAY at startup. Use a regular file owned by the MCP process user with mode 0600, no symlink, and at most 4096 bytes of UTF-8 JSON, such as {"selector":"bifrost"} or {"selector":"litellm"}. An invalid file or an unknown active selector stops startup.
Run local_backend_status to check liveness and available models for the default alias. LiteLLM checks /health/liveliness and /v1/models on the derived base. Bifrost checks /health with a trailing /litellm removed from that base and queries /v1/models on the derived base. With a plain Bifrost base URL, the model query goes to /litellm/v1/models in either API mode.
Configuration
Set these variables in the Claude Code MCP environment.
| Variable | Default | Purpose |
|---|---|---|
DELEGATE_LOCAL_URL | http://localhost:4000/v1/messages | Default LiteLLM endpoint. |
DELEGATE_LOCAL_KEY | Unset | Key sent as both bearer token and x-api-key. |
DELEGATE_LOCAL_MODEL | local-qwen-3-6-35b | Default HTTP model alias. |
DELEGATE_LOCAL_CODING_MODEL | DELEGATE_LOCAL_MODEL | Alias for recognized coding agents when model is omitted. |
DELEGATE_LOCAL_AGENTS_DIR | ~/.claude/agents | Global Markdown agent directory. |
DELEGATE_GATEWAY | litellm | Select litellm or bifrost. |
DELEGATE_GATEWAY_FILE | Unset | Overrides the selector at startup. Use an owned regular file with mode 0600 containing {"selector":"bifrost"} or the equivalent for LiteLLM. |
DELEGATE_BIFROST_URL | Unset | HTTP(S) base URL for Bifrost, without embedded credentials. |
DELEGATE_BIFROST_LOCAL_URL | DELEGATE_BIFROST_URL | Optional base URL for local-* and ornith*. |
DELEGATE_BIFROST_API | litellm | Use /litellm routes or set openai for /v1/chat/completions on both lanes. |
DELEGATE_BIFROST_VK_LOCAL, DELEGATE_BIFROST_VK_CODE | Unset | Virtual keys for the local and other model routes, respectively. |
DELEGATE_BIFROST_LOCAL_MAX_TOKENS | 16384 | Output token cap on the local Bifrost route. |
DELEGATE_PROVIDER_ALLOWED_HOSTS | Unset | Comma-separated host allowlist for explicit provider calls. |
DELEGATE_TOOL_PROFILE | full | Tool catalog. Set to async to expose only the nine CLI job tools and local_backend_status. |
DELEGATE_LOCAL_MAX_TURNS, DELEGATE_CLOUD_MAX_TURNS, DELEGATE_HARD_MAX_TURNS | 25 / 60 / 150 | Automatic local and cloud turn budgets, then the hard ceiling. |
DELEGATE_MAX_BATCH_SIZE | 12 | Maximum tasks per HTTP batch. |
DELEGATE_TURN_TIMEOUT, DELEGATE_DISPATCH_TIMEOUT | 1800 / 3600 | Per-call and dispatch time budgets in seconds. |
DELEGATE_BATCH_TASK_TIMEOUT | 4500 with defaults | Batch task deadline in seconds. Defaults to dispatch timeout plus queue grace. Set to 0 to disable. |
DELEGATE_BATCH_QUEUE_GRACE, DELEGATE_BATCH_HEARTBEAT_S | 900 / 20 | Batch queue allowance and progress heartbeat, in seconds. |
DELEGATE_CONCURRENCY_DEFAULT | 4 | HTTP pool size when no model bucket matches. |
DELEGATE_CROSS_PROCESS_SLOTS, DELEGATE_SLOT_DIR, DELEGATE_SLOT_POLL | 1 / ~/.cache/claude-delegate-local/slots / 0.5 | Shared HTTP slots, lock directory, and retry interval in seconds. |
DELEGATE_FAILOVER, DELEGATE_FAILOVER_GRACE | 0 / 10 | Opt into HTTP failover for omitted models and set fallback slot wait in seconds. |
DELEGATE_STREAMING, DELEGATE_PROMPT_CACHING | 1 / 1 | Enable HTTP streaming and cache markers for supported models. |
DELEGATE_RESEND_REASONING | auto | Replay reasoning for DeepSeek in auto mode. Use always or never to override. |
DELEGATE_MAX_NUDGES, DELEGATE_KEEP_TOOL_RESULTS | 1 / 6 | Completion nudges and retained recent tool results. |
DELEGATE_MAX_READ_FILE_BYTES, DELEGATE_MAX_WRITE_BYTES | 64 MiB / 8 MiB | File size limits for the HTTP agent tools. |
DELEGATE_RUN_BASH | 1 | Enables shell execution for HTTP agents. |
DELEGATE_RUN_BASH_TIMEOUT, DELEGATE_CLOUD_RUN_BASH_TIMEOUT, DELEGATE_RUN_BASH_MAX | 120 / 600 / 1800 | Local and cloud shell timeouts and the hard cap, in seconds. |
DELEGATE_RUN_BASH_CONCURRENCY, DELEGATE_ENV_PASSTHROUGH | 4 / unset | Maximum concurrent shell calls and extra child environment variables, comma-separated. |
DELEGATE_LOG, DELEGATE_LOG_PATH, DELEGATE_LOG_MAX_BYTES | 1 / ~/.cache/claude-delegate-local/dispatches.jsonl / 8 MiB | Dispatch logging, log path, and rotation threshold. |
DELEGATE_CODEX_BIN, DELEGATE_CODEX_MODEL, DELEGATE_CODEX_EFFORT | codex / gpt-6.2-sol / low | Codex executable, model, and effort. |
CODEX_HOME | ~/.codex | Codex configuration and authentication directory. |
DELEGATE_CODEX_STATE_DIR, DELEGATE_CODEX_SESSIONS_DIR | ~/.codex-jobs / ~/.codex/sessions | Job state and session logs used for quota readings. |
DELEGATE_CODEX_MAX_CONCURRENT, DELEGATE_CODEX_MAX_PER_PROJECT, DELEGATE_CODEX_MAX_QUEUE | 8 / 6 / 32 | Global, per-project, and waiting-job limits. |
DELEGATE_CODEX_STAGGER_S, DELEGATE_CODEX_LOCK_WAIT_S | 2.5 / 600 | Launch spacing and blocking tool lock wait in seconds. |
DELEGATE_CODEX_QUOTA_WARN, DELEGATE_CODEX_QUOTA_DOWNGRADE_PCT, DELEGATE_CODEX_QUOTA_REFUSE_PCT | 65 / 70 / unset | Weekly usage thresholds for warnings, lowering effort, and refusing new requests. |
DELEGATE_CODEX_ALLOW_DANGER, DELEGATE_CODEX_STDOUT_CAP | 0 / 512 KiB | Opt in to danger-full-access and set the stdout buffer limit. |
DELEGATE_AGY_BIN | Unset | Optional path to the Antigravity CLI. |
DELEGATE_GEMINI_ALLOW_DANGER, DELEGATE_GEMINI_AGY_SANDBOX_FLAG | 0 / 1 | Required opt-in for Antigravity and toggle for its own --sandbox flag. The outer jail remains active. |
DELEGATE_GEMINI_STATE_DIR | ~/.gemini-jobs | Antigravity job state. |
DELEGATE_GEMINI_MAX_CONCURRENT, DELEGATE_GEMINI_MAX_QUEUE | 4 / 32 | Antigravity concurrency and queue limits per server. |
DELEGATE_DSH_LAUNCHER | Unset | Path to the launcher. Required to use the dsh tools. |
DELEGATE_DSH_MODELS_FILE | Built-in path | Set this to your model allowlist. See the example. |
DELEGATE_DSH_STATE_DIR | ~/.dsh-jobs | DeepSeek Harness job state. |
DELEGATE_DSH_MAX_CONCURRENT, DELEGATE_DSH_MAX_PER_PROJECT, DELEGATE_DSH_MAX_QUEUE | 2 / 2 / 16 | Global, per-project, and waiting-job limits. |
DELEGATE_DSH_STAGGER_S, DELEGATE_DSH_KILL_GRACE_S | 5 / 60 | Launch spacing and cancellation grace in seconds. |
DELEGATE_WAIT_INTERVAL, DELEGATE_WAIT_TAG_LOOKBACK_S | 5 / 600 | Watcher poll interval and tag lookback in seconds. The lookback also applies when checking tag reuse. |
DELEGATE_TEST_ISOLATION, DELEGATE_TEST_ISOLATION_ROOT | Unset | Test-only storage guard. Presence of the first variable requires an absolute storage root in the second. |
Tools exposed
| Tool | Purpose |
|---|---|
delegate_to_local_agent | Run a Markdown agent on the configured backend and wait for the result. |
delegate_batch | Run Markdown agent tasks in parallel and return results in input order. |
delegate_to_provider | Run a Markdown agent with an explicit provider URL, key, and model. |
list_local_agents | List global agent definitions and their metadata. |
local_backend_status | Check the configured backend and list its available models. |
delegate_to_codex | Run one Codex CLI task and wait for the result. |
submit_codex | Submit Codex tasks and return job IDs and a watcher command. |
poll_codex | Fetch Codex job status and output by ID. |
cancel_codex | Cancel a queued or running Codex job owned by this server. |
delegate_to_gemini | Run one Antigravity CLI task and wait for the result. |
submit_gemini | Submit Antigravity tasks and return job IDs and a watcher command. |
poll_gemini | Fetch Antigravity job status and output by ID. |
cancel_gemini | Cancel a queued or running Antigravity job owned by this server. |
submit_dsh | Submit DeepSeek Harness tasks and return job IDs and a watcher command. |
poll_dsh | Fetch DeepSeek Harness job status and output by ID. |
cancel_dsh | Cancel a queued or running DeepSeek Harness job owned by this server. |
The HTTP agent tools accept max_turns=0 for automatic selection. The defaults are 25 local turns and 60 cloud turns, with a hard ceiling of 150. delegate_batch accepts up to 12 tasks by default and caps each final response at 900 characters unless you pass full=True. Pass full=True to include per-task telemetry and nudge replies.
HTTP agent shell calls always rerun. File writes and shell calls invalidate cached reads. Provider requests omit internal message metadata.
Backends and model families
- HTTP. Use LiteLLM, Bifrost, or an explicit compatible endpoint. Configure aliases for local inference such as llama.cpp, or cloud providers such as DeepSeek, Qwen, MiniMax, GLM, and Bedrock.
- Codex CLI. Sign in with ChatGPT using
codex login. The default isgpt-6.2-solatlow. The server acceptsgpt-6.2-{sol,astra},gpt-6.1-{sol,terra},gpt-6-{sol,astra,luna},gpt-5.6-{sol,terra,luna},gpt-5.5,gpt-5.4, andgpt-5.4-mini. Usesolor6.2-solforgpt-6.2-sol,astraor6.2-astraforgpt-6.2-astra,terraforgpt-6.1-terra, andlunaforgpt-6-luna. The minimum CLI versions are 0.169 for 6.2 and 0.159 for 6.1. - Antigravity CLI. Install and sign in to
agybefore using it. Requires macOSsandbox-execandDELEGATE_GEMINI_ALLOW_DANGER=1. Thefamilyvalues aregemini(default,gemini-3.8-flash-*),sonnet(claude-sonnet-5-5-*), andargon,hydrogen,neon, orcarbon(gemini-4-<family>-*). Each supportslow,medium(default), andhigh. A detected quota failure can returnquota_exhaustedand a suggestedfailovermodel for the caller. - DeepSeek Harness. Configure a launcher and a model allowlist. Each task requires
model. Unknown or disabled aliases and aliases starting withmimoorxiaomiare refused. The server reads the launcher'sresult.jsonand reports the run directory for review.
Completion notifications
- Call
submit_codex,submit_gemini, orsubmit_dshwith a list of task objects. A successful submission returns job IDs and awatchcommand while jobs are queued or running. - Run that command with Claude Code's Monitor tool or background Bash. The watcher reads local job snapshots and prints a line as each job finishes. The MCP server itself sends no completion notification.
- The Monitor line includes the final status, elapsed time, and result preview. Poll with
full=Trueonly when the preview says[trunc]. Usecancel_*to stop jobs owned by the current server. Review the work and run the project checks before integrating it.
Each object includes task and can set workdir and timeout_s. The default workdir is .. Codex accepts model, effort, and sandbox (workspace-write by default). Antigravity accepts family and effort. dsh requires model.
delegate-wait cx-example gm-example dsh-example
delegate-wait --all --fail-fast --timeout 1800 --tag docs-refresh --expect 2
Give each task an optional tag in the form [a-z0-9][a-z0-9-]{0,39}. Use a fresh tag for each submission. Tasks in one submission can share a tag, and recently persisted tags are refused on reuse across submissions. Use the ID-based watcher returned by submit to follow exactly that batch. Manual tag mode discovers at least --expect matching jobs within the lookback window, which defaults to 10 minutes. Use the same state directory and lookback settings in the watcher and server.
--all holds output until all jobs finish. Add --fail-fast with --all to emit the first detected failure and exit without cancelling jobs. Text lines include a sanitized preview capped at 450 characters plus [trunc] when shortened. --json prints one object per line. Exit codes are 0 for all done, 1 for an unsuccessful terminal job, 2 if a job expires after consecutive missing scans (three for previously seen jobs, with a 30-second startup grace for undiscovered jobs), and 3 when the watcher times out first. An exited owner can be reported as lost.
poll_codex shortens successful responses to 120 words and 900 characters before truncation notices. Use full=True for the 300-word and 4000-character limits. Codex failure text is capped at 4000 characters. Pollers expose persistence errors and truncation metadata when applicable. Use full=True for Codex account counters and effort justification, DSH concurrency limits, or short-run notices across all three pollers.
Concurrency pools and failover
HTTP calls use the longest matching pool prefix. All glm-* aliases share six slots. deepseek-v4-flash*, qwen-3-8-max*, and ornith* each have six slots, and local-* has two. Use DELEGATE_CONCURRENCY_<BUCKET> to override a pool, with uppercase letters and underscores in place of punctuation. An explicit model pins the alias. With DELEGATE_FAILOVER=1 and model omitted, saturated HTTP pools can try another model before work begins. local-*, ornith*, codex*, and gpt-* are excluded from those chains.
Codex and dsh use shared global and per-project limits, with one concurrent job per checkout. Linked worktrees share the project limit. Use a separate worktree for each parallel editing task. Codex retries throttled async jobs up to three times and can temporarily reduce admission after repeated throttling. Antigravity has its own per-server queue and concurrency limits.
Codex effort and weekly quota
Both Codex tools require a nonblank why of 1 to 300 characters when the normalized effort differs from low. Supported values are low, medium, high, xhigh, and max. An empty effort leaves effort selection to the CLI and also requires why.
When weekly usage is available from local session logs, usage above 65% adds a warning. Above 70%, effort other than low is reduced to low. Requests are refused only if the optional DELEGATE_CODEX_QUOTA_REFUSE_PCT threshold is exceeded. allow_over_quota=True bypasses downgrade and refusal while retaining the usage warning.
3-tier agent lookup
The HTTP tools look for an agent definition in this order:
<workdir>/.claude/agents/<name>.md<workdir>/.claude/skills/<name>/SKILL.md<agents-dir>/<name>.md, where<agents-dir>isDELEGATE_LOCAL_AGENTS_DIR
Dual-format backend routing
For HTTP routing, the prefixes deepseek-, openai-, gpt-, qwen-, minimax-, moonshot-, kimi-, grok-, and mimo- select OpenAI chat completions. Other aliases use Anthropic messages. Bifrost in openai mode uses chat completions on both routes. By default, eligible DeepSeek requests replay reasoning content between tool turns.
Best practices
- Keep tasks scoped to a specific project directory and describe how to verify the result.
- Keep prompts, files, context, and tags for cloud backends free of PHI, PII, and secrets. This is an operational rule. Workdir and sandbox checks do not inspect content for sensitive data.
- Codex, Antigravity, and dsh reject workdirs that overlap any provider's default or overridden job state, including ancestors, descendants, and symlink targets. Codex and Antigravity also reject the filesystem root, the home directory, and protected home subdirectories.
- The HTTP file tools confine paths to the workdir by default. The HTTP shell tool requires macOS Seatbelt. It uses private temp storage without network access, and review agents have read-only access to the checkout. Disable the shell with
DELEGATE_RUN_BASH=0. Explicit provider URLs must use HTTP(S) and an allowlisted host. The default allowlist contains only loopback hosts. - Both Codex tools accept
context_fileunder the workdir. Use a relative path to a readable regular UTF-8 file up to 64 KiB, with no symlink components or hard links. Its contents go into the prompt. Codex appends its standard socket instruction unlesspreset="none"or the task already contains the wordsockets.
Further reading
Recent changes
Version 0.8.0 updates the Codex default and quota rules, adds context files and tagged completion watches, shortens results, and expands the Antigravity model families. See the changelog.
Contributing
See the contribution guide for bugs, ideas, and pull requests. Report vulnerabilities privately using the security policy.