headroom

headroomlabs-aiApache-2.0活跃维护 有专家点评

在工具输出、日志、文件和 RAG 片段进入 LLM 前先做压缩,编码 Agent 省约 20% token,JSON 省 60-95%,答案不变。提供库、代理和 MCP 服务器三种用法。

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

v0.44.0发布于 2026-11-10 01:58 UTC79,314star +269 / 7 天6,199fork同步于 2026-11-10 23:19 UTC

专家点评

上手难度:进阶更新于 2026-11-11

在工具输出和 RAG 片段进上下文窗口前做无损压缩,顶替手写截断和摘要逻辑

适用场景

  • 编码 agent 跑长会话:工具输出和日志占满上下文时,用 headroom wrap claude 包一层比自己在 agent 里写截断规则省事,且原文留在本地缓存可回取
  • RAG 检索后、拼 prompt 前:JSON 和结构化 chunk 的压缩比明显高于纯文本,检索结果以表格/JSON 为主时收益最大,纯自然语言段落收益会小很多
  • 多轮对话的 KV 缓存维护:CacheAligner 只做标记不改写提示词,适合已经吃前缀缓存折扣、又不想让压缩破坏缓存命中的部署
  • 离线批量跑评测:作为库直接调用压缩器,不经过代理,避免代理层引入的额外故障面

踩坑

  • 在 x86 上跑:Magika 内容检测和 embedding 相关性依赖 AVX2,不支持的机器会静默回退到 BM25 和启发式,压缩质量和内容分类都会退化,而 README 不会在运行时提醒你
  • 装 [all] 时:LangChain、Agno、Strands 适配器不在里面,要单独装 extra;[ml]、[memory] 在 Linux 上可能把 CUDA 运行时包一起拉进来,纯 CPU 环境要留意依赖体积
  • 接 MCP 客户端时:客户端常不继承 shell PATH,必须配 command -v headroom 的绝对路径,否则表现为 MCP server 起不来而不是报错

同类对比

如果只需要对纯文本做摘要式压缩、不要求答案不变,直接用模型侧摘要更简单;如果问题只是上下文超长而非 token 成本,优先考虑检索侧改造而不是加一层压缩代理。

怎么上手

由 README 提炼,执行前请确认
pip install headroom-ai
uv tool install --python 3.13 "headroom-ai[all]"
headroom wrap claude
硬件要求按 README 说明

README 未说明显存要求;压缩在本地运行,无需 API key 和模型下载。x86/x86_64 上 ONNX 相关特性(Magika 内容检测、embedding 相关性)需要 AVX2,不支持时回退到 BM25 与启发式检测;arm64 和 Apple Silicon 无需 AVX2。原生 wheel 覆盖 macOS Apple Silicon 和 Linux,Intel macOS 需用 Docker 安装。

支持 Apple Silicon需要 CUDA有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

在内容进入 LLM 前压缩工具输出、日志、文件和 RAG 片段,答案不变而 token 更少

在工具输出、日志、文件和 RAG 片段进入 LLM 前先做压缩,编码 Agent 省约 20% token,JSON 省 60-95%,答案不变。提供库、代理和 MCP 服务器三种用法。

核心能力

  • 用 ContentRouter 识别内容类型并分派到对应压缩器
  • SmartCrusher 压缩 JSON、CodeCompressor 按 AST 压缩代码、Kompress-v2-base 压缩文本
  • CacheAligner 标记会破坏 KV 缓存前缀的易变内容且不改写提示词
  • CCR 本地缓存原文,模型可按需调用 headroom_retrieve 取回
  • 提供库、代理、MCP server 和 headroom wrap 一键包装编码 agent

容易踩的坑

