Repo Dev Tools

headroomlabs-ai/headroom

Local compression layer for AI agents: shrinks tool outputs, logs, JSON, RAG chunks and files before they reach the LLM, via library, proxy, agent wrapper or MCP server.

  • 80.8k GitHub stars
  • Python
  • ⚖️ Apache-2.0
  • 🎯 Intermediate

Last verified: repo last pushed

headroomlabs-ai/headroom preview image

What it is

Headroom compresses what an AI agent reads (tool outputs, logs, RAG chunks, files, conversation history) before it reaches the LLM. Compression runs on your machine. It routes content to compressors for JSON, code (AST) and text, and caches originals locally so the model can retrieve them on demand (CCR). It is available as a Python/TypeScript library, a proxy, one-command agent wrappers and an MCP server.

Who it's for

  • Developers who run coding agents daily and want token savings without changing their code
  • Teams using several agents (Claude, Codex, Gemini, Grok) who want one shared memory store
  • Users who need reversible compression with retrievable originals
  • Python and TypeScript app builders who want inline compression in LangChain, LiteLLM, Vercel AI SDK, Agno and similar stacks

Requirements

Requirements

  • Python 3.10+
  • The headroom CLI ships only in the PyPI package; the npm headroom-ai package is the TypeScript SDK and has no CLI
  • Ability to run local processes (not suited to sandboxes where they can't run)
  • Optional: C++ toolchain for the [vector] extra

Setup

  1. Install

    Install the CLI in an isolated env, via pip, or the TypeScript SDK (library only).

    bash
    uv tool install --python 3.13 "headroom-ai[all]"  # CLI in a self-contained env
    pip install "headroom-ai[all]"                    # Python — ships the `headroom` CLI
    npm install headroom-ai                           # TypeScript SDK only — no CLI
  2. Pick a mode

    Deploy locally, wrap a coding agent, or run a drop-in proxy.

    bash
    headroom deploy                         # turnkey local deployment + agent config
    headroom wrap claude                    # wrap a coding agent
    headroom proxy --port 8787              # drop-in proxy, zero code changes
  3. Check health and savings

    Verify routing and watch savings (the proxy must be running for the dashboard).

    bash
    headroom doctor                         # health check — confirms routing works
    headroom perf
    headroom dashboard                      # live savings (proxy must be running)

Examples

Inline compression in Python

python
python
from headroom import compress
from openai import OpenAI

messages = [{"role": "user", "content": "Analyze these results"}]
result = compress(messages, model="gpt-4o")

client = OpenAI()
response = client.chat.completions.create(model="gpt-4o", messages=result.messages)
print(f"Saved {result.tokens_saved} tokens ({result.compression_ratio:.0%})")

What it does: Compresses messages before sending them to an OpenAI client and prints the tokens saved.

Enable output token reduction on the proxy

bash
bash
export HEADROOM_OUTPUT_SHAPER=1     # off by default
headroom proxy --port 8787

What it does: Turns on verbosity steering and effort routing so the model writes fewer tokens back.

Learn a terseness level from past sessions

bash
bash
headroom learn --verbosity            # dry run — preview what it found
headroom learn --verbosity --apply    # save it and apply it to the running proxy

What it does: Reads past sessions to pick a verbosity level, with a dry run before applying.

Configure an MCP client with an absolute path

toml
toml
[mcp_servers.headroom]
command = "/Users/you/.local/bin/headroom"
args = ["mcp", "serve"]

What it does: MCP clients like Codex often can't inherit the shell PATH, so use the absolute path from command -v headroom.

Pros & cons

Pros

  • Pro:Runs locally; no prompt or file content is sent anywhere to be compressed
  • Pro:Many integration paths: library, proxy, one-command wrapping for many agents, MCP server
  • Pro:Reversible via CCR; the model can retrieve originals on demand
  • Pro:Reported accuracy parity on GSM8K and TruthfulQA at N=100, with sub-millisecond compression overhead

Cons

  • Con:Savings depend on the payload: prose, short conversations and already-dense output see little or no reduction
  • Con:Cursor needs manual setup and Cortex Code is library-only with no wrap
  • Con:Output-token savings are counterfactual estimates unless you configure a holdout

Images