Claude Code Delegate Local README

The full upstream README, mirrored for reference. Install config, tool schemas, adoption signals and our own overview live on the Claude Code Delegate Local listing page.

claude-code-delegate-local

English · Español

MIT

Table of contents

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.

bash
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

GatewayWhen to choose itWhat 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

dotenv
DELEGATE_GATEWAY=bifrost
DELEGATE_BIFROST_URL=https://bifrost.example.invalid
DELEGATE_BIFROST_API=litellm
  • DELEGATE_BIFROST_URL is required. Both URL variables accept HTTP(S) URLs with a host and no embedded credentials.
  • local-* and ornith* aliases use DELEGATE_BIFROST_LOCAL_URL when set, otherwise they use DELEGATE_BIFROST_URL. They use DELEGATE_BIFROST_VK_LOCAL for authentication. All other aliases use DELEGATE_BIFROST_URL and DELEGATE_BIFROST_VK_CODE. Set the relevant virtual keys if your gateway requires them. Requests send a configured key as both a Bearer token and x-api-key.
  • With a base URL, the default DELEGATE_BIFROST_API=litellm sends Anthropic messages to /litellm/v1/messages and OpenAI-format aliases to /litellm/v1/chat/completions. A base ending in /litellm gets /v1/messages appended, and a full /v1/messages endpoint is used as supplied for Anthropic messages. Set DELEGATE_BIFROST_API=openai to send all gateway-routed models to /v1/chat/completions on the selected base, with compatibility suffixes removed.
  • DELEGATE_BIFROST_LOCAL_MAX_TOKENS caps output tokens for local aliases. It defaults to 16384 and accepts integers from 1 to 1000000.

Use the Bifrost environment example for optional settings. The companion Bifrost kit provides ready-made configuration and installers for macOS and WSL2.

LiteLLM

dotenv
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.

