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 HEADROOM_SAVINGS_PROFILE and correct --mode default (#2031) (#2040)
Shubham Srivastavaf9f3162d3883
diff --git a/docs/content/docs/proxy.mdx b/docs/content/docs/proxy.mdxindex 8747cd0a6..78a358348 100644--- a/docs/content/docs/proxy.mdx+++ b/docs/content/docs/proxy.mdx@@ -37,7 +37,7 @@ Telemetry is **off by default** (opt-in). Opt in with `HEADROOM_TELEMETRY=on` or| `--max-connections` | `500` | Maximum upstream HTTP connections || `--max-keepalive` | `100` | Maximum upstream keep-alive connections || `--http-proxy` | None | HTTP proxy URL for upstream provider requests only; HTTPS provider APIs use CONNECT |-| `--mode` | `token` | Optimization mode: `token` prioritizes compression, `cache` preserves provider prefix-cache stability |+| `--mode` | `cache` | Optimization mode: `token` prioritizes compression, `cache` preserves provider prefix-cache stability. Default is `cache` (see [Savings profiles](#savings-profiles)) || `--no-optimize` | `false` | Disable optimization (passthrough mode) || `--no-cache` | `false` | Disable semantic caching || `--no-rate-limit` | `false` | Disable rate limiting |@@ -65,8 +65,8 @@ Avoid setting process-wide variables such as `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_P| Option | Default | Description ||--------|---------|-------------|-| `--mode token` | `token` | Prioritize token compression. This is the default. |-| `--mode cache` | `token` | Preserve prior turns to maximize provider prefix-cache hit rate. |+| `--mode token` | | Prioritize token compression; prior turns may be rewritten for maximum savings. |+| `--mode cache` | default | Freeze prior turns to maximize provider prefix-cache hit rate. This is the effective default (see [Savings profiles](#savings-profiles)). || `--intercept-tool-results` | `false` | Opt into tool-result interceptors such as ast-grep Read outlining. || `--no-read-lifecycle` | `false` | Disable stale/superseded Read-output compression. || `--code-aware` / `--no-code-aware` | disabled | Enable or disable AST-based code compression. Requires `headroom-ai[code]`. |@@ -90,6 +90,26 @@ headroom proxy --mode tokenheadroom proxy --mode cache```+### Savings profiles++`HEADROOM_SAVINGS_PROFILE` selects a named profile that seeds Headroom's whole compression posture — proxy mode, keep-ratio, which messages are compressed, and `force_kompress` — at proxy startup. It is read by `headroom proxy` and by the `headroom wrap` subprocesses. When unset, the default profile is `coding`.++| Profile | Target savings | Mode | Notes |+|---------|----------------|------|-------|+| `coding` | emergent (~50%) | `cache` | **Default.** Delta-only compression at ~0 prefix-cache busts; never lossy-compresses file reads. |+| `balanced` | ~70% | `token` | Moderate compression with structural compaction. Also the fallback for an unknown profile name. |+| `agent-90` | ~90% | `token` | Aggressive; pins a `0.10` keep-ratio and forces Kompress. |+| `general` | emergent (~60%) | `token` | Non-coding workloads. |++An unrecognized `HEADROOM_SAVINGS_PROFILE` value logs a warning and falls back to `balanced` — the proxy never fails to start over a bad profile name. 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:++```bash+# Aggressive ~90% token-savings profile+HEADROOM_SAVINGS_PROFILE=agent-90 headroom proxy --port 8787+```+### Optional features| Option | Default | Description |diff --git a/headroom/cli/proxy.py b/headroom/cli/proxy.pyindex 0c60c5da4..c97cc5868 100644--- a/headroom/cli/proxy.py+++ b/headroom/cli/proxy.py@@ -247,7 +247,7 @@ def dashboard(port: int, no_open: bool) -> None:case_sensitive=False,),help=(- "Optimization mode (default: token).\n"+ "Optimization mode (default: cache).\n"" token — prioritize compression; prior turns may be rewritten for max savings.\n"" cache — freeze prior turns to maximise provider prefix-cache hit rate.\n""Legacy aliases (token_mode, token_savings, token_headroom, cache_mode, "diff --git a/tests/test_cli_proxy_improvements.py b/tests/test_cli_proxy_improvements.pyindex d6787da13..e400ae35b 100644--- a/tests/test_cli_proxy_improvements.py+++ b/tests/test_cli_proxy_improvements.py@@ -478,6 +478,11 @@ class TestHelpTextCompleteness:def test_help_contains_mode_option(self, runner: CliRunner) -> None:assert "--mode" in self._help(runner)+ def test_help_reports_cache_as_default_mode(self, runner: CliRunner) -> None:+ out = self._help(runner)+ assert "Optimization mode (default: cache)" in out+ assert "Optimization mode (default: token)" not in out+def test_help_contains_workers_option(self, runner: CliRunner) -> None:assert "--workers" in self._help(runner)