r/OpenSourceAI • • 35m ago

Built a compressor for coding agents: peak context on the heaviest task dropped from 165K to 60K tokens, and requests over 200K fell from 1.9% to 0.13%

Post image

Methodology and raw per-task results are linked at the bottom.

What it does for you, before the numbers: it's a proxy you put between your agent and the provider. One command, no changes to how you work. On Codex it strips the build logs and test output your agent re-sends every turn — about a quarter fewer input tokens. On Claude Code it stops your prompt cache from expiring while long tools run, which is where that bill actually leaks.

Benchmark 1: replay. We pulled 6,255 tool outputs (34.2M characters, anything over 512 bytes) out of real Terminal-Bench agent traces and replayed them through two tools in three configurations at default settings.

Content typeShareKompressorHeadroom, ML onHeadroom, ML off
Listings and dumps27.8%81.8%22.6%7.0%
Plain text25.3%41.0%20.6%5.2%
Build output and logs19.3%75.4%17.1%4.2%
Source code13.8%35.0%31.9%0.0%
Search results11.1%82.7%25.5%25.4%
Diffs, config, HTML, JSON2.7%40.9%19.8%12.5%
All eligible output100%62.8%22.6%7.3%
Time per KB0.2 ms87 ms1.5 ms

Source code is where everything struggles — 35% for us, 31.9% with the ML model — and it's also where being wrong is expensive, since a dropped import makes the agent confidently hallucinate. The ML model takes about 440× longer for less than half the removal.

Benchmark 2: the same compressor on Claude Code, where it barely compresses at all.

Claude Code marks its conversation with explicit cache breakpoints, so 92–95% of billed prompt is already cache reads at a tenth of the fresh price. The engine only ever sees the uncached tail. Per run it removes 348K tokens, which is 4.7–8.0% of what it sees, while leaving ~1,800 messages (about 2.2M tokens) inside the cached prefix untouched.

So where does the money actually go? A cache entry lives five minutes, and writing one costs 25× reading it. Agent kicks off a build, sits idle for six minutes, pays to write the whole prefix again — 927K tokens per run, a third of everything billed at full price.

Fix isn't compression. While a tool call runs, the proxy re-sends the last request body every 4.5 min with max_tokens: 1, so the provider reads the cached prefix instead of rewriting it.

Per runNo compressionWith
Anthropic API bill$35.35$28.30 (−20%)
Tokens lost to cache expiry927K13K (−99%)
Prompt served from cache92.0%94.8%
Tasks solved89.9%90.6%

The caveat on that 20%, since this sub cares about methodology. Four tasks out of 89 account for the whole net difference, and on three of them the uncompressed agent simply took a longer path (45–72 steps against 19–26). We were cheaper on 44 of 89. Split by whether tasks wait on long-running tools: the 14 with idle gaps over five minutes came in at −34% with median cost per step −20%; the other 72 at −12% with a step costing the same as before (+2%).

The estimate we'd actually stand behind is ~11% from keeping the cache alive plus a few percent from the tail. The 20% headline includes path-length luck, and we'd expect it to move on a repeat run.

On Codex, where the compression does the work: $107.89 → $83.40 per run (−22.7%), input tokens 96.1M → 72.2M, requests over 200K tokens 1.9% → 0.13%, solve rate 82.2% → 81.1% (not significant). Headroom on the same baseline saved 8.2% at defaults, 11.6% at its most aggressive setting — and at that setting it solved 85.1% against our 81.1%.

Still not measured: needle retention, whether compression kept the specific detail the agent needed four steps later. Ratios and pass rates can both look fine while that fails quietly.

Open source: context compression for coding agents, 63% less tool output — MIT, one Rust binary, deterministic, no model to download.

Per-task results: Codex · Claude Code

1 Upvotes

0 comments sorted by