{"slug": "llm-token-compressor-vs-headroom-i-measured-both-here-s-what-the-numbers-say", "title": "LLM Token Compressor vs Headroom: I Measured Both. Here's What the Numbers Say.", "summary": "A developer built TokenSlim, an open-source token-compression library for coding agents, and benchmarked it against Headroom (~81k stars) using the same inputs and tiktoken counter. On a realistic 17-message coding session, TokenSlim cut 2,150 tokens to 592 (−72.5%), and on a 40-turn session it reached 3,683 tokens (−97.9%) versus Headroom's 57,111 (−68.2%), with both preserving 5/5 load-bearing facts. On a 55-fact table, TokenSlim kept 55/55 facts at −97.9% while Headroom kept 52/55 at −41.7%, though the comparison covered only Headroom's heuristic routers since its 261 MB ONNX ML compressor did not run in the test environment.", "body_md": "**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.\n\nI 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?\n\nMost 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.\n\nEvery 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.\n\nA 98% cut that deletes the error you're debugging isn't a win. It's a bug with good marketing.\n\nThe 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.\n\nRun 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.\n\nOn 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.\n\nHeadroom 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.\n\nThe scenario: a 40-turn coding session, 179,631 tokens, with an ERROR line buried in the middle.\n\nHeadroom 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.\n\nI 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.\n\nOne 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.\n\nAnd 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).\n\nThe library is the core, but the pieces around it are where it fits into real work:\n\nThat'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:\n\n```\npip install tokenslim-py\ngit clone https://github.com/kamalmosadegh/tokenslim\ncd tokenslim\npython core/tests/benchmark_real.py            # the realistic 72.5% number\npython core/tests/benchmark_headroom.py        # the Headroom head-to-head (needs pip install headroom-ai)\n```\n\nIf 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.\n\n*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](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](https://dev.to/kamalmosadegh/tokenslim-10-four-repos-one-repo-and-every-number-re-runnable-56n4)*", "url": "https://wpnews.pro/news/llm-token-compressor-vs-headroom-i-measured-both-here-s-what-the-numbers-say", "canonical_source": "https://dev.to/kamalmosadegh/llm-token-compressor-vs-headroom-i-measured-both-heres-what-the-numbers-say-3haj", "published_at": "2026-12-01 19:01:35+00:00", "updated_at": "2026-12-01 19:13:37.364643+00:00", "lang": "en", "topics": ["large-language-models", "ai-agents", "ai-tools", "developer-tools", "mlops"], "entities": ["TokenSlim", "Headroom", "tiktoken", "kamalmosadegh", "ONNX"], "also_reported_by": [], "takeaway": "TokenSlim cut a realistic coding session from 2,150 to 592 tokens (−72.5%) and a 40-turn session to 3,683 tokens (−97.9%) versus Headroom's 57,111, while both kept 5/5 facts and matched raw context at 23/24 on a 24-question accuracy eval.", "recommendation": {"advice": "Gate any context-compression saving on a fact-recall check that fails the run if load-bearing facts like error lines or trace IDs disappear, and benchmark against your own real sessions rather than pathological repeats.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/llm-token-compressor-vs-headroom-i-measured-both-here-s-what-the-numbers-say", "markdown": "https://wpnews.pro/news/llm-token-compressor-vs-headroom-i-measured-both-here-s-what-the-numbers-say.md", "text": "https://wpnews.pro/news/llm-token-compressor-vs-headroom-i-measured-both-here-s-what-the-numbers-say.txt", "jsonld": "https://wpnews.pro/news/llm-token-compressor-vs-headroom-i-measured-both-here-s-what-the-numbers-say.jsonld"}}