What it is
Headroom compresses what an AI agent reads (tool outputs, logs, RAG chunks, files, conversation history) before it reaches the LLM. Compression runs on your machine. It routes content to compressors for JSON, code (AST) and text, and caches originals locally so the model can retrieve them on demand (CCR). It is available as a Python/TypeScript library, a proxy, one-command agent wrappers and an MCP server.
Who it's for
- Developers who run coding agents daily and want token savings without changing their code
- Teams using several agents (Claude, Codex, Gemini, Grok) who want one shared memory store
- Users who need reversible compression with retrievable originals
- Python and TypeScript app builders who want inline compression in LangChain, LiteLLM, Vercel AI SDK, Agno and similar stacks
Requirements
Requirements
- Python 3.10+
- The
headroomCLI ships only in the PyPI package; the npmheadroom-aipackage is the TypeScript SDK and has no CLI - Ability to run local processes (not suited to sandboxes where they can't run)
- Optional: C++ toolchain for the
[vector]extra
Setup
Install
Install the CLI in an isolated env, via pip, or the TypeScript SDK (library only).
bashuv tool install --python 3.13 "headroom-ai[all]" # CLI in a self-contained env pip install "headroom-ai[all]" # Python — ships the `headroom` CLI npm install headroom-ai # TypeScript SDK only — no CLIPick a mode
Deploy locally, wrap a coding agent, or run a drop-in proxy.
bashheadroom deploy # turnkey local deployment + agent config headroom wrap claude # wrap a coding agent headroom proxy --port 8787 # drop-in proxy, zero code changesCheck health and savings
Verify routing and watch savings (the proxy must be running for the dashboard).
bashheadroom doctor # health check — confirms routing works headroom perf headroom dashboard # live savings (proxy must be running)
Examples
Inline compression in Python
pythonfrom headroom import compress
from openai import OpenAI
messages = [{"role": "user", "content": "Analyze these results"}]
result = compress(messages, model="gpt-4o")
client = OpenAI()
response = client.chat.completions.create(model="gpt-4o", messages=result.messages)
print(f"Saved {result.tokens_saved} tokens ({result.compression_ratio:.0%})")What it does: Compresses messages before sending them to an OpenAI client and prints the tokens saved.
Enable output token reduction on the proxy
bashexport HEADROOM_OUTPUT_SHAPER=1 # off by default
headroom proxy --port 8787What it does: Turns on verbosity steering and effort routing so the model writes fewer tokens back.
Learn a terseness level from past sessions
bashheadroom learn --verbosity # dry run — preview what it found
headroom learn --verbosity --apply # save it and apply it to the running proxyWhat it does: Reads past sessions to pick a verbosity level, with a dry run before applying.
Configure an MCP client with an absolute path
toml[mcp_servers.headroom]
command = "/Users/you/.local/bin/headroom"
args = ["mcp", "serve"]What it does: MCP clients like Codex often can't inherit the shell PATH, so use the absolute path from command -v headroom.
Pros & cons
Pros
- Pro:Runs locally; no prompt or file content is sent anywhere to be compressed
- Pro:Many integration paths: library, proxy, one-command wrapping for many agents, MCP server
- Pro:Reversible via CCR; the model can retrieve originals on demand
- Pro:Reported accuracy parity on GSM8K and TruthfulQA at N=100, with sub-millisecond compression overhead
Cons
- Con:Savings depend on the payload: prose, short conversations and already-dense output see little or no reduction
- Con:Cursor needs manual setup and Cortex Code is library-only with no
wrap - Con:Output-token savings are counterfactual estimates unless you configure a holdout
Images
