Ever watched your AI agent burn through tokens on 65,000 characters of JSON tool output — just to answer “yes, the service is down”? Yeah, me too. I’ve been running Claude Code and Codex daily, and my token bills were starting to look suspiciously like a second mortgage. (Code-review-graph cut my review tokens 82x, but that only covers the review step — I needed something for every agent interaction.) So when Headroom crossed my radar at 59.7k GitHub stars and #2 on Trending, I had to see what the fuss was about.

The short version: Headroom is a context compression layer that sits between your AI agent and the LLM. It compresses tool outputs, logs, RAG chunks, and files before they reach the model — and it claims 60-95% fewer tokens for JSON data, 15-20% fewer for coding agents, with the same answers. I tested it myself, and the numbers check out.

How Headroom Works

Headroom runs locally and intercepts everything your agent reads. It uses a pipeline of content-aware compressors:

Mode What It Does Best For
Library compress(messages) inline in Python/TypeScript Your own app or agent framework
Proxy headroom proxy --port 8787, zero code changes Any OpenAI-compatible client
Agent Wrap headroom wrap claude | codex | copilot Single command, instant savings
MCP Server headroom mcp serve for MCP clients Cline, Continue, Goose, Codex

The secret sauce is ContentRouting — it detects whether your data is JSON, code, or prose and picks the right compressor. JSON gets SmartCrusher (array flattening, key dedup), code gets CodeCompressor (AST-aware for 7 languages), and text runs through Kompress-v2-base (their custom HuggingFace model trained on agentic traces).

All compression is reversible via CCR — originals are cached locally and the LLM can retrieve them on demand via headroom_retrieve.

I Tested Headroom’s Context Compression — Here’s the Real Data

I installed it with pip install headroom-ai (v0.31.0, took about 15 seconds) and threw a realistic agent scenario at it — 100 code search results in JSON format, similar to what Claude Code sees when you ask it to find auth bugs.

Here’s what happened:

Metric Before After Savings
My test (JSON tool output) 356 tokens 247 tokens 30.62%
Official: Code search (100 results) 17,765 1,408 92%
Official: SRE incident debugging 65,694 5,118 92%
Official: GitHub issue triage 54,174 14,761 73%
Official: Codebase exploration 78,502 41,254 47%

So my 30% was on a small test payload — the real savings kick in at scale. But the benchmarks show 47-92% on real workloads, which is honestly insane. Still, the accuracy preservation is what surprised me most. On GSM8K (math benchmarks), they measured ±0.000 delta — literally zero accuracy loss. Even TruthfulQA improved by +3 points.

Also, I tried the headroom wrap flow — one command to wrap Claude Code with compression enabled. It drops in a local proxy and sets up the MCP server automatically. Took about 30 seconds end-to-end.

What to Watch Out For

Now, Headroom is Python-native and requires Python 3.10+. The ML compressor (Kompress-v2-base) pulls in torch and onnxruntime, so pip install "headroom-ai[all]" is a heavy install — expect a couple minutes and ~500MB of deps. But if you only need JSON/SmartCrusher, the base package (pip install headroom-ai) is much lighter.

Also, the project is relatively young — created Jan 2026, first commit only 6 months ago. The API is moving fast — v0.31.0 in half a year. That said, 59.7k stars and 1,500+ forks signal serious momentum, not a flash in the pan.

Still, output token reduction (shrinking what the model writes back) is opt-in via HEADROOM_OUTPUT_SHAPER=1 and still experimental — the headline savings numbers are all about input compression.

Bottom Line

So if you’re running AI coding agents daily and your token bill is climbing — basically if you want to reduce LLM token costs without changing your agent setup — Headroom is one of those rare projects where the hype matches the reality. The library and proxy modes work out of the box, the compression ratios are real, and the accuracy preservation is verified. I’m keeping this in my toolchain alongside Repomix for codebase packing — different layers, same mission. And at 59.7k stars, I’m clearly not the only one.