Overview
Headroom compresses everything an AI agent reads — tool outputs, logs, RAG chunks, files and conversation history — before it reaches the model. The goal is the same answer from far fewer tokens. The project reports 60–95% fewer tokens on JSON data and 15–20% fewer for coding agents, and its demo shows a 10,144-token input reduced to 1,260 while still surfacing the same FATAL log line.
It runs locally, so the data being compressed stays on your machine, and it exposes four entry points for different integration styles: a library (`compress(messages)` in Python or TypeScript), a drop-in proxy that needs no code changes in any language, a one-command wrapper around a specific coding agent, and an MCP server exposing `headroom_compress`, `headroom_retrieve` and `headroom_stats` to any MCP client.
Internally a ContentRouter detects the content type and picks a matching compressor: SmartCrusher for JSON, CodeCompressor for AST-aware code, and the Kompress-v2-base model for prose. A CacheAligner detects and warns about volatile content that would bust a provider's KV-cache prefix, without rewriting prompts itself. Compression is reversible — originals are cached locally under a scheme the project calls CCR, and the model can call `headroom_retrieve` when it needs the untruncated version. Headroom also ships cross-agent memory shared across agents with automatic dedup, and a `headroom learn` command that mines failed sessions and writes corrections into `CLAUDE.local.md`, `CLAUDE.md`, `AGENTS.md`, `GEMINI.md` or `GROK.md`.
What it does
- Content-aware compressors — SmartCrusher for JSON, CodeCompressor for AST, Kompress-v2-base for prose — selected automatically by a ContentRouter
- Four integration modes: Python/TypeScript library, drop-in proxy, one-command agent wrap, and MCP server
- Reversible compression (CCR): originals cached locally and retrievable by the model on demand
- CacheAligner warns about volatile content that would invalidate a provider's KV-cache prefix, without rewriting prompts
- Cross-agent memory shared across Claude, Codex, Gemini and Grok with automatic dedup
- Output token reduction that trims what the model writes back, not only what you send
Getting started
Install the CLI, choose an integration mode, then verify the savings. Note that the npm package ships the TypeScript SDK only — the `headroom` CLI comes from the uv or pip install.
Install
Use uv or pip for the CLI; npm gives you the TypeScript SDK without the CLI.
uv tool install --python 3.13 "headroom-ai[all]" # CLI as a global tool
pip install "headroom-ai[all]" # Python — ships the `headroom` CLI
npm install headroom-ai # TypeScript SDK onlyPick a mode
Wrapping a coding agent starts a local proxy, installs Serena for semantic code navigation, and launches the agent configured to route through Headroom. Undo it with `headroom unwrap <tool>`, or skip Serena with `--code-memory none`.
headroom deploy # turnkey local deployment + agent config
headroom wrap claude # wrap a coding agent
headroom proxy --port 8787 # drop-in proxy, zero code changes
# or inline: from headroom import compressVerify the setup and watch the savings
`doctor` confirms routing is working; the dashboard needs the proxy running.
headroom doctor
headroom perf
headroom dashboardCommands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Cut the token bill of a coding agent that keeps reading long logs, test output and large files
- Compress verbose JSON tool responses before they reach the model, where the reported savings are largest
- Add compression to an existing app with no code change by pointing it at the local proxy
- Keep compression reversible so an agent can pull the original text back when a summary is not enough
How Headroom compares
Headroom alongside other open-source gateways & routing tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| RTK | ★ 79.1k | A single-binary Rust CLI proxy that filters, groups, truncates and dedupes the output of 100+ dev commands before a coding agent reads it, cutting token use by 60–90%. |
| Headroom | ★ 69.1k | The context compression layer for AI agents |
| OmniRoute | ★ 61.9k | A local-first AI gateway that fronts hundreds of model providers with one OpenAI-compatible endpoint, quota-aware auto-fallback, many routing strategies and prompt compression. |
| LiteLLM | ★ 58.2k | A Python SDK and proxy server that gives one OpenAI-compatible API to 100+ LLM providers, with cost tracking, budgets, fallbacks, rate limiting, and an admin UI. |
| Apache APISIX | ★ 17.1k | A cloud-native API gateway whose AI plugins add multi-provider LLM proxying, load balancing, retries and fallbacks, token-based rate limiting, and content moderation. |
| Portkey AI Gateway | ★ 12.9k | An LLM gateway that routes calls to 100+ providers through one API and adds logging, tracing, caching, and fallbacks for production AI traffic. |
| Higress | ★ 9.3k | An AI-native API gateway built on Istio and Envoy that proxies and governs traffic to many LLM providers, with token rate limiting, caching, and MCP server hosting. |
| Bifrost | ★ 7.8k | A high-throughput LLM gateway written in Go that gives a single OpenAI-compatible API to many providers, with failover, load balancing, semantic caching, and very low overhead at high request rates. |