Metadata-Version: 2.5
Name: local-delegate-mcp
Version: 0.57.1
Summary: Delegate mechanical text tasks to a local OpenAI-compatible LLM endpoint to conserve Claude subscription quota.
Project-URL: Homepage, https://github.com/ZahiriNatZuke/local-delegate
Project-URL: Repository, https://github.com/ZahiriNatZuke/local-delegate
Project-URL: Issues, https://github.com/ZahiriNatZuke/local-delegate/issues
Author: Yohan González Almaguer
License-Expression: MIT
License-File: LICENSE
Keywords: claude,llama-swap,llm,local,mcp,ollama,openai-compatible,quota
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Requires-Dist: anyio<5,>=4.14.2
Requires-Dist: fastapi>=0.115
Requires-Dist: filelock<5,>=4
Requires-Dist: httpx2<3,>=2.5
Requires-Dist: mcp<3,>=2
Requires-Dist: opentelemetry-api<2,>=1.45.1
Requires-Dist: platformdirs<5,>=4
Requires-Dist: uvicorn>=0.30
Provides-Extra: llamaswap
Requires-Dist: pyyaml>=6; extra == 'llamaswap'
Description-Content-Type: text/markdown

<!-- mcp-name: io.github.ZahiriNatZuke/local-delegate -->

**English** · [Español](README.es.md)

# local-delegate

**Delegate the mechanical steps of your coding agent to models on your own GPU, and keep your subscription quota for the hard parts.**
An MCP server (`stdio` or a shared HTTP daemon) that is a **generic** client for any
OpenAI-compatible endpoint — llama-swap, Ollama, LM Studio, vLLM.

