Skip to main content

The Context Optimization Layer for LLM Applications - Cut costs by 50-90%

Project description

  ██╗  ██╗███████╗ █████╗ ██████╗ ██████╗  ██████╗  ██████╗ ███╗   ███╗
  ██║  ██║██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔═══██╗██╔═══██╗████╗ ████║
  ███████║█████╗  ███████║██║  ██║██████╔╝██║   ██║██║   ██║██╔████╔██║
  ██╔══██║██╔══╝  ██╔══██║██║  ██║██╔══██╗██║   ██║██║   ██║██║╚██╔╝██║
  ██║  ██║███████╗██║  ██║██████╔╝██║  ██║╚██████╔╝╚██████╔╝██║ ╚═╝ ██║
  ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═════╝ ╚═╝  ╚═╝ ╚═════╝  ╚═════╝ ╚═╝     ╚═╝
                  The context compression layer for AI agents

60–95% fewer tokens · library · proxy · MCP · 6 algorithms · local-first · reversible

CI codecov PyPI npm Model: Kompress-base Tokens saved: 60B+ License: Apache 2.0 Docs

Docs · Install · Proof · Agents · Discord · llms.txt

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


Headroom compresses everything your AI agent reads — tool outputs, logs, RAG chunks, files, and conversation history — before it reaches the LLM. Same answers, fraction of the tokens.

Headroom in action
Live: 10,144 → 1,260 tokens — same FATAL found.

What it does

  • Librarycompress(messages) in Python or TypeScript, inline in any app
  • Proxyheadroom proxy --port 8787, zero code changes, any language
  • Agent wrapheadroom wrap claude|codex|cursor|aider|copilot in one command
  • MCP serverheadroom_compress, headroom_retrieve, headroom_stats for any MCP client
  • Cross-agent memory — shared store across Claude, Codex, Gemini, auto-dedup
  • headroom learn — mines failed sessions, writes corrections to CLAUDE.md / AGENTS.md
  • Reversible (CCR) — originals never deleted; LLM retrieves on demand

How it works (30 seconds)

 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-base  (text, HF)     │
    │                                                     │
    │  Cross-agent memory  ·  headroom learn  ·  MCP      │
    └────────────────────────────────────────────────────┘
        │   compressed prompt  +  retrieval tool
        ▼
 LLM provider  (Anthropic · OpenAI · Bedrock · …)
  • ContentRouter — detects content type, selects the right compressor
  • SmartCrusher / CodeCompressor / Kompress-base — compress JSON, AST, or prose
  • CacheAligner — stabilizes prefixes so provider KV caches actually hit
  • CCR — stores originals locally; LLM calls headroom_retrieve if it needs them

Architecture · CCR reversible compression · Kompress-base model card

Get started (60 seconds)

# 1 — Install
pip install "headroom-ai[all]"          # Python
npm install headroom-ai                 # Node / TypeScript

# 2 — Pick your mode
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 — See the savings
headroom stats

Granular extras: [proxy], [mcp], [ml], [agno], [langchain], [evals]. Requires Python 3.10+.

Proof

Savings on real agent workloads:

Workload Before After Savings
Code search (100 results) 17,765 1,408 92%
SRE incident debugging 65,694 5,118 92%
GitHub issue triage 54,174 14,761 73%
Codebase exploration 78,502 41,254 47%

Accuracy preserved on standard benchmarks:

Benchmark Category N Baseline Headroom Delta
GSM8K Math 100 0.870 0.870 ±0.000
TruthfulQA Factual 100 0.530 0.560 +0.030
SQuAD v2 QA 100 97% 19% compression
BFCL Tools 100 97% 32% compression

Reproduce: python -m headroom.evals suite --tier 1 · Full benchmarks & methodology

60B+ tokens saved — community leaderboard
60B+ tokens saved by the community — live leaderboard →

Agent compatibility matrix

Agent headroom wrap Notes
Claude Code --memory · --code-graph
Codex shares memory with Claude
Cursor prints config — paste once
Aider starts proxy + launches
Copilot CLI starts proxy + launches
OpenClaw installs as ContextEngine plugin

Any OpenAI-compatible client works via headroom proxy. MCP-native: headroom mcp install.

When to use · When to skip

Great fit if you…

  • run AI coding agents daily and want savings without changing your code
  • work across multiple agents and want shared memory
  • need reversible compression — originals always retrievable via CCR

