LLM Token Compressor vs Headroom: I Measured Both. Here's What the Numbers Say.
TL;DR: I built TokenSlim to cut my coding agent's token use, then benchmarked it against Headroom (~81k stars) on the same inputs with the same counter. Realistic session: 2,150 → 592 tokens (−72.5%). 40-turn head-to-head: TokenSlim 3,683 tokens (−97.9%), Headroom 57,111 (−68.2%) — both kept 5/5 facts. Every number below is re-runnable from the repo.
I built TokenSlim because my coding agent kept drowning in its own tool outputs. But building it was the easy part. The hard part was answering one question honestly: does it actually work, or am I just moving tokens around and calling it a win?
Most tools in this space answer that question with a single big percentage. I didn't trust that — not from other tools, and not from myself. So I built the benchmark first, and I built it with a rule: a saving only counts if the facts survive.
The rule: facts or it didn't happen
Every benchmark in the TokenSlim repo ships with a fact-recall check. Before I compress anything, I pick the load-bearing facts in the input — the ERROR line, the trace ID, the amount, the answer — and after compression I check they're still there. If one is gone, the run fails, no matter how impressive the percentage looks.
A 98% cut that deletes the error you're debugging isn't a win. It's a bug with good marketing.
The realistic number: 72.5%
The headline scenario is a realistic 17-message coding session: a system prompt, three tool schemas, grep output, a source file, a pytest log, an API JSON dump, one realistic re-read of the same file, three RAG chunks. 2,150 tokens raw.
Run the pipeline — cache the repeated tool calls, trim the outputs, compress the RAG chunks, compact the old history — and it lands at 592 tokens. That's a 72.5% cut, counted with exact tiktoken.
On pathological inputs (the same 5,000-token log pasted ten times) the same pipeline reaches about 98%. I'm telling you that so you know it exists, not so you believe it. Your real sessions look like the first number, not the second.
Head-to-head with Headroom
Headroom is the strongest tool in this space, around 81,000 stars, and it deserves a fair comparison. So I ran one: same inputs, same tiktoken counter, both tools.
The scenario: a 40-turn coding session, 179,631 tokens, with an ERROR line buried in the middle.
- TokenSlim: 3,683 tokens (-97.9%), 5/5 facts kept
- Headroom: 57,111 tokens (-68.2%), 5/5 facts kept
Headroom kept the facts too. On English logs, it's genuinely good. The gap is depth: TokenSlim squeezes much harder on the same input. And there's one place Headroom's routers do nothing at all — small messages under its 250-token floor. TokenSlim has no floor.
I also ran a bigger version, a 55-fact table (353,523 tokens). TokenSlim kept 55/55 facts at -97.9% (7,522 tokens); Headroom kept 52/55 at -41.7% (206,067 tokens). All three of Headroom's misses were the same systematic drop, an fs-search path fact. I re-ran this one twice and got the same numbers both times, line for line.
One honest caveat: Headroom's ML text compressor (a 261 MB ONNX model) didn't run in my environment, so this compares its heuristic routers only. If you run the ML backend and get different numbers, I want to hear about it.
And one more check, because compression that makes your agent dumber is also a failure: on a small 24-question accuracy eval (single run per model, two models — small eval, stated plainly), raw context, TokenSlim and Headroom all scored 23/24. TokenSlim matches them, it doesn't beat them — while using 73.9% fewer context tokens on average (386 vs 1,476).
The rest of the stack
The library is the core, but the pieces around it are where it fits into real work:
- Gateway proxy: sits between your agent and its tools, trims every tool result before it reaches the model. Measured: 8,062 → 241 tokens (-97.0%), 4/4 facts kept.
- LangGraph middleware: trims tool outputs before they re-enter your agent's state. Measured: tool output 10,261 → 409 (96.0%), total state 10,317 → 465 (95.5%).
- MCP server: exposes the same trimming as a tool your agent can call.
Run it yourself
That's the whole point of this article. Don't take my numbers — they're in the repo, and they take about a minute to reproduce:
pip install tokenslim-py git clone https://github.com/kamalmosadegh/tokenslim cd tokenslim python core/tests/benchmark_real.py # the realistic 72.5% number python core/tests/benchmark_headroom.py # the Headroom head-to-head (needs pip install headroom-ai) If your numbers come out different, open an issue and tell me. A benchmark that can't be challenged isn't a benchmark, it's an ad.
TokenSlim v1.0.0 is on PyPI now — tokenslim-py, tokenslim-mcp, tokenslim-gateway, tokenslim-langgraph. MIT licensed. The repo is https://github.com/kamalmosadegh/tokenslim. My launch article is here: https://dev.to/kamalmosadegh/tokenslim-10-four-repos-one-repo-and-every-number-re-runnable-56n4