需要 Python 3.11+,且 [all] 不含 LangChain、Agno、Strands 等框架适配器,需单独安装对应 extra;[ml]、[memory] 等 extra 的 PyTorch 依赖在 Linux 上可能装入 CUDA 运行时包;MCP 客户端常无法继承 shell PATH,需配置 command -v headroom 的绝对路径;企业 SSL 检查环境下安装可能因 maturin 拉取 rustup 报 CERTIFICATE_VERIFY_FAILED,需先装 Rust 或改用预编译 wheel。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.44.0
  1. v0.44.0Release v0.44.0最新正式版2026-11-10 · 2026-11-10 01:58 UTC

    0.44.0 (2026-11-09)

    ⚠ BREAKING CHANGES

    • packaging: keep PyTorch extras out of all (#4067)

    Features

    • pipeline: say whose request an OutcomeSnapshot is (#4698) (a2bcbd1)
    • providers: add Hermes agent wrap support (#934) (7877241)
    • proxy/model-router: add shadow mode (HEADROOM_MODEL_ROUTER_LOG_ONLY) (#2395) (861ef95)
    • proxy: add lossless /v1/compress mode and detect provider by wire shape (#4617) (33f067a)
    • proxy: expose per-request cost_usd in /stats recent_requests (#1079) (#1565) (84cedbf)
    • proxy: expose shared Redis store availability in /health and /metrics (#4578) (602ca65)
    • proxy: give turn hooks one conversation id per client conversation (#4496) (94a99ed)
    • proxy: report DeepSeek as its own provider in dashboard (#2565) (9ad16a7)
    • proxy: show per-request /stats metadata to token-authenticated callers (#4168) (9b2dec5)
    • proxy: unified multi-upstream routing for Anthropic Cloud and local oMLX (#4597) (f896161)
    • savings: carry cumulative actual output_tokens in history checkpoints (#2921) (8388ff5)
    • wrap: add headroom wrap droid for Factory Droid (#4143) (bb8d18a)
    • wrap: make the Serena code-memory MCP opt-in (#4509) (2649835)

    Bug Fixes

    • asgi: stop buffering when the client disconnects (GHSA-mc2f-vg4v-2fh4) (#4701) (c6d7081)
    • beacon: enforce the allowlist below the top-level keys (#4691) (456288d)
    • binaries: fail closed on HEADROOM_BINARIES_ALLOW_UNVERIFIED=0/false (
  2. v0.43.1Release v0.43.12026-11-05 · 2026-11-05 19:34 UTC
    查看更新说明

    0.43.1 (2026-11-05)

    Bug Fixes

    • ccr: keep the in-memory order queue from evicting re-stored entries (#4545) (c6f5bf9)
    • memory: read the relation key the memory_save schema advertises (#4647) (7592e68)
    • memory: replace the HNSW vector when a memory is re-indexed (#4649) (ee638f9)
    • openclaw: accept 12-character hashes in headroom_retrieve (#4640) (8d3e9e5)
    • ort: avoid implicit runtime discovery from the workspace (#4570) (69fbd23)
    • proxy: bound the model-keyed tokenizer, beacon and litellm caches (#4497) (e51b806)
    • proxy: use HTTP/1.1 client for ChatGPT streaming and model metadata (#4006) (e1becdf)
    • release: normalize damaged release PR envelopes before detection (#4664) (917edc6)
    • router: keep tagged blocks out of the lossy size-gate fallback (#4543) (f333edf)
    • router: log the ONNX fallbacks at info instead of warning (#4535) (db30d82)

    Dependencies

    • bump the npm-minor-patch group across 3 directories with 6 updates (#4662) (8f104f8)

    Want more savings? Headroom Enterprise saves more for teams and enterprises. Talk to us at [email protected] or headroomlabs.ai.

  3. v0.43.0Release v0.43.02026-11-05 · 2026-11-05 18:36 UTC
    查看更新说明

    0.43.0 (2026-11-05)

    ⚠ BREAKING CHANGES

    • mcp: port MCP servers to SDK 2.x (#4603)

    Features

    • ccr: answer headroom_retrieve on streaming chat completions (#4631) (31dcaf4)
    • mcp: port MCP servers to SDK 2.x (#4603) (ee2252a)
    • plugins: headroom skill for Claude Code, Codex, Copilot and skills.sh (#4533) (66e1467)
    • savings: show the proxy's model-routing savings in headroom savings (#4304) (aaab338)

    Bug Fixes

    • [BUG] A timeout in one image compression call resets the shared worker pool and affects concurrent requests (#4528) (e9bcfe7)
    • [BUG] DirectMem0Adapter.search_memories calls removed mem0 search API (#4518) (d9cee45)
    • [BUG] Saved request metrics lose their cache optimization fields (#4584) (b4c9bdf)
    • [BUG] Volatile SQLite metrics stores lose their schema before the first save (#4633) (d8ff0fe)
    • Add info about apply to README.md (#1592) (4d34680)
    • backends/litellm: keep cache_control on text blocks for Bedrock prompt caching (#4565) (23a5bb1)
    • backends: forward the standard service_tier param (litellm + anyllm) (#2468) (62cc38a)
    • cache: build semantic entry before evicting so a failed embedding keeps live entries (#4581) (0d4c450)
    • cache: count a tool_result with no text as replayable in the frozen prefix (#4523) (fba09f6)
    • cache: fail closed on SQLite corruption instead of deleting the store online (#4361) (9801833)
    • cache: invalidate configured registry instances on replacement (#4363) (1bcdca2)
    • cache: namespace SemanticCacheLayer by provider, mo
  4. v0.42.0Release v0.42.02026-10-26 · 2026-10-26 23:03 UTC
    查看更新说明

    0.42.0 (2026-10-26)

    Features

    • pipeline: put per-request saved tokens on OutcomeSnapshot (#4231) (8cedf7b)
    • proxy: let turn hooks rewrite OpenAI Responses requests on HTTP and WebSocket (#4232) (fbf7bc3)
    • proxy: report the same tool savings on gateway /v1/compress as the proxy path (#4467) (a904210)
    • savings: add the per-request counterfactual savings record (#4236) (2912b7b)

    Bug Fixes

    • batch: preserve live contexts during capacity cleanup (#4210) (2cbdd22)
    • batch: preserve native Gemini continuation tools (#4211) (8757458)
    • cache: bound the router's compression cache, keep the rest in SQLite (#4357) (b196424)
    • cache: keep indented lines intact in OpenAI whitespace normalization (#4343) (2480100)
    • cache: keep prefix-tracker state across a graceful proxy restart (#4299) (62b3bed)
    • ccr: recognize client-owned MCP retrieval aliases (#4165) (89545fb)
    • ccr: stream the buffered CCR upstream request so idle-killing networks cannot cut it (#4206) (ca6ba34)
    • ci: pin checkout in release notification smoke workflow (#4399) (70273db)
    • copilot: detect COPILOT_API_URL in cli-main.js for Copilot CLI >= 1.0.93 (#4450) (043fe09)
    • copilot: preserve native inline OAuth identity (#4144) (ad62166)
    • deps: bump rustls to 0.23.46 for RUSTSEC-2026-0346..0349 (#4222) (132dbc7)
    • deps: patch OpenClaw Undici and narrow E2E audit exceptions (#4453) (1be699f)
    • deps: r
  5. v0.41.0Release v0.41.02026-10-14 · 2026-10-14 22:46 UTC
    查看更新说明

    0.41.0 (2026-10-13)

    Features

    • antigravity: add native Google Antigravity IDE integration (#3817) (cd4367b)
    • opencode: support the OpenCode 2.x plugin API (#3999) (1d4b357)
    • plugins: add headroom-snip Claude Code mod that animates compression (#3980) (17abee2)
    • proxy: native spend/savings stats + dashboard for the Rust proxy (#2321) (70b21c1)
    • router: add max_output_tokens condition to ModelRoute (#3898) (01185e3)
    • savings: per-agent attribution in history checkpoints and rollups (#2627) (489de46)
    • show the Headroom for Teams offer in the dashboard, docs, llms.txt and release notes (#3991) (1ad92f0)

    Bug Fixes

    • anthropic: route /api/hello connectivity probes to Anthropic (#3336) (#4059) (931e5b9)
    • beacon: stop Cloudflare logging senders' IP addresses (#4018) (db983ba)
    • cache: keep cache mode when Claude Code re-serializes its last reply (#4003) (aeb09f8)
    • cache: retain prefix trackers for the provider cache lifetime (#4023) (9553d42)
    • cache: stop Claude Code forks from cold-starting the conversation's lineage (#4043) (1cf4d05)
    • ccr: serve headroom_retrieve when the model calls it alongside client tools (#4034) (01d9194)
    • cli: name the broken Codex config, write init configs atomically, keep the identity check (#4129) (976aa71)
    • cli: pass configured SSL context to stdlib urlopen calls (#4011) (22d0905)
    • cli: say why the proxy failed to start (#4120) ([f3d240b](https://github.com/headroo

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    AI agents / LLMs: read /llms.txt here, or fetch the live index · full docs blob.

    Headroom (headroom-ai on PyPI and npm) compresses everything your AI agent reads — tool outputs, logs, RAG chunks, files, and conversation history — before it reaches the LLM. Same answers, fewer input tokens. Measured: 21–57% fewer input tokens on four agent scenarios, 90%+ on repeated JSON arrays and log lines, little on prose (Proof). Compression runs on your machine; no prompt or file content is sent anywhere to be compressed.

    Start here

    My app calls an LLM (Python, LangChain, LiteLLM, Agno, Strands):

    pip install headroom-ai
    
    from headroom import compress
    
    result = compress(messages, model="gpt-4o")  # OpenAI or Anthropic message dicts
    client.chat.completions.create(model="gpt-4o", messages=result.messages)
    

    No API key, no model download, in-process. Set HEADROOM_OFFLINE=1 for a zero-network run. Tool and assistant messages are compressed; user messages are left alone unless you pass compress_user_messages=True. FastAPI example · API reference. TypeScript apps: npm install headroom-ai plus the proxy (pip install "headroom-ai[proxy]", headroom proxy --port 8787); the npm SDK sends messages to it. TypeScript quickstart

    I run coding agents (Claude Code, Codex, Cursor, Copilot, OpenCode, Aider):

    uv tool install --python 3.13 "headroom-ai[all]"
    headroom wrap claude
    

    Zero code changes. Agent compatibility · Proxy

    What it does

    • Library — compress(messages) in Python or TypeScript, inline in any app.
    • Proxy — headroom proxy --port 8787, zero code changes, any language.
    • Agent wrap — headroom wrap claude|codex|grok|copilot|cursor|aider|opencode|cline|continue|goose|openhands|openclaw|vibe|omp|droid|zcode in one command; undo with headroom unwrap <tool>.
    • MCP server — headroom_compress, headroom_retrieve, headroom_stats for any MCP client.
    • Cross-agent memory — one shared store across Claude, Codex, Gemini and Grok, with automatic dedup.
    • headroom learn — mines failed sessions and writes corrections to CLAUDE.local.md (default, gitignored), CLAUDE.md, AGENTS.md, GEMINI.md or GROK.md.
    • Output token reduction — trims what the model writes back, not only what you send. See below.
    • Reversible (CCR) — originals are cached locally and retrieved on demand.

    How it works

     Your agent / app
       (Claude Code, Cursor, Codex, LangChain, Agno, Strands, your own code…)
            │   prompts · tool outputs · logs · RAG results · files
            ▼
        ┌────────────────────────────────────────────────────┐
        │  Headroom   (runs locally — your data stays here)  │
        │  ────────────────────────────────────────────────  │
        │  CacheAligner  →  ContentRouter  →  CCR            │
        │                    ├─ SmartCrusher   (JSON)        │
        │                    ├─ CodeCompressor (AST)         │
        │                    └─ Kompress-v2-base (text, HF)  │
        │                                                    │
        │  Cross-agent memory  ·  headroom learn  ·  MCP     │
        └────────────────────────────────────────────────────┘
            │   compressed prompt  +  retrieval tool
            ▼
     LLM provider  (Anthropic · OpenAI · Bedrock · …)
    
    • ContentRouter detects the content type and selects a compressor for it.
    • SmartCrusher / CodeCompressor / Kompress-v2-base handle JSON, source code and prose respectively.
    • CacheAligner flags volatile content that would bust a provider KV-cache prefix. It never rewrites prompts.
    • CCR stores originals locally so the model can call headroom_retrieve when it needs the full text.

    → Architecture · CCR · Kompress-v2-base model card

    Get started (60 seconds)

    # 1 — Install
    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
    headroom deploy                         # turnkey local deployment + agent config
    headroom wrap claude                    # wrap a coding agent
    headroom proxy --port 8787              # drop-in proxy, zero code changes
    # or: from headroom import compress     # inline library
    
    # 3 — Check it and watch the savings
    headroom doctor                         # health check — confirms routing works
    headroom perf
    headroom dashboard                      # live savings (proxy must be running)
    

    Reduce input tokens in your own app

    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%})")
    

    Launch a wrapped agent session each time, so the setup runs. headroom wrap starts a local proxy, installs Serena for semantic code navigation, and launches the agent configured to route through Headroom. For Claude Code, Serena is registered for the wrapped project only (as a local-scope MCP server in ~/.claude.json). Use --code-memory-scope user to make it available in every project, or --code-memory none to skip it. headroom unwrap removes either registration.

    headroom wrap ... is session-scoped: its proxy exits with the wrapped agent. For a proxy that survives reboots, use the turnkey headroom deploy command. Use headroom install apply when you need to choose a specific persistent service, scheduled task, Docker runtime, scope, or provider target; see the persistent installs guide.

    The headroom CLI ships only in the PyPI package. The npm headroom-ai package is the TypeScript SDK — a library you import (import { compress } from 'headroom-ai') — and provides no headroom command.

    Proof: measured token savings

    Four scenarios built from real MCP server output formats, measured with the provider tokenizer and the shipped compress(). Seeded and offline, so you get the same numbers we did:

    uv run python benchmarks/index_proof_table.py --seed 20260902
    
    ScenarioBeforeAfterSaved
    Code search (100 results)17,19913,59721%
    SRE incident debugging55,95724,34057%
    Codebase exploration58,80133,89542%
    GitHub issue triage46,06732,42930%

    Savings scale with how repetitive the payload is. Repeated JSON arrays and log lines clear 90% in benchmarks/bench_latency.py; prose and already-dense output compress very little. Run headroom savings against your own traffic for the number that applies to you.

    Compression costs well under a millisecond — 0.21 ms p50 on a 10K-token JSON search result, 1.4 ms at 100K tokens — so it does not show up in agent latency.

    Accuracy. python -m headroom.evals suite --tier 1:

    BenchmarkCategoryNBaselineHeadroomDelta
    GSM8KMath1000.8700.870±0.000
    TruthfulQAFactual1000.5300.560+0.030
    SQuAD v2QA100—97%at 19% compression
    BFCLTools100—97%at 32% compression

    At N=100 a delta of ±0.03 falls inside the confidence interval, so TruthfulQA shows no detectable difference rather than an improvement. Methodology →

    Output token reduction

    Everything above shrinks the prompt you send. You also pay for every token the model writes back, and on Opus-class models output costs 5× input. Much of that output is ceremony: "Great, let me…" preambles, code re-printed straight back at you, and deep reasoning spent on routine steps like reading a file.

    Headroom trims it from the proxy, with no change to your code:

    • Verbosity steering appends a short "be terse, don't restate context" note to the end of the system prompt, so your prompt cache still hits.

    It applies to Anthropic /v1/messages and to OpenAI-compatible /v1/chat/completions and /v1/responses, with the same output_shaper:* labels on all paths.

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

    Already running a proxy? These switches are read live on every request, so a proxy that headroom wrap reused rather than started would not see a value you export afterwards — its environment was snapshotted at launch. headroom wrap hot-syncs your current settings to the running proxy over a loopback POST /admin/runtime-env, so they take effect with no restart and no dropped requests. On a shared proxy these overrides are global; the last explicit setting wins.

    Terseness you didn't have to configure. People rarely state how terse they want answers — they show it, by interrupting long replies or moving on before they could have read them. headroom learn --verbosity reads past sessions and picks the level:

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

    A proxy in cache mode (the default) never re-reads the learned level, because a level that changes mid-conversation would bust the prompt cache. There --apply pins it with HEADROOM_VERBOSITY_LEVEL; set that variable yourself to keep it after a restart.

    Measuring it. Output savings are counterfactual — we never see what the model would have written — so Headroom reports an estimate with a confidence range and labels it as one:

    headroom output-savings
    # Reduction: 31.7%  (95% CI 27.7% … 35.7%)   [estimated]
    

    For a measured number instead, hold out 10% of conversations as an unshaped control: export HEADROOM_OUTPUT_HOLDOUT=0.1. The dashboard's Output Tokens Saved card then reads measured rather than estimated, with the band.

    → Output token reduction

    Agent compatibility

    Agentheadroom wrapNotes
    Claude Code✅--memory · --code-graph · --1m · --tool-search
    Codex✅shares memory with Claude
    Grok CLI✅routes via GROK_MODELS_BASE_URL
    CursorManual setupstarts the proxy and prints base URLs for Cursor settings
    Aider✅starts proxy + launches
    Copilot CLI✅starts proxy + launches
    VS Code Copilot✅transparent proxy; keeps the selected model
    OpenClaw✅installs as a ContextEngine plugin
    OpenCode✅injects config · starts proxy + launches 1
    Cline✅starts proxy + injects config
    Continue✅starts proxy + injects config
    Goose✅starts proxy + launches
    OpenHands✅starts proxy + launches
    Mistral Vibe✅starts proxy + launches
    Oh My Pi✅Anthropic + OpenAI/Codex · injects config · starts proxy + launches
    Factory Droid✅routes via FACTORY_API_BASE_URL; Anthropic-model turns compressed, other Factory traffic passed through
    Cortex CodeLibrary only60–65% savings in library mode; no wrap
    Kimi CLI✅OAuth bearer forwarded — log in once
    ZCode✅starts the proxy and prints base URLs for ZCode settings

    Any OpenAI-compatible client works through headroom proxy. MCP-native clients: headroom mcp install. Undo durable wrapping with headroom unwrap <tool> (claude, copilot, codex, grok, kimi, omp, opencode, openclaw, zcode). Registry authors should use the canonical server.json rather than reconstructing the headroom mcp serve contract from prose.

    For Anthropic /v1/messages, --mode cache skips automatic --memory context injection so the provider prefix remains stable. OpenAI chat/responses and Gemini append memory to the live-zone tail. Use --mode token when you need automatic memory context on the Anthropic path.

    Headroom can route Copilot CLI subscription traffic through the local proxy:

    headroom copilot-auth login
    headroom wrap copilot --subscription -- --model gpt-4o
    

    The wrapper exchanges Headroom's reusable GitHub OAuth token for Copilot's short-lived API token and prints the upstream endpoint as COPILOT_PROVIDER_API_URL=... at launch. headroom copilot-auth login stores a Headroom-specific Copilot OAuth token, rather than relying on generic GitHub or Copilot CLI tokens that can read account metadata but are still rejected by Copilot's token-exchange endpoint.

    For GitHub Enterprise Server or a custom-domain Copilot deployment, set one of these before launching. If both are set, the URL wins:

    export GITHUB_COPILOT_ENTERPRISE_DOMAIN=ghe.example.com
    export GITHUB_COPILOT_ENTERPRISE_URL=https://ghe.example.com
    

    For GitHub.com Enterprise Cloud URLs such as github.com/enterprises/your-enterprise, set neither — Headroom uses GitHub's normal token-exchange endpoint and the Copilot API endpoint advertised for the signed-in account.

    Platform support. macOS auth reuse through Copilot CLI Keychain storage and Windows device authentication are live-tested. Copilot CLI 1.0.81 does not expose its Windows login through the legacy Credential Manager schema Headroom reads, so run headroom copilot-auth login on Windows. Linux Secret Service / secret-tool reuse is implemented but not yet validated on a real desktop. In Docker and CI, pass an explicit GITHUB_COPILOT_TOKEN or GITHUB_COPILOT_GITHUB_TOKEN instead of relying on host keychain access.

    Headroom overrides Copilot's API proxy endpoint, so the VS Code model picker stays authoritative. GPT-5.5, GPT-5.6 Luna/Sol/Terra, Claude Sonnet/Opus and other Copilot models keep their original model IDs while traffic passes through the local compression proxy. Headroom does not patch VS Code or change Codex settings.

    headroom copilot-auth login
    headroom wrap vscode
    

    Keep the command running and use Copilot normally. The short-lived upstream Copilot token is held only in the proxy process. Full guide →

    The official Claude Code extension embeds Claude Code and reads the same user settings as the CLI. Install the proxy extra, then run the wrapper from the project you will open in VS Code:

    pip install "headroom-ai[proxy]"
    headroom wrap vscode-claude
    # Optional: persist Claude Code's client-owned 1M model selector
    headroom wrap vscode-claude --1m
    

    Reload the VS Code window on first run. Keep the wrapper terminal running while you use the Claude Code panel; the dashboard or proxy log printed at startup shows requests and savings. Your Anthropic authentication and selected model are preserved. Ctrl+C stops the proxy; headroom unwrap vscode-claude restores the settings that existed before setup.

    With --1m, Headroom writes the resolved [1m] model selector to Claude Code's top-level user setting and restores the exact prior model on headroom unwrap vscode-claude or when setup runs again without --1m. Use headroom wrap vscode-claude --no-configure --1m to print the setting without writing files.

    Claude Code and Anthropic own 1M model support and account eligibility. Local tests prove persisted settings and restoration, not a live entitled VS Code session or the resulting context window. Full guide →

    When to use · when to skip

    Use the library (compress()) when your own code builds the prompt: an API that forwards tool results, logs, search hits, database rows or long chat history to a model. It is a function over the message list, runs in-process with no key and no network, and works anywhere Python runs, including sandboxes and serverless functions.

    Use the proxy or headroom wrap when you want savings on a coding agent or any client you do not control, with no code changes, or when you want one shared memory across several agents. Either way, compression is reversible: originals stay retrievable through CCR for the configured TTL.

    Skip it for short conversational prompts and prose: there is little to compress, and blocks under the Kompress min_input_words floor come back byte-identical. If your provider's native compaction already covers your traffic and you do not need reversibility or cross-agent memory, you may not need Headroom either. Limitations has the full list.

    Your setupHook in with
    Any Python appcompress(messages, model=…)
    Any TypeScript appawait compress(messages, { model })
    Anthropic / OpenAI SDKwithHeadroom(new Anthropic()) · withHeadroom(new OpenAI())
    Vercel AI SDKwrapLanguageModel({ model, middleware: headroomMiddleware() })
    LiteLLMlitellm.callbacks = [HeadroomCallback()]
    LangChainHeadroomChatModel(your_llm)
    AgnoHeadroomAgnoModel(your_model)
    StrandsStrands guide
    ASGI appsapp.add_middleware(CompressionMiddleware)
    Multi-agentSharedContext().put / .get
    MCP clientsheadroom mcp install
    • SmartCrusher — universal JSON: arrays of dicts, nested objects, mixed types. It keeps error items, values outside the normal statistical range, and first/last boundaries, selected from field-variance statistics rather than a keyword list.
    • CodeCompressor — AST-aware for Python, JS/TS, Go, Rust, Java, C/C++, C#, PHP.
    • Kompress-v2-base — our HuggingFace model, trained on agentic traces.
    • Image compression — 40–90% reduction through a trained ML router.
    • CacheAligner — flags volatile content that would bust a provider KV-cache prefix; never rewrites prompts.
    • Live-zone compression — only new bytes are compressed (fresh tool output, the latest turn). The frozen prefix stays byte-identical, so the provider cache survives, and history is never dropped.
    • CCR — reversible compression; the model retrieves originals on demand.
    • Cross-agent memory — shared store with agent provenance and auto-dedup.
    • SharedContext — compressed context passing across multi-agent workflows.
    • headroom learn — plugin-based failure mining for Claude, Codex and Gemini.

    One request lifecycle is shared by compress(), the SDKs and the proxy:

    Setup → Pre-Start → Post-Start → Input Received → Input Cached → Input Routed → Input Compressed → Input Remembered → Pre-Send → Post-Send → Response Received

    • Transforms do the work: CacheAligner → ContentRouter → SmartCrusher / CodeCompressor / Kompress-base, live-zone only. IntelligentContext and RollingWindow were retired in PR-B1.
    • Pipeline extensions observe or customise lifecycle stages through on_pipeline_event(...).
    • Compression hooks sit alongside the lifecycle as an additional extension seam.
    • Proxy extensions are the integration seam for ASGI middleware, routes and startup policy.

    Provider- and tool-specific behaviour lives under headroom/providers/, so core orchestration stays focused on lifecycle, sequencing and policy:

    • CLI/tool slices — headroom/providers/claude, copilot, codex, grok, openclaw
    • Provider runtime slices — headroom/providers/claude, gemini, with shared backend dispatch in headroom/providers/registry.py
    • wrap.py, client.py, cli/proxy.py and proxy/server.py delegate env shaping, API target normalisation, backend selection and transport dispatch

    Install

    uv tool install --python 3.13 "headroom-ai[all]"  # CLI, isolated app env
    pip install "headroom-ai[all]"                    # CLI/proxy feature set
    npm install headroom-ai                           # TypeScript SDK (library only)
    docker pull ghcr.io/headroomlabs-ai/headroom:latest
    

    [all] includes the CLI/proxy feature set, including image support, without PyTorch-backed dependencies. Add [ml], [memory], [evals], or [voice] separately for those features; their PyTorch dependency can install CUDA runtime packages on Linux.

    Granular extras: [proxy], [mcp], [ml] (Kompress-v2-base), [code], [memory], [vector] (optional HNSW backend — needs a C++ toolchain), [relevance], [image], [lean] (torch-free proxy dependency profile; [sandbox] is a deprecated alias), [agno], [langchain], [evals], [voice], and [pytorch-mps] (Apple-GPU memory-embedder offload — set HEADROOM_EMBEDDER_RUNTIME=pytorch_mps). Requires Python 3.11+.

    [all] covers the core stack but not the framework adapters. Install those separately: pip install "headroom-ai[langchain]", and likewise [agno], [strands], [anyllm], [bedrock].

    → Installation guide — Docker tags, persistent service, PowerShell, devcontainers.

    Prefer uv tool install for the CLI so the command lives in an isolated app environment. On macOS, pass --python 3.13 if your default python3 is newer than the current wheel set:

    brew install [email protected]  # if 3.13 is not already available
    uv tool install --python 3.13 "headroom-ai[all]"
    uv tool update-shell      # if ~/.local/bin is not on PATH
    headroom --version
    

    Codex and other MCP clients often cannot inherit an interactive shell PATH. Configure the absolute path returned by command -v headroom:

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

    command = "headroom" only works when the client starts with a PATH that already includes the uv tool directory.

    With pipx, choose the interpreter explicitly:

    pipx install --python python3.13 "headroom-ai[all]"
    

    Native wheels currently cover macOS Apple Silicon and Linux. On Intel macOS, use the Docker-native install until native wheel support lands.

    CPU requirement (x86/x86_64). The ONNX-backed features — Magika content detection and embedding relevance — use a precompiled ONNX Runtime that needs AVX2. On x86 hosts without AVX2 (some Docker/QEMU setups, older cloud VMs) Headroom falls back to its non-ONNX paths — BM25 relevance, heuristic detection — rather than crashing. arm64 and Apple Silicon need no AVX2.

    headroom update          # detects pip / pipx / uv tool and upgrades in place
    headroom update --check  # report the latest release without upgrading
    headroom update --pre    # include pre-releases
    

    headroom update works out how Headroom was installed (pip/venv, pip --user, pipx, uv tool) and runs the matching upgrade on macOS, Linux and Windows. For git checkouts, editable installs, Docker images and externally-managed system Pythons (PEP 668) it prints the correct manual step instead of guessing.

    The proxy also prints a one-line "update available" notice at startup. It checks PyPI at most once a day, in the background, and never blocks. Opt out with HEADROOM_UPDATE_CHECK=off; it is also skipped in --stateless mode and CI.

    If pip install "headroom-ai[all]" fails with CERTIFICATE_VERIFY_FAILED (unable to get local issuer certificate), your network runs SSL inspection — a MITM proxy presenting a company CA. The build backend (maturin) downloads rustup over a connection your TLS stack does not trust. Install Rust first so the build never fetches it:

    # macOS / Linux
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh && rustup default stable
    # Windows
    winget install Rustlang.Rustup && rustup default stable
    

    Restart your shell, then install. A prebuilt wheel avoids the Rust build entirely: pip install --only-binary headroom-ai headroom-ai. Wheels are published for Windows (win_amd64), Linux (x86_64 / aarch64) and macOS (Apple Silicon and Intel), so those platforms never need a local Rust toolchain — the Rust-first step above is only for the sdist fallback when no wheel matches.

    At runtime Headroom verifies upstream TLS against the operating system's certificate store — where IT installs the Zscaler / Netskope / Palo Alto root — plus certifi's public roots, so a managed machine normally needs no setup. headroom doctor --network shows who signed each upstream certificate, whether Headroom trusts it, and whether a gateway block page is in the way. If the root is not in the OS store, export it as PEM and set HEADROOM_CA_BUNDLE=/path/to/root.pem (NODE_EXTRA_CA_CERTS also works). Full guide and the domain list for IT: Corporate networks.

    Two download hosts can still need attention:

    • cdn.pyke.io — the ONNX Runtime for the Rust core, fetched with Mozilla's roots only. Pre-provide it with ORT_STRATEGY=system and ORT_LIB_LOCATION=/path/to/onnxruntime.
    • huggingface.co — the kompress-base model (Python, OS store) and the Rust core's embedding model (Mozilla's roots only). If the domain is blocked, pre-download and run with HF_HUB_OFFLINE=1, or point HF_ENDPOINT at a trusted mirror.

    Running with compression disabled (pure gateway) needs neither asset.

    Intel macOS: no prebuilt ONNX Runtime (#941). ort-sys ships no prebuilt binary for x86_64-apple-darwin, so a source build fails by default even outside a corporate proxy. Point it at a system runtime:

    brew install onnxruntime
    ORT_STRATEGY=system \
    ORT_LIB_LOCATION="$(brew --prefix onnxruntime)/lib" \
    ORT_PREFER_DYNAMIC_LINK=1 \
      pip install "headroom-ai[all]"
    
    # ORT is dlopen'd at runtime too:
    export ORT_DYLIB_PATH="$(brew --prefix onnxruntime)/lib/libonnxruntime.dylib"
    

    ORT_LIB_LOCATION must point at lib/, not the bare prefix, and ORT_PREFER_DYNAMIC_LINK=1 is required — without it ORT_STRATEGY=system still attempts static linking, which the Homebrew keg does not provide.

    "Basic Constraints of CA cert not marked critical" only occurs with HEADROOM_CERT_STORE=bundled (the OS store verifies these roots fine). If TLS fails with:

    [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
    Basic Constraints of CA cert not marked critical
    

    then the corporate CA is found and trusted, and adding it to a CA bundle changes nothing. Python 3.13 with OpenSSL 3.x enables VERIFY_X509_STRICT by default, which enforces RFC 5280 §4.2.1.9: a CA cert's basicConstraints must be marked critical. Inspection roots such as Zscaler set CA:TRUE without the critical bit, so the chain is rejected.

    HEADROOM_TLS_STRICT=0 clears only the strict flag, from every TLS context Headroom controls — the proxy's httpx upstream client and the urllib3/huggingface_hub path used for model downloads. Chain validation, signature, expiry and hostname checks all stay on.

    HEADROOM_TLS_STRICT=0 headroom proxy --port 8787
    

    The Rust core's downloads use rustls with Mozilla's roots and are unaffected by HEADROOM_TLS_STRICT and the CA variables; pre-provision ONNX Runtime with ORT_STRATEGY=system and models via HF_ENDPOINT as above.

    headroom learn

    headroom learn mines failed sessions and writes corrections to CLAUDE.local.md (default, gitignored; use --target CLAUDE.md for the shared team file), AGENTS.md or GEMINI.md. → Failure learning

    Telemetry

    An anonymous beacon is on by default. It reports how compression behaved: ratios, counters, provider and model IDs, OS and architecture. It never sends prompts, completions, code or file paths. It exists so we can see when a release regresses a compression ratio across real workloads rather than only our own test corpus.

    Turn it off with HEADROOM_BEACON=off, HEADROOM_TELEMETRY=off, the DO_NOT_TRACK=1 convention, or HEADROOM_OFFLINE=1. The full field list is in the proxy docs.

    Headroom for teams

    Not seeing the savings you want? Headroom OSS is a framework. It was built to show what's possible on one developer's laptop, so it saves less than it could. We are building bigger savings for teams and enterprises in Headroom Enterprise, which adds:

    • More cost savings
    • Tokens secured
    • On premise deployment
    • Deep attribution
    • And many more features

    If you're a team or an enterprise, talk to us: [email protected] · headroomlabs.ai

    Everything in this repo stays open source under Apache 2.0.

    Documentation

    Start hereGo deeper
    QuickstartArchitecture
    ProxyHow compression works
    MCP toolsCCR — reversible compression
    MemoryCache optimization
    Failure learningBenchmarks
    ConfigurationLimitations
    Persistent installsSavings analytics

    Compared to

    Headroom runs locally, covers every content type, works with every major framework, and is reversible.

    ScopeDeployLocalReversible
    HeadroomAll context — tools, RAG, logs, files, historyProxy · library · middleware · MCPYesYes
    Compresr, Token Co.Text sent to their APIHosted API callNoNo
    OpenAI CompactionConversation historyProvider-nativeNoNo

    Headroom is the proxy, and it compresses everything flowing through it whatever sits upstream. Our recommended companion is Serena for semantic code navigation, installed by default when you wrap an agent, plus Ponytail if you want leaner model output. Everything else is your call — attach a code-memory MCP, Graphify, Caveman, or any other MCP server, and Headroom compresses downstream of all of it.

    Contributing

    git clone https://github.com/headroomlabs-ai/headroom.git && cd headroom
    uv sync --extra dev && uv run pytest
    

    Devcontainers in .devcontainer/ (default, plus memory-stack with Qdrant and Neo4j). See CONTRIBUTING.md.

    Community

    License

    Apache 2.0 — see LICENSE.

    Footnotes

    1. headroom wrap routes OpenAI-compatible traffic to the default upstream (https://api.openai.com/v1). For a third-party OpenAI-compatible provider (DeepSeek, Together, OpenRouter, a self-hosted gateway), pass --openai-api-url https://api.deepseek.com/v1 — or set OPENAI_TARGET_API_URL before wrapping — otherwise your provider key is sent to OpenAI and rejected with 401 Incorrect API key provided. See OpenCode + DeepSeek. ↩