Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
docs(proxy): document cache-mode memory behavior (#3577)
AxelRay7ff67693be35
diff --git a/README.md b/README.mdindex 5ae98a97d..389d919b7 100644--- a/README.md+++ b/README.md@@ -252,6 +252,8 @@ Any OpenAI-compatible client works through `headroom proxy`. MCP-native clients:`zcode`). Registry authors should use the canonical [`server.json`](server.json)rather than reconstructing the `headroom mcp serve` contract from prose.+For Anthropic `/v1/messages`, `--mode cache` skips automatic `--memory` context injection so the provider prefix remains stable. OpenAI chat/responses and Gemini append memory to the live-zone tail. Use `--mode token` when you need automatic memory context on the Anthropic path.+<details><summary><b>GitHub Copilot CLI subscription mode</b></summary>diff --git a/docs/content/docs/proxy.mdx b/docs/content/docs/proxy.mdxindex ca5fa31c9..19fc5447c 100644--- a/docs/content/docs/proxy.mdx+++ b/docs/content/docs/proxy.mdx@@ -116,7 +116,7 @@ headroom proxy --mode cacheAn unrecognized `HEADROOM_SAVINGS_PROFILE` value logs a warning and falls back to `coding` (the same default an unset variable resolves to) — the proxy never fails to start over a bad profile name. `balanced` is used only as a last-resort fallback when the runtime has no `coding` entry at all (old-runtime/new-client version skew). See `headroom/agent_savings.py` for each profile's full set of knobs.-Because the default `coding` profile uses **cache** mode (and the proxy's own default mode is also `cache`), Headroom runs in cache mode out of the box. Mode precedence: an explicit `--mode` wins, otherwise `HEADROOM_MODE` (which a profile seeds), otherwise the `cache` default. To run token mode, pass `--mode token` or choose a token-mode profile:+Because the default `coding` profile uses **cache** mode (and the proxy's own default mode is also `cache`), Headroom runs in cache mode out of the box. For a direct `headroom proxy` invocation, mode precedence is `--mode` > `HEADROOM_MODE` > the `cache` default. The selected `HEADROOM_SAVINGS_PROFILE` does not provide a third-level mode fallback after startup; wrapped launches may seed `HEADROOM_MODE` before starting the proxy. To run token mode, pass `--mode token` or set `HEADROOM_MODE=token`:```bash# Aggressive ~90% token-savings profile@@ -127,7 +127,7 @@ HEADROOM_SAVINGS_PROFILE=agent-90 headroom proxy --port 8787| Option | Default | Description ||--------|---------|-------------|-| `--memory` | `false` | Enable persistent user memory and provider-appropriate memory tools |+| `--memory` | `false` | Enable persistent user memory and provider-appropriate memory tools. In `--mode cache`, automatic context injection is skipped only for Anthropic `/v1/messages` to preserve prefix stability; OpenAI chat/responses and Gemini append memory to the live-zone tail. Use `--mode token` for automatic memory context on the Anthropic path. || `--memory-db-path` | `{cwd}/.headroom/memory.db` | Override the memory SQLite path || `--no-memory-tools` | `false` | Disable automatic memory tool injection || `--no-memory-context` | `false` | Disable automatic memory context injection |@@ -175,17 +175,20 @@ HEADROOM_SAVINGS_PROFILE=agent-90 headroom proxy**`general`** — Token-mode compression for non-coding conversations. No turn protection (`protect_recent=0` — nothing code-positional to preserve) and does not compress user or system messages. Uses the standard lossless pipeline.-### Profiles override CLI flags+### Profile defaults and overrides-A profile's `proxy_mode` setting overrides the `--mode` flag. The `coding` profile sets `proxy_mode="cache"`, so `--mode token` has **no effect** when coding is active:+Profiles seed compression settings. For a direct `headroom proxy` invocation, explicit mode settings take precedence in this order: `--mode` (CLI) > `HEADROOM_MODE` (environment) > the `cache` default. The selected profile does not replace that final fallback, but wrapped launches may pre-seed `HEADROOM_MODE`. The `coding` profile defaults to `cache`, and an explicit `--mode token` still takes effect:```bash-# These are equivalent — coding's cache mode always wins+# Coding's default mode is cacheheadroom proxy-headroom proxy --mode token # --mode token is silently overridden+# An explicit CLI mode overrides the profile default+headroom proxy --mode token+# An explicit environment mode also overrides the profile default+HEADROOM_MODE=token HEADROOM_SAVINGS_PROFILE=coding headroom proxy```-To run in token mode, switch to a profile that uses it:+You can also choose a profile whose default is token mode:```bashHEADROOM_SAVINGS_PROFILE=agent-90 headroom proxy --mode token