headroomlabs-ai/headroom
Local context compression for LLMs via a Python library, proxy, and MCP server
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
Headroom preprocesses LLM messages through an in-process Python library, a request proxy, or callable MCP tools. ContentRouter dispatches JSON to SmartCrusher, source code to the AST-based CodeCompressor, and eligible prose to a Kompress-v2-base path. CacheAligner flags volatile content that could break a provider’s cached prefix without rewriting it. CCR retains originals locally so the model can recover details through headroom_retrieve rather than requiring every request to carry the full payload.
The headroom-ai Python package requires Python 3.11 or newer and uses Maturin to build the PyO3 extension. The Cargo workspace separates headroom-core, headroom-proxy, the Python bindings, and simulator and parity crates. The npm package is a TypeScript SDK that calls the proxy, not a standalone compressor or CLI. MCP exposes headroom_compress, headroom_retrieve, and headroom_stats as explicit tools rather than transparently intercepting traffic.
Key Capabilities & Differentiators
The default library path compresses tool and assistant messages while leaving user messages untouched unless compress_user_messages=True is set. Wrapped agents include Claude Code and Codex; Cursor uses manual proxy configuration. Optional output shaping adds verbosity guidance to the system prompt for Anthropic /v1/messages and OpenAI-compatible /v1/chat/completions and /v1/responses. Cross-agent memory and headroom learn address different needs: sharing context across supported agents and turning lessons from failed sessions into editable instruction files.
Seeded offline tests using provider tokenizers and default compress() settings reduced input tokens by 21% for code search, 57% for SRE incident debugging, 42% for codebase exploration, and 30% for GitHub issue triage. Repeated JSON arrays and log lines exceeded 90% in separate benchmarks. Those results describe payloads, not production cost or answer quality. The 100-example GSM8K test matched baseline at 0.870, and the TruthfulQA difference was within the reported confidence interval. Output savings are a separate metric: HEADROOM_OUTPUT_HOLDOUT=0.1 reserves unshaped conversations as a control instead of relying on a modeled baseline.
Trade-offs & Limitations
The strongest case for Headroom over direct provider calls is a workload dominated by repeated structured tool output. Compared with provider-native compaction, it offers preprocessing across supported clients and a way to recover originals; it also adds another component that can affect request routing, task quality, and latency. CCR only makes compression reversible while the original is retained and the agent can use the retrieval tool. Short prompts and dense prose leave little room for savings. Validate task success and retrieval frequency before rolling it out on correctness-sensitive workflows.
In-process compression minimizes operational dependencies, while the proxy is useful when you do not control the client or want shared memory. A reported 0.21 ms p50 for a 10K-token JSON result is a compression microbenchmark, not end-to-end proxy latency or a result for prose inference. Measure upstream cache behavior along with token usage. On a reused shared proxy, runtime overrides synced by headroom wrap are global and the last explicit setting wins; teams needing different output policies should not assume those settings are isolated by session.
Hardware & Deployment Guide
For an application you control, start with pip install headroom-ai and call compress() before the provider SDK. The basic path needs neither a Headroom API key nor a model download; HEADROOM_OFFLINE=1 keeps compression offline, not the downstream provider call. For agents, uv tool install --python 3.13 "headroom-ai[all]" provides the CLI. headroom wrap claude runs a session-scoped proxy, while headroom deploy is the persistent local option. Set --openai-api-url or OPENAI_TARGET_API_URL for a third-party OpenAI-compatible upstream; wrapping otherwise defaults that traffic to OpenAI.
For Docker, run the proxy alone if semantic memory is unnecessary. The Compose stack adds Qdrant and Neo4j; set real NEO4J_AUTH credentials before non-local use. The standalone example publishes port 8787 only on host loopback and explicitly acknowledges the unauthenticated container bind; do not reuse that configuration for a remotely exposed service. Release v0.44.0 stopped including PyTorch extras in [all], so do not assume that install includes them. v0.45.0 added repeatable --extra-model flags for OpenCode wrapping. Size the runtime against payload mix, concurrency, and retained data, and assess optional prose inference separately.
headroom_retrieve within the configured TTL.compress() settings show 21–57% fewer input tokens across four scenarios.Coding agents and LLM applications where repeated JSON tool results, logs, or search hits dominate input tokens, especially when you need recoverable originals or a common preprocessing layer across clients.
Most requests are short or prose-heavy, provider-native compaction already meets your needs, or you cannot accept either temporary retention of originals or the risk of losing detail when retrieval is unavailable.
Quick Start & Installation
pip install headroom-aiComparison vs. Top Coding, Skills & MCP Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| headroom ★ | 81.5k | +455 | Python | Apache-2.0 | Local context compression for LLMs via a Python library, proxy, and MCP server |
| agents | 43.2k | +212 | Python | MIT | One Markdown plugin catalog adapted to seven AI coding tools |
| graphify | 156.8k | +2.4k | Python | Apache-2.0 | Local AST graphs for dependency tracing, with CLI and MCP access. |
| oh-my-pi | 40.5k | +483 | TypeScript | MIT | A Bun/Rust terminal agent for model-flexible coding with LSP and editor integrat |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/headroomlabs-ai/headroom.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about headroom
Should I integrate the library, proxy, or MCP server?
compress(messages, model=…) when you own the message-building code. For TypeScript, the npm SDK sends messages to a running Headroom proxy; it does not ship the CLI. For a supported coding agent, headroom wrap starts and configures the proxy for the session. An MCP client can call headroom_compress, headroom_retrieve, and headroom_stats explicitly; installing those tools is not the same as routing every model request through the proxy.Do I need a GPU, and what should I size for?
Can we self-host it commercially, and what data-handling rules still apply?
When is Headroom preferable to provider-native compaction?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy