# Repository Briefing: headroomlabs-ai/headroom
> Source: https://repoforai.com/repo/headroomlabs-ai/headroom (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/headroomlabs-ai/headroom
- **Official Docs / Website**: https://docs.headroomlabs.ai/docs
- **Category**: Coding, Skills & MCP (AI 编程 / Skills / MCP)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: A+ (96/100 · Maintenance 35/35 · Adoption 21/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v0.45.0 (2026-11-22) — https://github.com/headroomlabs-ai/headroom/releases
- **Review Snapshot**: 2026-12-02
- **Deployment / Stack Signals**: Docker, Self-Hosted, Local AI, CLI, MCP, API
- **Momentum**: 81,468 ★ total (+43 24h / +455 7d) · 6,426 forks
- **Topics**: `agent`, `ai`, `anthropic`, `claude-code`, `compression`, `context-engineering`, `context-window`, `cursor`, `fastapi`, `langchain`, `llm`, `mcp`
- **When to Use**: Best for: 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. Skip if: 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.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Content-aware compression: SmartCrusher handles JSON, CodeCompressor uses ASTs for source, and Kompress-v2-base provides a prose path.
- Original recovery: CCR exposes retained originals through `headroom_retrieve` within the configured TTL.
- Cache diagnostics: CacheAligner flags volatile content that can invalidate a provider’s cached prefix without rewriting prompts.
- Reproducible measurements: Seeded offline tests using default `compress()` settings show 21–57% fewer input tokens across four scenarios.
- Integration boundaries: Python can run in-process, TypeScript calls the proxy, and MCP clients get explicit compress, retrieve, and stats tools.
- Output controls: Opt-in verbosity steering supports Anthropic Messages and OpenAI-compatible Chat Completions and Responses; a conversation holdout separates measured savings from modeled estimates.
```

## Quick Start / Clone
```bash
pip install headroom-ai
```