Skip it if you…

  • only use a single provider's native compaction and don't need cross-agent memory
  • work in a sandboxed environment where local processes can't run
Integrations — drop Headroom into any stack
Your setup Hook in with
Any Python app compress(messages, model=…)
Any TypeScript app await compress(messages, { model })
Anthropic / OpenAI SDK withHeadroom(new Anthropic()) · withHeadroom(new OpenAI())
Vercel AI SDK wrapLanguageModel({ model, middleware: headroomMiddleware() })
LiteLLM litellm.callbacks = [HeadroomCallback()]
LangChain HeadroomChatModel(your_llm)
Agno HeadroomAgnoModel(your_model)
Strands Strands guide
ASGI apps app.add_middleware(CompressionMiddleware)
Multi-agent SharedContext().put / .get
MCP clients headroom mcp install
What's inside
  • SmartCrusher — universal JSON: arrays of dicts, nested objects, mixed types.
  • CodeCompressor — AST-aware for Python, JS, Go, Rust, Java, C++.
  • Kompress-base — our HuggingFace model, trained on agentic traces.
  • Image compression — 40–90% reduction via trained ML router.
  • CacheAligner — stabilizes prefixes so Anthropic/OpenAI KV caches actually hit.
  • IntelligentContext — score-based context fitting with learned importance.
  • CCR — reversible compression; LLM retrieves originals on demand.
  • Cross-agent memory — shared store, agent provenance, auto-dedup.
  • SharedContext — compressed context passing across multi-agent workflows.
  • headroom learn — plugin-based failure mining for Claude, Codex, Gemini.
Pipeline internals

Headroom exposes one stable request lifecycle across compress(), the SDK, and the proxy:

SetupPre-StartPost-StartInput ReceivedInput CachedInput RoutedInput CompressedInput RememberedPre-SendPost-SendResponse Received

  • Transforms do the work: CacheAligner, ContentRouter, SmartCrusher, CodeCompressor, Kompress-base, IntelligentContext / RollingWindow.
  • Pipeline extensions observe or customize lifecycle stages via on_pipeline_event(...).
  • Compression hooks sit alongside the canonical lifecycle as an additional extension seam.
  • Proxy extensions remain the server/app integration seam for ASGI middleware, routes, and startup policy.

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

  • CLI/tool slices: headroom/providers/claude, copilot, codex, openclaw
  • Provider runtime slices: headroom/providers/claude, gemini, plus shared backend/runtime dispatch in headroom/providers/registry.py
  • Core files stay orchestration-first: wrap.py, client.py, cli/proxy.py, and proxy/server.py delegate provider-specific env shaping, API target normalization, backend selection, and transport dispatch.

Install

pip install "headroom-ai[all]"          # Python, everything
npm install headroom-ai                 # TypeScript / Node
docker pull ghcr.io/chopratejas/headroom:latest

Granular extras: [proxy], [mcp], [ml] (Kompress-base), [agno], [langchain], [evals]. Requires Python 3.10+.

Using pipx? Choose a supported interpreter explicitly:

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

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

headroom learn

headroom learn in action

headroom learn — mines failed sessions, writes corrections to CLAUDE.md / AGENTS.md / GEMINI.md.

Documentation

Start here Go deeper
Quickstart Architecture
Proxy How compression works
MCP tools CCR — reversible compression
Memory Cache optimization
Failure learning Benchmarks
Configuration Limitations

Compared to

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

Scope Deploy Local Reversible
Headroom All context — tools, RAG, logs, files, history Proxy · library · middleware · MCP Yes Yes
RTK CLI command outputs CLI wrapper Yes No
lean-ctx CLI commands, MCP tools, editor rules CLI wrapper · MCP Yes No
Compresr, Token Co. Text sent to their API Hosted API call No No
OpenAI Compaction Conversation history Provider-native No No

Attribution. Headroom ships with the excellent RTK binary for shell-output rewriting — git show --short, scoped ls, summarized installers. Huge thanks to the RTK team; their tool is a first-class part of our stack, and Headroom compresses everything downstream of it. Headroom can also use lean-ctx as the selected CLI context tool; set HEADROOM_CONTEXT_TOOL=lean-ctx before running headroom wrap ....

Contributing

git clone https://github.com/chopratejas/headroom.git && cd headroom
pip install -e ".[dev]" && pytest

