Overview
Headroom compresses everything an AI agent reads — tool outputs, logs, RAG chunks, files, and conversation history — before it reaches the LLM, delivering the same answers for a fraction of the tokens. Compression runs entirely on your machine; no prompt or file content is sent anywhere. It works as an inline library, a zero-code-change proxy, an agent wrapper, or an MCP server.
Key Features
- Library mode:
compress(messages)in Python or TypeScript, inline in any application - Proxy mode:
headroom proxy --port 8787with zero code changes, any language - Agent wrap: one command wraps claude, codex, grok, copilot, cursor, aider, opencode, cline, and more; undo with
headroom unwrap - MCP server exposing
headroom_compress,headroom_retrieve, andheadroom_statsto any MCP client - Cross-agent memory: one shared store across Claude, Codex, Gemini, and Grok with automatic dedup
- Reversible compression (CCR): originals are cached locally and retrieved on demand; output token reduction also trims what the model writes back
Use Cases
- Cut token spend of coding agents without changing their prompts or workflows
- Shrink huge JSON tool outputs and log dumps before they hit the context window while keeping critical lines discoverable
- Share compressed memory and learned corrections across multiple agents on the same machine
Technical Details
- Pipeline is CacheAligner → ContentRouter → CCR: ContentRouter detects the content type and dispatches to SmartCrusher (JSON), CodeCompressor (AST-based), or the Kompress-v2-base text model hosted on Hugging Face
- CCR caches the original text locally so the model can call
headroom_retrieveto fetch the uncompressed version exactly when it needs it - CacheAligner flags volatile content that would bust a provider's KV-cache prefix but never rewrites prompts, preserving prompt-cache hit rates
headroom wrap <agent>starts a local proxy, installs the Serena MCP server for semantic code navigation, and launches the agent configured to route through Headroom;headroom learnmines failed sessions and writes corrections to CLAUDE.md, AGENTS.md, GEMINI.md, or GROK.md
