# Headroom - AI Agent 上下文压缩层,减少60-95%Token > 本地运行的AI上下文压缩工具,支持6种算法、可逆压缩、跨Agent共享记忆,零代码接入 ## Headroom — AI Agent 上下文压缩层 **Headroom** 是一个本地运行的 AI Agent 上下文压缩工具,能在保持答案准确性的前提下减少 60–95% 的 Token 消耗。支持 Python 和 TypeScript,可作为库、代理、MCP Server 使用。 ### 核心能力 - **6 种压缩算法** — SmartCrusher(JSON)、CodeCompressor(AST)、Kompress-base(文本ML模型)等 - **可逆压缩(CCR)** — 原始内容本地保存,LLM 按需取回,不丢信息 - **跨 Agent 共享记忆** — Claude Code、Codex、Cursor 等多 Agent 共享上下文,自动去重 - **`headroom learn`** — 自动挖掘失败会话,将修正写入 CLAUDE.md / AGENTS.md ### 使用方式 | 模式 | 命令 | 说明 | |------|------|------| | 库调用 | `compress(messages)` | 嵌入任意 Python/TS 应用 | | 代理 | `headroom proxy --port 8787` | 零代码改动,任何语言 | | Agent 包装 | `headroom wrap claude` | 一键包装主流编码 Agent | | MCP Server | `headroom mcp install` | 任何 MCP 客户端可用 | ### 实测压缩效果 | 场景 | 压缩前 | 压缩后 | 节省 | |------|-------:|-------:|-----:| | 代码搜索(100条) | 17,765 | 1,408 | **92%** | | SRE 故障排查 | 65,694 | 5,118 | **92%** | | GitHub Issue 分类 | 54,174 | 14,761 | **73%** | | 代码库探索 | 78,502 | 41,254 | **47%** | ### Agent 兼容 Claude Code ✅ · Codex ✅ · Cursor ✅ · Aider ✅ · Copilot CLI ✅ · OpenClaw ✅ 任何 OpenAI 兼容客户端均可通过 `headroom proxy` 接入。 ### 技术栈 Python 3.10+ · HuggingFace Kompress-base 模型 · Apache 2.0 开源协议 --- **分类**:软件 **标签**:压缩 · Agent · 上下文 **作者**:Xiao.Xi **链接**:https://octohz.com/p/1807