Devcontainers in .devcontainer/ (default + memory-stack with Qdrant & Neo4j). See CONTRIBUTING.md.

Community

License

Apache 2.0 — see LICENSE.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

headroom_ai-0.22.3-cp313-cp313-manylinux_2_28_aarch64.whl (18.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

headroom_ai-0.22.3-cp313-cp313-macosx_11_0_arm64.whl (16.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_aarch64.whl (18.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

headroom_ai-0.22.3-cp312-cp312-macosx_11_0_arm64.whl (16.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_aarch64.whl (18.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

headroom_ai-0.22.3-cp311-cp311-macosx_11_0_arm64.whl (16.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_aarch64.whl (18.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

headroom_ai-0.22.3-cp310-cp310-macosx_11_0_arm64.whl (16.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file headroom_ai-0.22.3-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 13314984fae54e94ecbd2101197c529d62cab06b1831f37277681ded49a227c7
MD5 d138cfaf4a48cc7ca3bdd2ca57610f53
BLAKE2b-256 a1cfc7893ea897683e886f1afac21b5eb8bb607fb08d8298e8bac8ebc11a8f6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d55d9a59183118539203c1f17b366c71dd1a3583e61d390cd82fcdeb89e53d3e
MD5 ef475171b7b9689f799479a82387f9c3
BLAKE2b-256 85a8dd4b1bd48d405e60c899b0a058872c7ba219c7c19d211aa94cccfffd0e61

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dc5fff2cd99380f9229477cc5957e97661cb5a71bfbbe25a6ae225acfd97cddb
MD5 bef2e6babc94345173351d8fba132964
BLAKE2b-256 abc67e224ca5b3de2cb54eb2117d1d0b1160687eff6e13ef19fbb81b10b527ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 97b15ede322587d907577103a5802d0055aeccedae296fabea1d66b7d03fa861
MD5 80f06c512dbf3d14493fa4b3e35d58de
BLAKE2b-256 b0e775a43af6cfe1df0168bc036a769d77a695c15f222321d6852262dfca1dfc

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d82f2aede911ae4c5a3d529270758b548399b97290f8b7b6161c3f460e07348e
MD5 ff76df93126d527c48cf8967dca6cff4
BLAKE2b-256 25db584de503f4d8d91ed0b8eaab3a120c75cddf7e0c037cf98f514689deaed5

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 061f60f55826cfd01d954faa8916ef4232b39f8ac4a2d36bb6a77fe5803fdfaf
MD5 8c72bc7d4f730c648878079cad07b87a
BLAKE2b-256 ab5986e2015a57575b7c3902d04eb12fc7c247c4d5f5510ece4d1cd44cbcd5b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c4670e3247ee39bc585e902cfd6923621f632988a08b8a5237c9225e9cfd5998
MD5 a362cf74575e10ac6b23f7f1f4239338
BLAKE2b-256 539213995ed818a5c2a7b6595a00239303f41652faa2be3b1e69bfb197a698e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc83337a24bce8fbca4f5cb943e0d123ab87784d4bccdc946c4b6211f6b478d3
MD5 2d11947b9ede5a1f226b33bbc166ae36
BLAKE2b-256 61a251417833e6c61f77a1933fd67eb8c3e38451484830008ecf710f0bfba18a

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 26f2ea60d82492c1f3a3bd2cb5e7e8325451f09b019c317ab071018cece66123
MD5 9133140c3c2fa03e435921f76796644e
BLAKE2b-256 5e85884721f4c576e183edf7108a88c4b32be6b8ac3c24b25b1fd526d5738c9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fafec8d9233f650d71e4bba4ba9c1fd6aaf8d1c2cf151dc00ca22ec33249ad8d
MD5 e31de37eba0417403554260dc38f99e0
BLAKE2b-256 a7b676151a7e3d9dd222a07943fe9fb5b48ca3404e46fd54d3dc8e0f70ed7ad8

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headroom_ai-0.22.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for headroom_ai-0.22.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e325ae6a92a4f6bc5c8c006665d11cd557fbf9fd60db3380cc1ea6fe16d45f5
MD5 f88e02a73991a1b43e61898128515e2d
BLAKE2b-256 babc64027e1689137762731803f870e3a5cdac1d5c730587149b6a91a04f24de

See more details on using hashes here.

Provenance

The following attestation bundles were made for headroom_ai-0.22.3-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on chopratejas/headroom

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page