Headroom Compresses Agent Tool Calls Before They Burn Tokens

AI coding agents hit context limits fast: JSON tool responses, logs, and file outputs pile up with each turn. Headroom compresses this repetition deterministically before it reaches the LLM, cutting token counts by 20-95% in JSON-heavy workflows—though real-world results vary widely, and prompt-cache invalidation can complicate savings.

Featured Repository Screenshot

By the tenth tool-call turn in an AI coding session, your context window can swell past 100,000 tokens—JSON search results, database rows, file listings, and logs piling up with each round-trip. Headroom attacks that repetition with deterministic compression, stripping redundant keys and duplicate chunks before they reach the LLM. The pitch: compress tool outputs early, save tokens, stay under context limits. The reality is more textured.

The context explosion nobody talks about

Agent workflows stack content fast. A search tool returns twenty JSON objects with identical keys; a RAG retrieval appends five overlapping document chunks; a file-system scan lists hundreds of paths with shared prefixes. Each tool output, log line, and conversation turn flows into the prompt unfiltered, and the weight can push sessions into six-figure token counts. That burns API dollars, slows responses, and sometimes hits hard context ceilings mid-conversation. For teams running long-lived agents or heavy database queries, the cost curve bends steeply upward.

How Headroom attacks repetition

Headroom integrates with Claude Code, Cursor, Codex, and other MCP-compatible hosts through three core tools: compression, retrieval, and session statistics. The compression engine scans tool outputs for repeated JSON keys, redundant log prefixes, and overlapping text blocks, then rewrites them into a shorter representation before the next LLM call. The approach is deterministic—same input yields the same compressed output—which keeps the process predictable and cache-friendly in theory. Developers can query session stats to see how many tokens were saved and retrieve earlier compressed turns when needed.

When compression delivers (and when it doesn't)

The headline numbers promise 60–95% compression in JSON-heavy tasks, but results vary. One issue reports 7–19% compression in production and notes that prompt-cache invalidation can increase total token costs. Another documents Anthropic and Claude Code workloads seeing only 1–4% reduction, with cache hit rates dropping when prior turns are rewritten. Data shape matters: a database query returning fifty rows with twenty shared columns compresses well; a conversational back-and-forth with mostly prose sees minimal gains. One user hit a five-second compression deadline that left a worker running and skipped compression entirely, which points to the latency risk in high-throughput scenarios.

The prompt-cache trade-off

Rewriting earlier turns to insert compressed versions can break prompt-cache hits—the mechanism that makes repeated API calls affordable. A Hacker News thread raised questions about whether Headroom's benchmarks accounted for this offset, calling for cost comparisons that factor in cache behavior. If compression saves five thousand input tokens but invalidates a cached prefix worth twenty thousand, the net result is a bill increase. Headroom's maintainers acknowledge the dilemma; the choice hinges on whether your workload is cache-bound or context-bound.

OptScale's competing approach

OptScale's Terminal-Bench comparison found that its own Kompressor achieved lower cost and fewer input tokens than Headroom, crediting cache-safe deterministic compression as the differentiator. The result highlights an architectural fork: optimize for maximum per-turn compression or preserve cache integrity across turns. Both paths solve the same scaling problem; the best fit depends on your agent's conversation pattern and LLM pricing model.

Who should use Headroom today

Developers running JSON-heavy agents—search APIs, database tools, large RAG retrievals—will see the biggest token reductions. Teams relying on prompt cache for cost control or working with mostly-text workflows should benchmark carefully before committing. Headroom reached v0.43.1 in November 2025 with frequent fixes to CCR, memory, routing, and MCP integrations, signaling active iteration on the growing pains reported in issues. The project is still finding its footing in the fast-moving agent ecosystem, and the compression numbers will keep evolving as workloads diversify. For now, it's a tool for a real problem—just measure twice before deploying at scale.


headroomlabs-aiHE

headroomlabs-ai/headroom

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

78.9kstars
6.2kforks
agent
ai
anthropic
claude-code
compression