VariableDefaultPurpose
DELEGATE_LOCAL_URLhttp://localhost:4000/v1/messagesDefault LiteLLM endpoint.
DELEGATE_LOCAL_KEYUnsetKey sent as both bearer token and x-api-key.
DELEGATE_LOCAL_MODELlocal-qwen-3-6-35bDefault HTTP model alias.
DELEGATE_LOCAL_CODING_MODELDELEGATE_LOCAL_MODELAlias for recognized coding agents when model is omitted.
DELEGATE_LOCAL_AGENTS_DIR~/.claude/agentsGlobal Markdown agent directory.
DELEGATE_GATEWAYlitellmSelect litellm or bifrost.
DELEGATE_GATEWAY_FILEUnsetOverrides the selector at startup. Use an owned regular file with mode 0600 containing {"selector":"bifrost"} or the equivalent for LiteLLM.
DELEGATE_BIFROST_URLUnsetHTTP(S) base URL for Bifrost, without embedded credentials.
DELEGATE_BIFROST_LOCAL_URLDELEGATE_BIFROST_URLOptional base URL for local-* and ornith*.
DELEGATE_BIFROST_APIlitellmUse /litellm routes or set openai for /v1/chat/completions on both lanes.
DELEGATE_BIFROST_VK_LOCAL, DELEGATE_BIFROST_VK_CODEUnsetVirtual keys for the local and other model routes, respectively.
DELEGATE_BIFROST_LOCAL_MAX_TOKENS16384Output token cap on the local Bifrost route.
DELEGATE_PROVIDER_ALLOWED_HOSTSUnsetComma-separated host allowlist for explicit provider calls.
DELEGATE_TOOL_PROFILEfullTool 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_TURNS25 / 60 / 150Automatic local and cloud turn budgets, then the hard ceiling.
DELEGATE_MAX_BATCH_SIZE12Maximum tasks per HTTP batch.
DELEGATE_TURN_TIMEOUT, DELEGATE_DISPATCH_TIMEOUT1800 / 3600Per-call and dispatch time budgets in seconds.
DELEGATE_BATCH_TASK_TIMEOUT4500 with defaultsBatch task deadline in seconds. Defaults to dispatch timeout plus queue grace. Set to 0 to disable.
DELEGATE_BATCH_QUEUE_GRACE, DELEGATE_BATCH_HEARTBEAT_S900 / 20Batch queue allowance and progress heartbeat, in seconds.
DELEGATE_CONCURRENCY_DEFAULT4HTTP pool size when no model bucket matches.
DELEGATE_CROSS_PROCESS_SLOTS, DELEGATE_SLOT_DIR, DELEGATE_SLOT_POLL1 / ~/.cache/claude-delegate-local/slots / 0.5Shared HTTP slots, lock directory, and retry interval in seconds.
DELEGATE_FAILOVER, DELEGATE_FAILOVER_GRACE0 / 10Opt into HTTP failover for omitted models and set fallback slot wait in seconds.
DELEGATE_STREAMING, DELEGATE_PROMPT_CACHING1 / 1Enable HTTP streaming and cache markers for supported models.
DELEGATE_RESEND_REASONINGautoReplay reasoning for DeepSeek in auto mode. Use always or never to override.
DELEGATE_MAX_NUDGES, DELEGATE_KEEP_TOOL_RESULTS1 / 6Completion nudges and retained recent tool results.
DELEGATE_MAX_READ_FILE_BYTES, DELEGATE_MAX_WRITE_BYTES64 MiB / 8 MiBFile size limits for the HTTP agent tools.
DELEGATE_RUN_BASH1Enables shell execution for HTTP agents.
DELEGATE_RUN_BASH_TIMEOUT, DELEGATE_CLOUD_RUN_BASH_TIMEOUT, DELEGATE_RUN_BASH_MAX120 / 600 / 1800Local and cloud shell timeouts and the hard cap, in seconds.
DELEGATE_RUN_BASH_CONCURRENCY, DELEGATE_ENV_PASSTHROUGH4 / unsetMaximum concurrent shell calls and extra child environment variables, comma-separated.
DELEGATE_LOG, DELEGATE_LOG_PATH, DELEGATE_LOG_MAX_BYTES1 / ~/.cache/claude-delegate-local/dispatches.jsonl / 8 MiBDispatch logging, log path, and rotation threshold.
DELEGATE_CODEX_BIN, DELEGATE_CODEX_MODEL, DELEGATE_CODEX_EFFORTcodex / gpt-6.2-sol / lowCodex executable, model, and effort.
CODEX_HOME~/.codexCodex configuration and authentication directory.
DELEGATE_CODEX_STATE_DIR, DELEGATE_CODEX_SESSIONS_DIR~/.codex-jobs / ~/.codex/sessionsJob state and session logs used for quota readings.
DELEGATE_CODEX_MAX_CONCURRENT, DELEGATE_CODEX_MAX_PER_PROJECT, DELEGATE_CODEX_MAX_QUEUE8 / 6 / 32Global, per-project, and waiting-job limits.
DELEGATE_CODEX_STAGGER_S, DELEGATE_CODEX_LOCK_WAIT_S2.5 / 600Launch spacing and blocking tool lock wait in seconds.
DELEGATE_CODEX_QUOTA_WARN, DELEGATE_CODEX_QUOTA_DOWNGRADE_PCT, DELEGATE_CODEX_QUOTA_REFUSE_PCT65 / 70 / unsetWeekly usage thresholds for warnings, lowering effort, and refusing new requests.
DELEGATE_CODEX_ALLOW_DANGER, DELEGATE_CODEX_STDOUT_CAP0 / 512 KiBOpt in to danger-full-access and set the stdout buffer limit.
DELEGATE_AGY_BINUnsetOptional path to the Antigravity CLI.
DELEGATE_GEMINI_ALLOW_DANGER, DELEGATE_GEMINI_AGY_SANDBOX_FLAG0 / 1Required opt-in for Antigravity and toggle for its own --sandbox flag. The outer jail remains active.
DELEGATE_GEMINI_STATE_DIR~/.gemini-jobsAntigravity job state.
DELEGATE_GEMINI_MAX_CONCURRENT, DELEGATE_GEMINI_MAX_QUEUE4 / 32Antigravity concurrency and queue limits per server.
DELEGATE_DSH_LAUNCHERUnsetPath to the launcher. Required to use the dsh tools.
DELEGATE_DSH_MODELS_FILEBuilt-in pathSet this to your model allowlist. See the example.
DELEGATE_DSH_STATE_DIR~/.dsh-jobsDeepSeek Harness job state.
DELEGATE_DSH_MAX_CONCURRENT, DELEGATE_DSH_MAX_PER_PROJECT, DELEGATE_DSH_MAX_QUEUE2 / 2 / 16Global, per-project, and waiting-job limits.
DELEGATE_DSH_STAGGER_S, DELEGATE_DSH_KILL_GRACE_S5 / 60Launch spacing and cancellation grace in seconds.
DELEGATE_WAIT_INTERVAL, DELEGATE_WAIT_TAG_LOOKBACK_S5 / 600Watcher poll interval and tag lookback in seconds. The lookback also applies when checking tag reuse.
DELEGATE_TEST_ISOLATION, DELEGATE_TEST_ISOLATION_ROOTUnsetTest-only storage guard. Presence of the first variable requires an absolute storage root in the second.

