I recently encountered a problem while using Claude Code: after running a few complex tasks, the token consumption was incredibly high. This was especially true in scenarios where a large number of files needed to be read or the code repository had to be searched; several thousand tokens could be used up in just one round of interaction.
I then came across the Headroom project and gave it a try, and it indeed worked effectively.
What it does
Simply put, Headroom acts as a context compression layer. It adds an extra layer between your AI Agent and the LLM, compressing the data before sending it to the model.
Key features:
- Token savings: Official data shows a reduction of 60-95%.
- No impact on accuracy: In benchmark tests like GSM8K and TruthfulQA, the accuracy remains virtually unchanged after compression.
- Local operation: The data is not uploaded to any external services.
- Reversible compression: The original data can be restored when needed by the model.
Actual results
Here are the test results provided by the developers:
| Scenario | Before Compression | After Compression | Savings |
|---|---|---|---|
| Code search (100 results) | 17,765 tokens | 1,408 tokens | 92% |
| SRE troubleshooting | 65,694 tokens | 5,118 tokens | 92% |
| GitHub Issue classification | 54,174 tokens | 14,761 tokens | 73% |
| Code repository exploration | 78,502 tokens | 41,254 tokens | 47% |
I tried it in my own project and noticed a savings of around 50-70%, which isn’t as significant as the official claims, but it’s still a considerable amount.
How to use it
The simplest way to use Headroom is to wrap your Agent with a single command:
# Install Headroom
pip install "headroom-ai[all]"
To wrap Claude Code or Codex:
headroom wrap claude
headroom wrap codex
Alternatively, you can use the proxy mode with no need to modify your code:
headroom proxy --port 8787
The proxy mode is the most convenient; it starts a local proxy server, and you just need to configure your Agent to use this proxy.
Agents supported
Most major programming AI assistants are supported, including:
- Claude Code:
headroom wrap claude - Codex:
headroom wrap codex - Cursor: You can simply print the configuration and paste it.
- Aider: You need to start both the proxy and the assistant.
- Copilot CLI: You need to start both the proxy and the Copilot CLI.
Some notable features:
- Cross-Agent memory sharing: If you use both Claude Code and Codex, Headroom can share the compressed context between them, avoiding duplicate processing of the same content.
- **
headroom learn: This feature analyzes failed sessions, identifies issues, and automatically writes them to files likeCLAUDE.mdorAGENTS.md, allowing the agents to learn from their mistakes. - Content-aware compression: It uses different compression algorithms based on the type of data:
- JSON data → SmartCrusher
- Code → CodeCompressor (AST-aware)
- Text → Kompress-base (a specially trained model)
Who it’s suitable for:
- Developers who use AI programming assistants frequently and have high token consumption.
- Teams that use multiple agents and want to manage them uniformly.
- People who are concerned about data privacy and don’t want to send their code to external services.
Who it’s not suitable for:
- Those who use only one agent and don’t consume many tokens.
- Those in sandbox environments where local processes cannot be run.
Project link: https://github.com/chopratejas/headroom
Headroom has received 14,000 stars and is licensed under the Apache 2.0 license. It supports both Python and TypeScript. If you’re also struggling with high token costs, you might want to give it a try.