ranxianglei /billion-context
A context-compression plugin for month-long single sessions (billions of tokens) ,small context windows (a 100K context is enough) and token savings (5x fewer tokens) .上下文压缩插件,月级长会话会话, 兼顾小窗口(100k上下文足矣)省token(省5倍token) . billion-context is all you need
★ 5,903⑂ 449👁 11⑃ 3,175● 2,770▤ 206◈ 16
5,903
stars
+389
449
forks
11
watchers
3,175
prs
2,770
issues
206
releases
16
discussions
README
billion-context English | 中文 | 日本語 上下文压缩插件 — billion-context is all you need。 小窗口(100k 上下文足矣)· 省 5 倍 token · 超长会话(十亿级别单会话)· 高压缩质量 npm install -g billion-context --prefix=~/.local --- 缓存健康速览:健康会话的前缀缓存命中率在 95–97% 左右——压缩本身代价 ≤2%。持续低于这个数,用 /acp 或 /acp-cache 查归因(见常见问题);常见原因依次:上游缓存 TTL 到期 · 切换模型 · bili 的 bug(欢迎提报)· 其他/未知。 社区 QQ群: 1056132097(已满) 1108730198(已满) 1129868472(未满) --- 📄 论文 / 预印本 - 模型驱动的分层增量压缩:面向长寿命编码 Agent 的免训练多代上下文管理(中文版,v0.2) 📝 论文本身与代码一同以 MIT 许可开源(位于 paper/ 目录),是代码库的一部分 —— 这是一份活文档,任何人都可以编辑,欢迎提 PR 改进。 生产规模纵向研究:四个半月、三宿主、174,327 次模型调用、187.6 亿累计输入 token(三宿主合计约 247 亿),204,800-token 窗口零违规,马拉松会话 8,584–12,049 次调用。 📊 第三方独立评测基准 - 1,500 题三大基准横评报告(LongMemEval-S · ContextBench · MemoryAgentBench)(English)—— 基于 DeepSeek V4.1 Flash、Qwen3-Embedding-8B、Qwen3-Reranker-4B 与 Pi Agent,对 billion-context (v0.1.202)、full 全量上下文及 3 条 RAG 管线(bm25、embedding、embedding-rerank)进行全成本归因盲测:ContextBench 端到端有效 F1 夺得全场第一(0.3097,比 full 省钱 58.3%)、LongMemEval-S 领先最强 RAG 达 +16.6%(79.20% vs 62.60%,比独立会话 full 省钱 71.1%)、MemoryAgentBench 1.48M 超长会话实现 100% 存活与 30× 稳态压缩(full 199 题全部爆窗崩溃)。 --- billion-context 架在任意编程助手与其模型 API 之间,用 acp-kernel 压缩重写 Anthropic/OpenAI 流。何时压缩、压缩什么 —— 由模型决定,而非硬截断。 为什么 长编程会话会把上下文撑爆。各家 provider 按 token 计费,一旦超过上下文窗口,会话质量下降甚至崩掉。billion-context 把已消耗的对话压缩成分层摘要,让你一个会话连跑数天 —— 海量 token 穿过同一个上下文窗口。 与宿主自带的摘要器不同,这里的压缩增量、可逆、对前缀缓存友好:摘要在小范围内写入,可按需解压,缓存前缀保持完整。 工作原理 !工作原理 上下文管理工具 代理向对话注入四个上下文管理工具;模型在上下文增长时自行调用,代理在服务端执行 compress,折叠后的范围在历史中保持摘要形态、直到被恢复: - compress —— 把一段消息范围折叠成详细摘要。 - decompress —— 需要精确细节时恢复某个已压缩范围。 - search_context —— 在压缩摘要与可见消息中做关键词检索。 - acp_status —— 上下文用量概览 + 哪些区间仍可压缩。 模型会自主使用以上工具自主管控上下文,无需人工干预。 该选哪个? 按客户端选: | 客户端 | 用这个 | |---|---| | pi | billion-context —— bili pi(启动器)或 bili plugin install pi(原生);独立 billion-context-pi 仍可用 —— 细节见 docs/clients.zh-CN.md | | opencode(1.x / 2.x) | billion-context —— bili opencode(启动器)或 bili plugin install opencode(原生);独立 opencode-acp 在 1.x 上仍可用 —— 完整指南:OpenCode | | omp | billion-context,bili omp(内置插件)或 bili plugin install omp(自拉起原生插件,免启动器) | | dsh | billion-context —— bili dsh(启动器,经 --patch 注入完整原生插件)或 bili plugin install dsh ≡ dsh plugin --profile add billion-context(统一泳道)—— 细节见 docs/clients.zh-CN.md | | kimi | bili plugin install kimi(自拉起原生,需 Kimi Code ≥ 2.0.0)或 bili kimi(证书 MITM)或 /bili/ 前缀 —— 细节见 docs/clients.zh-CN.md | | hermes | bili plugin install hermes(自拉起原生,Python 插件 958)或 bili hermes(证书 MITM) | | zcode(Z.ai / bigmodel coding plan) | bili plugin install zcode(自拉起原生,1145)或 GUI「设置 → 网络」证书 MITM 或 /bili/ 前缀 —— 细节见 docs/clients.zh-CN.md | | claude | bili claude(启动器)或 bili plugin install claude(原生姿态,964 —— 受管 settings 块 + 会话自管代理;见下方"注意") | | codex | bili codex(启动器 —— 全功能零配置姿势)或 bili plugin install codex(MCP shell 工具面配套:先起 bili 再玩 —— shell 不拉代理,也路由不了 codex 本体流量)—— 细节见 docs/clients.zh-CN.md | | jcode | billion-context,bili jcod
Top issues
#4599CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue)198 comments · 2026-10-24#917Message Board | 留言板59 comments · 2026-09-17#2411[feature] Intercept TRAE Code (traecode) native compression commands, aligning with dsh native compression interception | [feature] 拦截 TRAE Code(traecode)的原生压缩指令,对齐 dsh 原生压缩拦截46 comments · 2026-10-08#3011[Bug] Fork of DSH branch clone: inheritance permanently abandoned by 409 SNAPSHOT_UNAVAILABLE — zero-fold clone triggers context_length_exceeded 400 on first turn | [Bug] DSH 分支克隆的 fork 继承被 409 SNAPSHOT_UNAVAILABLE 永久放弃:克隆零折叠,首轮即 context_length_exceeded …41 comments · 2026-10-13#2438[resilience] Preflight compress/timeout loop on sustained mass fold-coverage loss has no graceful degrade37 comments · 2026-10-08#5643Snapshot-Centric Compression Foundation: Single-Row Table as Source of Truth + Compression = Insert/Delete/Update Events | Snapshot中心化的压缩底座:单行表真源 + 压缩=对表的增删改事件(非增量车道,#5652/v6 线定位纠正)33 comments · 2026-11-04#3978[Bug] Excessive preflight compression time on ultra-large contexts; client mid-disconnect causes repeated request forwar | [Bug] 超大上下文 preflight 压缩耗时过长,客户端中途断开导致请求反复无法转发31 comments · 2026-10-20#3837OpenAI/Codex channel: Per-request body rewriting causes the prefix cache to periodically reset to zero (degenerate foldi | OpenAI/Codex 通道:每请求改写请求体导致前缀缓存周期性归零(退化折叠 foldPoint=m00001 + abort 后 stamped 漂移),单会话 66.7% 计费为全价输入25 comments · 2026-10-19
Discussions
#5874提案:快照表式压缩底座(六段固定链,单一存储真源)0 comments · 2026-11-07#5843My testing shows this tool is not worth it? Am I doing something wrong?5 comments · 2026-11-07#5818Can billion-context be integrated with opencodex?3 comments · 2026-11-06#5552What to do when your model keeps treating compressed old content as fresh user instructions?0 comments · 2026-11-02#5551What to do when billion-context compresses frequently? · billion-context频繁压缩该怎么办?0 comments · 2026-11-02#5550Meet billion-context · 认识 billion-context0 comments · 2026-11-02#5312billion-context instead of billion-context-pi for pi?9 comments · 2026-10-31#3916实时 Issue/PR 状态板(自动维护,勿手编)1 comments · 2026-10-20
Latest release
v0.1.213 v0.1.213 2026-11-07What's Changed [PR] fix: revert self-contradictory inclusive billing stamp to split (5515) by @ranxianglei in https://github.com/ranxianglei/billion-context/pull/5518 [PR] docs(website): add blog post 'What to Do When the Model Keeps Treating Old Compressed Content as New User Instructions?' | docs(website): add blog post '模型总是把压缩老内容当成用户新指令咋办?' (EN+ZH) by @ranxianglei in https://github.com/ranxianglei/billion-context/pull/5549 [PR] fix: read Responses additional_tools preamble in tool reachability observation by @ranxianglei in https://github.com/ranxianglei/billion-context/pull/5528 [PR]