[![PyPI](https://img.shields.io/pypi/v/local-delegate-mcp.svg)](https://pypi.org/project/local-delegate-mcp/)
[![CI](https://github.com/ZahiriNatZuke/local-delegate/actions/workflows/ci.yml/badge.svg)](https://github.com/ZahiriNatZuke/local-delegate/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
[![local-delegate MCP server](https://glama.ai/mcp/servers/ZahiriNatZuke/local-delegate/badges/score.svg)](https://glama.ai/mcp/servers/ZahiriNatZuke/local-delegate)

**[zahirinatzuke.github.io/local-delegate](https://zahirinatzuke.github.io/local-delegate/)** — what
it does and why, on one page (es/en). Its source is in [`site/`](./site).

## Demo

<!-- Absolute URL to raw.githubusercontent.com so the image also renders on PyPI
     (relative links only resolve inside GitHub). -->
<picture>
  <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ZahiriNatZuke/local-delegate/main/docs/assets/dashboard-light.png">
  <img alt="local-delegate savings dashboard" src="https://raw.githubusercontent.com/ZahiriNatZuke/local-delegate/main/docs/assets/dashboard.png">
</picture>

*Embedded dashboard (sample data): local backend status (loaded models, delegation in progress with its per-chunk progress, MCP tools), system RAM/VRAM with per-process usage, context tokens preserved, savings by tool and model, where the compute ran —this machine or a remote backend— and paginated recent activity in your local time. Served at `http://127.0.0.1:9393`.*

## Figures and method

Every figure says where it comes from; none is a savings promise for your case.

| Figure | Method and source |
|---|---|
| **27 of 30** commit messages preferred blind with Inkling 2 Mini, against 2 with Gemma 4 26B (1 tie) | 33 cases per model (30 real and 3 traps); blind sheet judged by an agent with no access to the key or the results; the control trap did not win. [`benchmarks/commits-2026-11/verdict.md`](./benchmarks/commits-2026-11/verdict.md), 2026-11-30. |
| **10 of 11** correct code explanations with Inkling 2 Mini, against 3 of 11 with Qwen3.6 35B | Measured on 2026-11-29 with llama.cpp b12845; it is about 4 times slower when explaining (~38 s against ~9 s). The entry for the `code` role change in the [CHANGELOG](./CHANGELOG.md). |
| **Context preserved**, the one your dashboard shows | Characters read by the server (`source=path`, successful calls) minus what was returned, converted to Claude tokens with a density table per tokenizer and content type. Full method in “The savings metric”, below. |

We do not publish an “X % less quota” figure yet: the control measurement with a clean install
is pending and, until it runs, there is no honest number to give. The demo dashboard figures
are sample data, not a measurement.

## Why?

When Claude has to summarize a huge log, classify, extract fields or generate boilerplate,
it spends your subscription quota on **mechanical** work. `local-delegate` exposes those tasks as
MCP tools that run on a **local** LLM: you pass `path` instead of `text` and the file is read
**on the server side**, so the large content **never enters Claude's context**. Only the short
result comes back: the document neither fills your context window nor is processed by Claude.

## Quick install

With [`uv`](https://docs.astral.sh/uv/) there is nothing to install: `uvx` downloads and runs the package in isolation.

Add it to your MCP config (Claude Desktop / Claude Code) in the compatible `stdio` mode:

```json
{
  "mcpServers": {
    "local-delegate": {
      "command": "uvx",
      "args": ["local-delegate-mcp"]
    }
  }
}
```

See complete templates in [`examples/`](./examples).

Or let the package configure everything for you —MCP entry, hooks, skill and the delegation rule in
your global `CLAUDE.md`/`AGENTS.md`— with a single command:

```bash
uv tool install local-delegate-mcp          # leaves `local-delegate` on the PATH
local-delegate install --dry-run            # shows exactly what it would touch
local-delegate install                      # applies
```

`uvx local-delegate-mcp install` also works to try it without installing anything, but note that
**`uvx` does not leave the command available**: it builds an ephemeral environment and deletes it
when it finishes, so `local-delegate doctor` will answer “command not found” afterwards. `install`
itself warns you if it detects that case.

It is idempotent, leaves a `.bak` of what it edits (the first time it touches it; it does not
overwrite it afterwards), does not touch other people's configuration and is reverted with
`local-delegate uninstall`. Since 0.44.0 it writes atomically, reapplies its change if Claude Code
saves the file at the same time, and if a file is not UTF-8 (cp1252, UTF-16) the action fails
without touching it. Details and options in [Integration install](./docs/wiki/Integration-install.en.md).

Want Tab completion of subcommands, options and values? `local-delegate install
--shell-completion` loads it into your PowerShell, zsh or bash profile (opt-in, reversible with
`uninstall --shell-completion`), and `local-delegate completion powershell|zsh|bash` prints the script
in case you prefer to load it yourself. See [Shell autocompletion](./docs/wiki/Integration-install.en.md#shell-autocompletion).

If you use **several sessions or several clients** on the same machine, a single daemon is recommended:

```powershell
uvx local-delegate-mcp serve
```

The daemon serves MCP at `http://127.0.0.1:9393/mcp` and the dashboard at
`http://127.0.0.1:9393/`. Codex, Claude Code, opencode and any Streamable HTTP-compatible client
can share that URL without starting duplicate MCP processes. With a local llama-swap, the
`[llamaswap]` extra and `LLAMASWAP_CONFIG` pointing at its `config.yaml`, the daemon also **hands
out the backend by turns**: two delegations whose models would evict each other do not step on each
other, and the second waits (the dashboard shows it as a local wait). Full guide: [Shared daemon](./docs/wiki/Daemon.en.md).

A delegation can add turn waiting and inference, and some clients cut earlier: **Codex cuts any
MCP tool call at 60 s** (`tool_timeout_sec` in `[mcp_servers.local-delegate]` of `config.toml`
raises it, and it has to be restored after each `install`/`update`, which rewrite that block) and
Claude Code cuts an HTTP call **after 5 min without a response** (the
`CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT` variable, in ms, raises it and survives `install`). Details in
[Integration install](./docs/wiki/Integration-install.en.md#mcp-client-timeouts).

To use another machine's GPU while keeping the client's local paths, use a local MCP that points at
the remote backend: [Mac → PC guide](./docs/wiki/Remote-backend.en.md) and the
[full technical recipe](./docs/recipes/remote-backend.md). The operations of both machines form a
single queue: the one that does not have the backend asks the other's daemon for a turn, with the
same backend key and only toward a private host (the tailnet), and if that daemon is not available it
goes on without a turn, as before ([common PC+Mac turn](./docs/wiki/Remote-backend.en.md#common-pcmac-turn)).

> **Do not pin an old version “for stability”.** A pin (`==X.Y.Z`) also freezes the dependency
> ranges that wheel declared, and that ages badly: versions before 0.12.2 asked for `mcp` **with no
> ceiling**, so today they resolve to SDK 2.x and **die on import**. If you need to pin, pin the
> **current** one, and bump it when a new one comes out.

On Windows, if you register it as a task at logon, run the `pythonw.exe` of the environment where
you installed the package with `-m local_delegate serve --log-level warning`. `pythonw` creates no
console and no taskbar button. The task belongs to the **Windows** user, not to Codex or Claude: any
local client shares the same daemon. The dashboard identifies that single process with the
`MCP DAEMON` badge; connected sessions are HTTP clients, not additional MCP processes.

**When updating on Windows, stop the daemon before `uv tool install --force`.** With the daemon
running, the reinstall can fail halfway (it has files of the environment open) and leave it broken;
`schtasks /End` is not enough because the launcher is detached, so stop the daemon's `pythonw`
process, install and launch it again. Afterwards, `local-delegate update` restores hooks, skill and
the `CLAUDE.md`/`AGENTS.md` block if they were left out of date.

If you installed with a pinned version (`uv tool install "local-delegate-mcp==X.Y.Z"`), `uv tool
upgrade` says “Nothing to upgrade” and upgrades nothing: reinstall with
`uv tool install "local-delegate-mcp[llamaswap]@latest"` (with your extras). Since 0.45.1,
`local-delegate update` and `doctor` detect it and give that command.

> **0.36.0 speaks Spanish or English and follows the system language.** With the system in
> English you will start seeing English: to stay in Spanish, `LOCAL_DELEGATE_LANG=es local-delegate
> install` (or `update`). The `_local_delegate` keys and the tools' markers become
> English (breaking change); the table is in the [CHANGELOG](./CHANGELOG.md) and in
> [Language](./docs/wiki/Language.en.md).

> **0.35.0 renames commands, variables, the skill and data files to English.** The old names worked
> with a warning since 0.35.0 and **were removed in 0.38.0**: they no longer have any effect.
> `local-delegate doctor` names those still set (up to 0.40.x) and `local-delegate update` migrates
> the ones it can. Going back to an earlier version is not supported. The full table is in the
> [CHANGELOG](./CHANGELOG.md).

## Requirements

**Python 3.11+** — with `uvx` you do not have to install it yourself, it resolves it; it only
matters if you install with `pip` in an environment of your own.

And an **OpenAI-compatible endpoint** already running, reachable at `LOCAL_DELEGATE_BASE_URL`
(default `http://127.0.0.1:9292/v1`). Any of these works:

- **llama-swap** — see the [recipe with a Blackwell GPU](./docs/recipes/llama-swap-blackwell.md).
- **Ollama** — `http://127.0.0.1:11434/v1`.
- **LM Studio**, **vLLM**, or any server that speaks the OpenAI API.

The package **does not start** any backend by default (`LOCAL_DELEGATE_AUTOSTART=0`). Auto-starting
llama-swap is opt-in (see the configuration table).

Which versions of `llama-server`/`llama-swap` to use and how to lay out the workspace? See
[Backend versions and reference workspace](./docs/wiki/Backend-versions.en.md) (a tested suggestion,
not a requirement). `local-delegate doctor` compares your installation against those versions and,
along the way, checks the rest of the scaffolding —hooks, skill, memory, MCP entries, the daemon,
that each role's model is in the backend's list and, in Codex, the hooks and the plugin— without
writing anything ([what each check looks at](./docs/wiki/Integration-install.en.md#check-the-installation-local-delegate-doctor)).

## Tools

Passing `path` (instead of `text`) makes the MCP read the file server-side: the content does not
enter Claude's context, and that is where the savings come from. A file that is not UTF-8 (UTF-16
with BOM, Windows-1252) is read without losing characters and the response says so.

| Tool | What it does | Model role (default) |
|---|---|---|
| `local_summarize` | Summarizes text or a file; optional `focus` to say what to keep (e.g. “configuration figures”); warns if the summary carries acronyms, words or figures that the input does not have | mechanical / long (auto; a small input with a table goes to long) |
| `local_classify` | Returns ONE label from a list | mechanical |
| `local_extract` | Extracts fields → a **validated object** with exactly the requested keys (missing ones, or ones that come back as “N/A”, are `null`), not a string you have to parse; each field with its type (a list never comes back as a boolean; what does not fit gets one retry and, if it stays the same, goes into `type_mismatch_keys`); with `path`, a field that asks for lines comes back as a list of `{name, start, end}` **computed by the program**, never by the model (index of Python, TS/JS, Markdown, diff and ids; or a literal chunk that the program looks up exactly), with `located` and `unlocated`; a small input with a table (HTML, ARIA, Markdown/GFM, CSV or TSV) goes to the long model and `_local_delegate.role_reason` says so with its `format`; if a key's value comes from the row of another requested key, it warns in `cross_filled_keys`, and if it flips a negation of the input, in `polarity_flipped_keys` | mechanical / long (auto; also with a table; code or long input with a line field that needs a model) |
| `local_boilerplate` | Generates code from a spec and **writes it to `target`**; returns only a receipt | code |
| `local_delegate` | Generic text→text escape hatch | mechanical (or the one you pass) |
| `local_lint_summary` | Summarizes lint/test/CI logs; with pytest it starts from the real failures in the log and warns if the summary does not match them | mechanical / long (auto) |
| `local_commit_msg` | Commit message from a diff; with `path` it takes the repo's language and warns if it could not; with an enormous diff it finishes in time with what was read and says so; chunked, it warns and lists the changed conditions so you can review it | code |
| `local_translate` | Translates text or a file | mechanical / long (auto) |
| `local_explain_code` | Explains code in prose; with `path` and a question it warns about doubtful cited lines and about a premise the code does not support, even if the answer places it next to real code | code |
| `local_describe_image` | Describes an image or answers a question about it (image→text); it does not measure alignment, sizes or line breaks, and warns when the question or the answer talk about that | vision |
| `local_status` | Read-only diagnostics: backend, catalog, log, VRAM, system RAM | — (does not call the chat backend) |

Local models **do not** use tool-calling: the server assembles the prompt + guardrails, POSTs to the
endpoint and returns **only text**.

**Long documents.** `local_translate` (and `local_delegate` with long inputs) splits the text at
natural boundaries —Markdown headers, paragraphs, lines— and processes **one chunk per call**
respecting the `max_tokens` ceiling, concatenating the outputs in order and keeping the format at the
seams. A document of 20 000+ characters comes back complete instead of cut off halfway. The log
records `chunks: N` and the dashboard shows the progress (`chunk 3/7`) while it runs. Since 0.43.0,
“In progress” also says the phase: “Combining 3 chunks…” while the partials are being joined and
“Retrying chunk n/total” when a truncated chunk is split again; and activity separates chunks from
backend calls (`3 +1`: three chunks and one combination). Since 0.47.2 that case says “Splitting
chunk n/total” and, as soon as the parts are known, how far the split has got without moving the
total number of chunks: “Chunk 3/4 · split into 3 · part 2” in the dashboard and `3/4 · split into
3 · part 2` in the band.

**Long calls and queues.** Since 0.45.0 each live call sends MCP progress every 20 s with its phase
(“waiting for turn, position N”, “processing chunk k/N”), so Claude Code no longer cuts at 300 s a
delegation that is waiting in the queue. The daemon gives each call its own deadline
(`LOCAL_DELEGATE_CALL_MAX_S`, 1800 s) and, if the queue has gone 900 s without progress, fails at
once with “queue saturated” instead of leaving the client hanging. Aborted delegations stay in the
log as errors, “In progress” separates “Processing (n)” from “In queue (m)”, and each log entry says
which machine it came from (`host`) and how long it waited in each phase (`concurrency`). Since
0.46.0 a long chunked delegation hands the turn over between chunks to the one that collides with it
(`LOCAL_DELEGATE_TURN_YIELD_S`, 120 s), “In progress” groups under “Waiting for backend” the call
that is waiting for llama-swap to switch models, and a `read_timeout` names the model that was
blocking it. Since 0.47.0 that wait is shown as such even while the chunk is being split (it used to
show as “retrying”; since 0.47.2, “splitting”).

**Bursts that mix models.** The turn serves in arrival order, so a burst that alternates tools of
models that do not fit together (summarize and explain code, for example) forces a model switch at
each handover, and the last one can wait **minutes** without the model being slow. Claude Code sends
to the background a call that has taken 2 min and the result arrives all the same. If the turn wait
passes `LOCAL_DELEGATE_TURN_WAIT_NOTICE_S` (60 s), the response carries a notice saying how long it
waited. Grouping the calls by tool (all the summaries first, then all the code) reduces it.

**Summaries of huge documents.** `local_summarize` and `local_lint_summary` do **map-reduce** when
the input does not fit in the model: they summarize each part and then summarize the summaries,
level by level if needed. They used to truncate —with a huge CI log, the beginning was summarized
and the rest silently discarded, which is exactly where the errors usually are— and now the whole
thing is read. If a chunk is cut off by `max_tokens`, the result says so and the log records
`finish_reason: length`. Since 0.43.0, a cut-off partial is no longer accepted as good: it is
discarded, the chunk (or the regrouped batch) is split and retried, up to two levels; if any is
still cut off, the notice says which chunk and which lines. Since 0.47.0, the regrouped batch does
not repeat rounds without progress: if a round does not reduce the material by at least 20 % and the
notes still do not fit in the final step, it stops and returns the grouped notes with a notice,
marked as truncated (`finish_reason: length`, `truncated_out`). And a unified diff is summarized in
prose, never “by sections”.
Since 0.36.1, with a log that does not fit in one call, `local_lint_summary` only feeds in the ten
most named files (and says how many more there are), and the figures of the final summary are put in
by the program, not the model.
Since 0.36.0, `local_commit_msg`, `local_explain_code` (by top-level `def`/`class`, with the name
inventory in the final step) and `local_extract` (a partial object per chunk and a final step with a
schema that combines them) also read the whole input. Since 0.44.2, if after chunking a
`local_extract` field is `null` in every chunk, `_local_delegate.chunked` says so (`pieces`,
`null_fields`, `notice`): that `null` means “not seen”, not “does not exist”.
Since 0.47.0, `local_explain_code` with `question` carries the question to each chunk and, with
`path`, at the end checks the lines it cites against the file (warns about the doubtful ones) and
adds the exact occurrences of each identifier in the question.

## Configuration

Everything through environment variables; nothing hardcoded. The default model ids are just that —
swap them for those of your backend.

| Variable | Default | Description |
|---|---|---|
| `LOCAL_DELEGATE_BASE_URL` | `http://127.0.0.1:9292/v1` | OpenAI-compatible endpoint |
| `LOCAL_DELEGATE_API_KEY` | *(empty)* | Bearer token, if your endpoint requires one |
| `LOCAL_DELEGATE_BACKEND_ORIGIN` | `auto` | `local`/`remote` force the compute origin; `auto` infers it from the host. Set it if you reach the backend through a **tunnel** (`ssh -L`, port-forward): on loopback it would look local |
| `LOCAL_DELEGATE_TIMEOUT` | `180` | HTTP timeout (seconds) |
| `LOCAL_DELEGATE_MAX_CONCURRENT_REQUESTS` | `2` | Maximum backpressure per process; shared by every daemon client |
| `LOCAL_DELEGATE_ASK` | `1` | Ask the user (via `elicitation`) instead of failing silently: backend down, model outside the catalog, empty `output_format`. `0` disables it |
| `LOCAL_DELEGATE_ASK_TIMEOUT` | `30` | Seconds to wait for an answer; once exhausted, the tool proceeds as if it had not asked |
| `LOCAL_DELEGATE_LOG_DIR` | *(user data dir)* | Directory of the monthly-rotated `usage-YYYYMM.jsonl` and `clients.jsonl`, and of `project-salt`, `project-names.json` and `self-projects.json`. The daemon, hooks and scripts must resolve the same one: if you set it in the launcher and not in the daemon, or the other way round, the salt and the name map differ between rows and events |
| `LOCAL_DELEGATE_LOG` | *(empty = rotation active)* | If set, path of an explicit non-rotated `usage.jsonl` (compatibility) |
| `LOCAL_DELEGATE_MACHINE_NAME` | *(short machine name)* | Name of this machine in the usage log (`host`) and in the `X-Local-Delegate-Host` header sent to the backend; useful if two machines are named the same |
| `LOCAL_DELEGATE_MODEL_MECHANICAL` | `gemma3-4b` | Model for classify/extract/short summary |
| `LOCAL_DELEGATE_MODEL_LONG` | `qwen38-27b` (fallback: `gemma4-26b-a4b`) | Model for long documents |
| `LOCAL_DELEGATE_MODEL_CODE` | `inkling2-mini` | Model for code: Inkling 2 Mini, which always reasons (llama.cpp ≥ b12828, ~10 GB RAM and ~13 GB peak VRAM). It carries its own reasoning values (origin `model` in `backend-params show`). Without that entry in your catalog, the previous one: `LOCAL_DELEGATE_MODEL_CODE=qwen36-35b-a3b`; `doctor` suggests it if your backend serves it |
| `LOCAL_DELEGATE_MODEL_VISION` | `qwen36-35b-a3b-vision` | Vision model for `local_describe_image`: Qwen3.6 35B-A3B with `--mmproj` (~14 GB RAM, ~11 GB VRAM). With less VRAM or without that entry in your catalog, the light alternative: `LOCAL_DELEGATE_MODEL_VISION=gemma4-12b` |
| `LOCAL_DELEGATE_MAX_IMAGE_MB` | `8` | Image size cap for `local_describe_image` |
| `LOCAL_DELEGATE_DUMP_CHUNK_NOTES` | *(empty: off)* | Local folder where each chunked operation leaves the output of each step; for measurement only, it never leaves the machine |
| `LOCAL_DELEGATE_LONG_INPUT_CHARS` | `6000` | Mechanical↔long threshold |
| `LOCAL_DELEGATE_EXTRACT_TABLE_LONG` | `1` | `local_extract` sends to the long model an input below the threshold that contains a table (HTML, ARIA, Markdown/GFM, CSV or TSV), and says so in `role_reason` (response, with the format, and log). It takes longer and can load the model; `0` disables it |
| `LOCAL_DELEGATE_SUMMARIZE_TABLE_LONG` | `1` | The same rule for `local_summarize`: the summary ends with a notice naming the format and the log row carries `role_reason`; `0` disables it |
| `LOCAL_DELEGATE_CHUNK_CHARS` | `3500` | Chunk size when splitting long documents (`local_translate`, `local_delegate`) |
| `LOCAL_DELEGATE_CHUNK_MAX_TOKENS` | `2048` | `max_tokens` ceiling per chunk |
| `LOCAL_DELEGATE_CHUNK_MIN_CHARS` | `400` | Minimum chunk: below it, it is not split again |
| `LOCAL_DELEGATE_JSON_SCHEMA` | `auto` | `response_format` with schema in `local_extract`: `auto`/`on`/`off` |
| `LOCAL_DELEGATE_FEEDBACK` | `1` | Savings line appended to the result when `source=path` (`0` disables it). In `local_extract` it is not appended to the text —it would break the JSON—: it goes inside `_local_delegate` |
| `LOCAL_DELEGATE_ALLOWED_DIRS` | *(empty = no additional restriction)* | Allowed roots for `path` and `target`, separated by `;`. Protected paths (credentials, autostart, configuration that executes code) are always rejected, with or without this variable: see [Configuration](docs/wiki/Configuration.en.md#protected-paths-always-active) |
| `LOCAL_DELEGATE_DENY_PATHS` | *(empty)* | Extra paths, separated by `;`, that the tools neither read nor write; they are added to the protected list |
| `LOCAL_DELEGATE_WEB` | `1` | Web embedded in `stdio` mode (`0` to disable it). Since 0.42.0 it asks for the `LOCAL_DELEGATE_WEB_TOKEN` token if set, like the daemon |
| `LOCAL_DELEGATE_WEB_HOST` / `_PORT` | `127.0.0.1` / `9393` | Host/port of the web or the daemon. Empty counts as unset |
| `LOCAL_DELEGATE_WEB_ALLOWED_HOSTS` | *(empty)* | Extra names the port accepts in the `Host` header, comma-separated (e.g. the one from `tailscale serve`). By default only loopback and `WEB_HOST`, against DNS rebinding (since 0.42.0: without it, coming in through another name gives 421); `*` disables the check |
| `LOCAL_DELEGATE_WEB_FONTS` | `1` | Brand typography from Google Fonts (`0` = zero requests to third parties) |
| `LOCAL_DELEGATE_AUTOSTART` | `0` | Auto-start of llama-swap (opt-in) |
| `LLAMASWAP_EXE` / `LLAMASWAP_CONFIG` / `LLAMASWAP_LISTEN` | — | Only if `AUTOSTART=1`; `LLAMASWAP_CONFIG` also enables the daemon's turn and affinity (with the `[llamaswap]` extra). `LLAMASWAP_EXE` must be an absolute path to an existing file (otherwise it warns and does not start); without it, `llama-swap` is searched only in the absolute folders of `PATH`, never in the current folder (since 0.44.0) |
| `LLAMASWAP_WATCH_CONFIG` | `0` | `1` adds `-watch-config` to the auto-started backend |
| `LOCAL_DELEGATE_FALLBACK` | `1` | Fallback between models: if a role's model fails on its own, the next one in its chain answers (`_MAX_HOPS`=2; chains with `_<ROLE>`, see the wiki). `0` disables it |
| `LOCAL_DELEGATE_COOLDOWN` | `1` | Per-model cooldown: 3 consecutive failures (`_FAILURES`) stop it for 120 s (`_S`), doubling up to 900 s (`_MAX_S`). `0` disables it |
| `LOCAL_DELEGATE_BACKEND_BREAKER` | `1` | Cut-off for an unreachable backend: 3 consecutive connection failures (`_FAILURES`) make the `local_*` tools answer at once “backend unreachable, do it yourself” for 60 s (`_S`), doubling up to 600 s (`_MAX_S`), without counting as a delegation; when it expires, the next call probes it. `0` disables it |
| `LOCAL_DELEGATE_REMOTE_TURN_CUT` | `1` | Remote turn cut (#577): with the other machine's turn unanswered, operations go without a turn and one at a time per process (Claude Code and the Desktop daemon each carry their own row); if one exhausts its read deadline on the backend (`_FAILURES`, 1; a 5xx at the moment does not count), for 120 s (`_S`, doubling up to 600 s, `_MAX_S`) those that would go without a turn fail at once with “the remote turn does not respond; retrying now does not help”. `0` turns it off (the series stays) |
| `LOCAL_DELEGATE_COST_FALLBACK` | *(empty = `claude-opus-5-5` in subagent)* | With which model and thread a delegation without an attributed model is valued: `model` or `model:main\|subagent`. An invalid value breaks nothing: the dashboard uses the declared one and says so |
| `LOCAL_DELEGATE_COMMIT_LANGUAGE` | *(empty = current language)* | Language of the `local_commit_msg` message: `es`, `en`, `fr`, `pt`, `de`, `it` or a free name. Empty: the product's current language; `diff`: the predominant language of the diff's texts |
| `LOCAL_DELEGATE_OUTPUT_LANGUAGE` | *(empty = current language)* | Language in which the free-text tools (`local_summarize`, `local_lint_summary`, `local_explain_code`, `local_describe_image`) ask the model to answer: `fr`, `pt`, `português`… It does not change the interface nor `local_commit_msg` |
| `LOCAL_DELEGATE_TURN_MAX_S` | `600` | Daemon turn between models that collide in llama-swap: if the first in the queue has waited this many seconds **and** the daemon has gone another such time with no backend call starting or finishing, it is granted the turn anyway (`turn: "forced"` in the log) |
| `LOCAL_DELEGATE_TURN_YIELD_S` | `120` | Turn handover between chunks: if the first in the queue has waited this many seconds for a model colliding with that of an operation that has held the turn for another such time, that operation releases it before its next chunk and goes to the back of the queue (`turn_yields` in the log). Cost: at most one pair of model loads every such time when two long operations collide. `0` disables it |
| `LOCAL_DELEGATE_CALL_MAX_S` | `1800` | The daemon's own deadline for a call, queue included: on passing it, it is cancelled and logged as a failure (`cancel_reason: "deadline"`). `0` disables it |
| `LOCAL_DELEGATE_PROGRESS_INTERVAL_S` | `20` | Every how many seconds a live call sends `notifications/progress` with its phase (queued, slot, chunk k/N), so the client does not cut it for inactivity (Claude Code: 300 s). `0` disables it |
| `LOCAL_DELEGATE_TURN_WAIT_NOTICE_S` | `60` | If a call waited for the turn at least this many seconds, its response carries a notice (`[local-delegate warning: …]`; in `local_extract`, `_local_delegate.turn_wait`) saying how long it waited, that it was other delegations' queue and not model slowness, and that grouping calls by tool reduces it. Not in `local_classify` (exact label) nor in an error response. `0` disables it |
| `LOCAL_DELEGATE_QUEUE_MAX_WAIT_S` | `900` | Maximum seconds a call waiting for the turn or a slot endures **without the queue advancing** (a slow queue that does advance cuts no one): on passing it, the call fails at once with “queue saturated” (`error: "queue_saturated"`). `0` disables it |
| `LOCAL_DELEGATE_SLOW_THRESHOLD` | `0.5` | A call is “slow” (`slow` in the log, “slow ×0.37” in the dashboard) if it generates at less than this fraction of its model's normal speed |
| `LOCAL_DELEGATE_AFFINITY_MARGIN_S` | `5` | Affinity: an already loaded model is used only if at least this many seconds of TTL remain |
| `LOCAL_DELEGATE_BACKEND_PARAMS` | *(empty)* | Point override, key by key, of the per-role parameters in `backend-params.json` (sampling and reasoning): `role.key=value;…`, e.g. `code.top_k=20`. Needs a daemon restart; the file does not |

The **per-role parameters** that travel in each request to the backend (`top_k`, `temperature`,
`enable_thinking` with its budget…) are stored in `backend-params.json` and edited with
`local-delegate backend-params show|set|unset|reset`; the closed list of keys, the precedence, and
the reasoning are in the [wiki](docs/wiki/Configuration.en.md#backend-parameters-by-role).

## The savings metric

The MCP logs each call in a monthly-rotated log and serves a **dashboard** at
`http://127.0.0.1:9393`, with a range selector and visibility of delegations in progress.
The *context preserved* = the input read server-side (calls with `source=path` that succeeded) minus
what the tool returned to you, counted **once per delegation** even if the MCP chunks it.
It is measured in characters and converted to **Claude tokens** with a density table measured per
tokenizer family and content type (prose, code, log, structured data, diff): a `.md` does not count
the same as a `.json`, and Haiku 4.5 does not count like Opus 5.5. Images are left out of that
figure —without their dimensions there is no way to know how many tokens they would cost Claude— and
are shown separately. Against it, the *local cost* = the tokens your GPU actually consumed, **summing
all** calls: a chunked delegation repeats the system prompt in each chunk, and that difference is
what chunking cost. There the real token count reported by the backend is used; `chars ÷ 4` is only
the fallback for the **local** model when it does not report one. Details in the
[wiki](./docs/wiki/Savings-and-metrics.en.md).

The dashboard also shows an **estimated API-price equivalent**: what that same context read by
Claude would cost at list price, between a low bound and an estimate that counts the requests in
which that content would have been re-read from the cache. **It is not money you saved**: your
subscription is flat-rate. It is an estimate with its assumptions in view (with which model each
delegation is attributed, how many requests followed, which density was used) and it does not
deduct re-reads of the same file. Next to it, a **quota** block that reads “uncalibrated” until
there are at least three measurements from statusline windows of different kinds, and never shows a
percentage without that calibration. To attribute the history and feed those two blocks, run
`local-delegate recompute-cost` from time to time (it reads your transcripts locally and writes only
aggregates; since 0.50.0, if it cannot read one of its files it stops without rewriting it);
`doctor` warns if there are delegations about to run out of transcript.

**Tests do not count**: delegations from the `mcp` client of scripts, those from benchmarks and
those falling in a **test window** are set aside from the dashboard and from `local_status`. Before
testing live against the MCP or the daemon, mark the interval and keep the id it prints:

```bash
local-delegate test-window start --label "Monday test"   # prints the id
local-delegate test-window stop <id>
local-delegate test-window list                          # windows and rows in each
```

The dashboard bar's **Tests** button shows them again; its ⓘ says how many were left out.

**By project**: each log row stores from which Claude Code project the delegation was requested
(`caller_project`, a hash with the local salt `LOG_DIR/project-salt`, never the name or the path),
and each hook-telemetry event, `project`. The dashboard shows the **By project** card (delegations
and savings of each repo, largest first) and, in the filter bar, a **project** selector that
filters the whole dashboard; by default it shows everything. The readable name comes from a separate
local map, `LOG_DIR/project-names.json` (hash → the last folder of the project's real path, such as
`webshop`, with the parent folder if two coincide and the full path on hover), which is written
when the hash is computed and never leaves the machine; rows from before the map existed name
themselves the first time you open the dashboard, from the folders of `~/.claude/projects`. A hash
without a name shows as “Unnamed project” and rows without a project, as “No project”. The “Who
delegated” card separates main thread, subagents and mod. Whoever has the log **and** `project-salt`
can confirm a project name by brute force: do not share that file (nor `project-names.json`) together
with a log. Details in
[Savings & metrics](docs/wiki/Savings-and-metrics.en.md#by-project) and in
[Configuration](docs/wiki/Configuration.en.md#project-per-row-project-salt-project-namesjson-and-self-projectsjson).

The dashboard comes out in Spanish or English depending on your browser's language, and the `ES`/`EN`
selector in its header changes it (remembered in that browser). See
[Savings & metrics](docs/wiki/Savings-and-metrics.en.md#language).

The ranges, the chart days and the table hours use **your time zone** (the log is written in UTC,
which is an unambiguous instant; the conversion is presentation). The dashboard also separates
**where the compute ran**: `local` if the backend listens on loopback, `remote` if the inference
went to another machine —for example this Mac using the PC's GPU—. Events from before v0.11.0 do
not carry the field and show as `n/a`.

## Scope / non-goals

`local-delegate` is deliberately **text/image→text**: it assembles the prompt (or the multimodal
payload), POSTs to `/chat/completions` and returns only text. Things it does **not** do on purpose:

- **Local tool-calling.** Local models do not invoke tools or execute code; Claude still does that.
  Adding it would turn this package into a parallel orchestrator, which is not the goal.
- **Image generation or editing.** `local_describe_image` is only image→text (describe, read visible
  text, answer a specific question); nothing about generating or editing images.
- **Audio.** For transcription, use the companion
  [`whisper-transcribe-mcp`](https://github.com/ZahiriNatZuke/whisper-transcribe-mcp)
  instead of trying to fit audio in here.
- **Replacing the subscription.** The goal is to preserve quota by delegating bounded mechanical
  steps, not to route all the work to local models.

## Client integration: hooks, skill and memory

`local-delegate install` leaves the complete integration ready in your HOME:

| Component | Where | What it does |
|---|---|---|
| MCP entry | Claude Code config / `~/.codex/config.toml` / `~/.config/opencode/opencode.json[c]` | registers the server (stdio with `uvx` or HTTP against the daemon) |
| Hooks | Claude Code plugin `local-delegate@local-delegate` (or `~/.claude/hooks/local-delegate/` + `settings.json`) | suggest delegating; the read ones can also **reject** a full read of documentation, if turned on; one records which agent requested each delegation |
| Codex hooks | `~/.codex/hooks.json`, next to yours | two advisory hooks (`UserPromptSubmit` and `SubagentStart`), one that summarizes large prose reads through the shell and stops writing over what was only read summarized (`PreToolUse` on Bash, `apply_patch` and MCP reads) and one that records the session of each delegation (`PreToolUse` on the `local-delegate` tools), which Codex runs only when you approve them in `/hooks` |
| Skill | `~/.claude/skills/local-delegation/` and `~/.config/opencode/skill/local-delegation/` | golden rule and tool catalog |
| Memory | managed block in `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md` and `~/.config/opencode/AGENTS.md` | the rule in a short, always-loaded note |

By default **only the clients you have installed** are configured; you choose by hand with
`--clients claude|codex|opencode`. The **hooks** are Claude Code's and, since 0.53.0, Codex's too:
four in `~/.codex/hooks.json` (two advisory, one that summarizes large prose reads through the shell
and stops writing over what was only read summarized, and one that records which session each
delegation comes from), which neither touch nor move yours and which do not run until you approve
them in `/hooks`. See
[Codex hooks](docs/wiki/Integration-install.en.md#codex-hooks). opencode extends with
TypeScript plugins, which is another surface, and Claude Desktop has no hooks at all. The Claude
Code plugin **does not work in Codex**: Codex 0.169 rejects its whole `hooks/hooks.json` (because of
the mod's `modules`) with only a warning at startup. If you imported it by hand, `local-delegate
doctor` says so and gives `codex plugin remove local-delegate@<marketplace>`, which leaves the MCP
entry intact. Each piece can be excluded (`--no-hooks`, `--no-skill`, `--no-memory`, `--no-mcp`).

Everything comes out in **Spanish or English**. `install` and `update` save the language of the
session they run in (`LOCAL_DELEGATE_LANG=es|en`, or the system's) in `language.json`, so the daemon
and the hooks use it too, and they write the skill, the memory block and the subagents' catalog in
that language. Precedence and how to go back to following the system:
[Language](./docs/wiki/Language.en.md).

Three hooks act on their own: `UserPromptSubmit` (mechanical intents), `SubagentStart` (reminds each
subagent to load the `local_*` tools and read by ranges) and `record_call.py` (`PreToolUse` on the
local-delegate tools), which neither warns nor blocks: it records which agent requested each
delegation and with what effort, to attribute the equivalent cost to its model. The two read
ones —`PreToolUse`/`Read` and `PreToolUse`/`Bash|PowerShell`— stay off unless
`--enable-read-hook`, which turns them on together (`--disable-read-hook` or `uninstall` turn them
off). They go together because they are a single rule over two paths: closing the `Read` tool and
leaving `cat report.md` open does not change the behavior, it moves it elsewhere. With a large
image that `local_describe_image` accepts (`.png`, `.jpg`, `.gif`, `.webp`) the notice recommends
that tool with `path`, not a read by ranges; `.svg`, `.bmp`, `.ico`, small images, `.pdf` and
`.ipynb` pass silently.

Those two warn; **rejecting** a read is something else and comes apart and off
(`LD_HOOK_READ_BLOCK`). It only reaches the full read of a large `.md` or `.txt`, with the local
backend answering, and the rejection message names the tool that serves and the emergency exit:
reading by slices is never blocked. The reason it exists is that it is measured —four times— that
suggesting does not change the behavior.
See [Integration install](./docs/wiki/Integration-install.en.md) and
[`docs/recipes/claude-code-hooks.md`](./docs/recipes/claude-code-hooks.md).

### Claude Code plugin, mod commands and Claude Desktop

Since 0.40, with Claude Code 2.1.292 or later installed with `uv tool`, `install` delivers the hooks
as a **plugin** (`local-delegate@local-delegate`) instead of writing them to `settings.json`, and
migrates an earlier installation on its own while preserving the read block. If the conditions are
not met, it falls back to `settings.json` and says why; `--claude-delivery settings` goes back to
that by hand and `update` respects it. The MCP **is not** inside the plugin.

The plugin also carries a **mod**, which runs inside Claude Code without spending model turns:

- `/local-summarize <path>`, `/local-commit` (proposes the message from `git diff --cached`; only shows it) and `/local-lint <file|command>` call the local tool directly.
- Pins `local_summarize`, `local_extract`, `local_lint_summary` and `local_commit_msg`, so the model does not have to look them up with ToolSearch.
- Puts a band above the prompt with the state of local-delegate in the session: in the terminal, a one-row bar with a background and a state label (` ● READY `, ` ◐ DELEGATING `, ` ◔ LOADING `, ` ○ DOWN `), the model, the tool in progress with its slice (`7/9`) and how long it has taken (`3 min 16 s`), the delegations and the session's savings and the read mode (option `status_style`: `bar` or `line`, a dash over a line); in Claude Desktop, a single line of text in two tones, without pill or link. Since 0.45.0, with several delegations at once it names first the one processing the backend and, if all are waiting, the oldest with its wait (`in queue · 4 min 0 s`). A delegation waiting for llama-swap to switch models says ` ◐ WAITING BACKEND ` with the model it asked for, not the one loaded. It refreshes itself every second while a delegation is in progress. Since 0.50.0 a single slow poll does not put it in ` ○ DOWN `: like the dashboard, it takes a second consecutive failure. While llama-swap starts a model it says ` ◔ LOADING ` with that model, even if `/v1/models` does not answer in time (#628): ` ○ DOWN ` is left for a backend that does not respond. Claude quota is not here: it belongs to the status line.
- Since 0.41, the **read mod** (on by default, option `read_mod_enabled`) summarizes with `local_summarize` the large prose read in full and delivers the summary as the result of the tool itself; with a dialog it asks first. After a summary, writing to that file is rejected until it is actually read. While it acts, the session's read hooks are set aside. To decide what each call reads it asks the daemon, without starting processes (the measured per-`Bash`-call overhead stays within the noise). A missing saved value counts as enabled; if you turned it off in 0.40.0, it turns back on in the plugin's configuration menu. Since 0.44.2 a range read always passes literally in a subagent (without spending the main thread's 80 % margin), in a short file (200 lines or fewer and less than 32 KB) and when the range starts after the last line. Since 0.50.0 it reuses the summary of a file whose text did not change (`summary_reused` in telemetry, not counted as new savings), and the hooks let the read pass when the session does not have the MCP. Since 0.51.0, if Claude Code sends the summary to the background, the read goes literally instead of delivering its notice as the summary, and the header counts the lines the file has at that moment.
- After updating, open a new Claude Code session: the mods load when the session starts.

On Windows, `install --desktop` adds the **Claude Desktop** chat: it writes an entry that launches `local-delegate desktop-bridge`, an stdio bridge to the daemon that reads the token itself, because Desktop does not pass its environment to the MCP. To go down to 0.39, `uninstall` first. Full details in [Claude Code plugin delivery](./docs/wiki/Claude-plugin.en.md).

### The mod in Codex

Codex does not load the mod and has nothing equivalent: there are no user commands without a model (only `!command`, which runs a local command) and no bar to paint your own thing in (`/statusline` picks Codex's fixed fields). What it does have is a way for the model to see the tools without searching for them:
`install --clients codex --codex-direct-tools` sets `omit_tools_from = ["deferred"]` in the MCP entry. All eleven tools come in at once (Codex does not let you pick them one by one), about 15.8 KB more per turn, so it is off by default; `update` keeps what you choose. The full table, with the evidence for each row and the pending live tests:
[Codex: what it has and what it does not have from the mod](./docs/wiki/Codex-capabilities.en.md).

## llama-swap groups (optional)

With `pip install "local-delegate-mcp[llamaswap]"`, the CLIs to manage llama-swap **groups** (a pool that rotates and, only if you ask, a model that stays loaded) are available, with a built-in VRAM guardrail **and system RAM** (`--ram-gb` is optional: `llama-server` also maps the GGUF in RAM even when the compute is 100 % GPU, so a catalog that fits in VRAM can still exhaust RAM on machines with less than 32 GB):

```bash
local-delegate check-llamaswap --config config.yaml --vram-gb 16 --ram-gb 32
local-delegate init-llamaswap --config config.yaml --swap gemma3-4b,gemma4-26b-a4b,qwen36-35b-a3b --vram-gb 16 --ram-gb 32
local-delegate llamaswap residency            # what stays loaded and with what TTL; does not write
local-delegate llamaswap residency --none --ttl gemma3-4b=120   # back to “no resident”
```

**The recommended option is no resident**: with the daemon's rotation, colliding models share the backend without fighting each other, and an already loaded model is used when there is an approved cell for that tool (see [Tools](./docs/wiki/Tools.en.md)). Residency is opt-in:
`init-llamaswap --resident ID` or `llamaswap residency --pin ID` leave that model in a `persistent` group with `ttl: 0`, and **hold its VRAM permanently** (`--pin` asks for each model's measured VRAM with `--vram-model ID=GiB` and refuses if it does not fit together with the worst case of the rest). `--ttl-resident` defaults to 0: with `persistent` and a TTL above 0 the model unloads all the same and there is no real residency.

The package **never** touches your `config.yaml` on its own — these commands only run if you invoke them. `init-llamaswap` runs the guardrail(s) before writing (writes nothing if it does not fit in VRAM or, if you passed `--ram-gb`, in RAM) and never overwrites without `--force` (leaving a copy `<config>.<YYYYMMDD-HHMMSS>.bak`). `llamaswap residency` edits only the lines that change, leaves the same dated copy, does not write with delegations in progress (except with `--now`) and says what llama-swap did with the reload. Full detail, semantics of `groups` verified against llama-swap's code, and the application ritual in [`docs/recipes/llama-swap-groups.md`](./docs/recipes/llama-swap-groups.md).

## Links

- [Wiki](./docs/wiki/Home.en.md) · [Recipes](./docs/recipes)
- [CONTRIBUTING](./CONTRIBUTING.md) · [CODE OF CONDUCT](./CODE_OF_CONDUCT.md) · [CHANGELOG](./CHANGELOG.md)
- [MIT License](./LICENSE)