Tools exposed

ToolPurpose
delegate_to_local_agentRun a Markdown agent on the configured backend and wait for the result.
delegate_batchRun Markdown agent tasks in parallel and return results in input order.
delegate_to_providerRun a Markdown agent with an explicit provider URL, key, and model.
list_local_agentsList global agent definitions and their metadata.
local_backend_statusCheck the configured backend and list its available models.
delegate_to_codexRun one Codex CLI task and wait for the result.
submit_codexSubmit Codex tasks and return job IDs and a watcher command.
poll_codexFetch Codex job status and output by ID.
cancel_codexCancel a queued or running Codex job owned by this server.
delegate_to_geminiRun one Antigravity CLI task and wait for the result.
submit_geminiSubmit Antigravity tasks and return job IDs and a watcher command.
poll_geminiFetch Antigravity job status and output by ID.
cancel_geminiCancel a queued or running Antigravity job owned by this server.
submit_dshSubmit DeepSeek Harness tasks and return job IDs and a watcher command.
poll_dshFetch DeepSeek Harness job status and output by ID.
cancel_dshCancel 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 is gpt-6.2-sol at low. The server accepts gpt-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, and gpt-5.4-mini. Use sol or 6.2-sol for gpt-6.2-sol, astra or 6.2-astra for gpt-6.2-astra, terra for gpt-6.1-terra, and luna for gpt-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 agy before using it. Requires macOS sandbox-exec and DELEGATE_GEMINI_ALLOW_DANGER=1. The family values are gemini (default, gemini-3.8-flash-*), sonnet (claude-sonnet-5-5-*), and argon, hydrogen, neon, or carbon (gemini-4-<family>-*). Each supports low, medium (default), and high. A detected quota failure can return quota_exhausted and a suggested failover model for the caller.
  • DeepSeek Harness. Configure a launcher and a model allowlist. Each task requires model. Unknown or disabled aliases and aliases starting with mimo or xiaomi are refused. The server reads the launcher's result.json and reports the run directory for review.

Completion notifications

  1. Call submit_codex, submit_gemini, or submit_dsh with a list of task objects. A successful submission returns job IDs and a watch command while jobs are queued or running.
  2. 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.
  3. The Monitor line includes the final status, elapsed time, and result preview. Poll with full=True only when the preview says [trunc]. Use cancel_* 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.

bash
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:

  1. <workdir>/.claude/agents/<name>.md
  2. <workdir>/.claude/skills/<name>/SKILL.md
  3. <agents-dir>/<name>.md, where <agents-dir> is DELEGATE_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_file under 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 unless preset="none" or the task already contains the word sockets.

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.

License

MIT