ByteCosts
billion-context-review.mdx

AI Coding Agents

Billion Context Review: Model-Driven Compression for Month-Long Sessions

billion-context is a proxy that injects four context-management tools (compress, decompress, search_context, acp_status) into your session so the model itself decides what to fold into hierarchical summaries, keeping a stable prefix for provider prompt caching. The design targets month-long single sessions and claims 5× fewer tokens; the project is popular and fast-moving but runs pre-1.0 releases with 1,667 open issues as of November 30, 2026.

billion-context (ranxianglei/billion-context) is a context-compression proxy that sits between your coding agent and its model API, rewriting Anthropic and OpenAI streams. Its twist: instead of compressing on a fixed rule, it injects four tools into the conversation and lets the model decide when and what to compress into layered, restorable summaries. The pitch is month-long single sessions: “a 100K context is enough,” “5× fewer tokens,” “billions of tokens through one context window.” It is one of the most-starred projects in this category (8,767 stars, 718 forks as of November 30, 2026) and also carries one of the largest open-issue backlogs we have seen (1,667), on a pre-1.0 versioning scheme that reached v0.1.218 on November 29, 2026.

At a glance

QuestionAnswer
What is it?A proxy that folds conversation history into layered summaries at the model’s direction.
What cost does it target?Input from resending long histories and the context-window pressure that builds over a session.
Where does it act?Between the coding agent and the Anthropic or OpenAI API.
How do you try it?Install the npm package and use a supported client plugin, launcher, or custom base URL.
Can you recover originals?The model can call decompress to restore a folded range. Native installs save a config snapshot for rollback.
What license is stated?GitHub records NOASSERTION for the repository. The in-repo paper is MIT-licensed.
What is its maturity signal?8,767 stars and 1,667 open issues as of November 30, 2026.
When is it a good fit?Long sessions that regularly approach the context limit, where you can monitor prefix-cache reuse.

What it is and which cost layer it targets

Most tools in this series shave tokens off tool output before it enters context. billion-context works on a different layer: the conversation history itself, on the wire between agent and provider. The costs it targets are the compounding ones of long-lived sessions:

  • History re-carriage: every turn re-sends the accumulated transcript. Folded ranges collapse to summaries, so the per-turn bill stops growing with session age.
  • Context-window exhaustion: the real failure it prevents is the session dying outright. The project’s longitudinal study reports zero window violations on 204,800-token models across marathon sessions.
  • Prompt-cache economics: the design is explicitly prefix-cache friendly. Compression is incremental (small ranges fold at a time), so the cached prefix stays intact and keeps billing at cache-read rates instead of full input rates.
  • Retrieval after folding: decompress restores a range and search_context keyword-searches summaries and visible messages, so folded detail is recoverable rather than destroyed.

How it works

The proxy injects four context-management tools into the conversation; the model calls them itself as context grows, and the proxy executes compress server-side so folded ranges stay summarized in history until restored:

  • compress: fold a message range into a detailed summary.
  • decompress: restore a compressed range when exact details are needed again.
  • search_context: keyword search over compressed summaries and visible messages.
  • acp_status: context-usage overview plus which ranges are still compressible.

The compression engine is acp-kernel. Because the model itself picks fold ranges, this is “model-driven” compression: the quality of folding depends on the model understanding the tools, which is also its biggest fragility (more on that in the issues section). The README sets the operational target: a healthy session keeps a 96–99% prefix-cache hit rate, with compression itself costing under 2% of tokens.

Integration has three forms: a self-spawning native plugin inside the client (bili plugin install <client> for pi, omp, opencode, dsh, kimi, hermes and zcode), a launcher that brings up proxy plus client in one command (bili <client>, covering about two dozen clients including codex, claude, gemini, trae, qoder, copilot, zed and goose), and a universal /bili/ base-URL prefix for anything else. Where clients honor proxy and CA environment variables the launcher uses certificate-based MITM, TLS-terminating only whitelisted provider hosts discovered from the client’s own config; where they don’t, it rewrites the base URL. A deliberate bili start daemon owns port 8787; spawned lanes self-manage a zone starting at 18787.

Two traps the README itself flags. First, native plugins and the standalone extensions (billion-context-pi, opencode-acp) are mutually exclusive; running both double-compresses, and the installer snapshots your original config to .bili-bak when it swaps entries. Second, on Claude Code the native posture (managed settings block plus SessionStart hook, shipped via issue #964) has a known limitation tracked as #2290: the Claude Desktop app’s Code tab sets its own ANTHROPIC_BASE_URL, bypassing the proxy entirely while DISABLE_AUTO_COMPACT=1 still applies, so desktop sessions get neither bili compression nor native auto-compaction.

Install and first run

npm install -g billion-context --prefix=~/.local

That puts bili in ~/.local/bin. Then pick one of the three postures:

bili plugin install pi          # native plugin inside the client
bili codex                      # launcher: proxy + client in one command
bili plugin remove <client>     # undo

For clients using a custom base URL, append /bili/ to the proxy origin. Codex plugin installation registers the four ACP tools over MCP and requires a reachable bili proxy. Use bili codex, the documented launcher, to route Codex model traffic through compression. Removal is bili plugin remove <client>. Native installs keep a .bili-bak config snapshot.

What it saves: claims vs evidence

Every savings number for this project is self-reported, so frame them as claims:

  • The tagline claims “5× fewer tokens” and month-long sessions on a 100K window.
  • The in-repo paper (MIT-licensed, a “living document”) reports a 4.5-month longitudinal study: three hosts, 174,327 model calls, 18.76B cumulative input tokens (~24.7B across all hosts), zero window violations on 204,800-token models, marathon sessions of 8,584–12,049 calls.
  • The third-party benchmark suite run by the project (v0.1.202, versus full context and three RAG arms on DeepSeek V4.1 Flash) reports #1 on ContextBench (0.3097 Utilized F1, -58.3% cost vs full), 16.6 percentage points above the best RAG arm on LongMemEval-S (79.20% vs 62.60%, -71.1% independent-session cost), and 100% survival on a 1.48M-token MemoryAgentBench TTL at 30× steady-state compression where the full-context arm failed 199 of 199 items.

The project ran these evaluations on third-party benchmarks. The captured evidence contains no independent replication. For long sessions, check two outcomes separately: whether the session fits within the context window and whether its cumulative provider cost falls. Run the same sequence of questions with and without the launcher. Include a later question that depends on a detail from the beginning of the session. Then check the answer against the original text and price both runs using the provider’s usage breakdown. A run can stay within the window and still lose a detail the next task needs.

Prompt-cache and extra-turn risk

This is the section that should drive your decision, because the whole design stands or falls on cache behavior. At committed Anthropic rates, claude-sonnet-5-5 charges $2 per million input tokens but only $0.10 per million cache-read tokens: a stable cached prefix is 20× cheaper than re-sent context. billion-context’s incremental folding exists to keep that prefix stable. The open issues show the failure modes when it does not:

  • Issue #3837: on the OpenAI/Codex channel, per-request body rewriting caused the prefix cache to periodically reset to zero; the title reports 66.7% of a session billed at full-price input.
  • Issue #5608: cache hit rate collapsing to 1–12% for a whole generation, then returning to 100%, repeating fifteen times in a day.
  • Issue #1249 (closed): long-session cache hit rate fluctuating 99% to 4% on oh-my-pi; the reporter estimated net negative benefit across 125 folds.

The README’s own diagnostic advice (/acp, /acp-cache for cache attribution) exists precisely because this is the dominant failure axis. If you trial it, cache hit rate is the metric to watch first, ahead of tokens saved.

What the GitHub issues show

1,667 open issues is an extraordinary backlog, even for a fast-moving pre-1.0 project, and the most-commented ones describe failure modes that are architectural rather than cosmetic:

  • Issue #6025: in proxy mode the model confuses historical queries with the current one, producing irrelevant answers.
  • Issue #5403: a 20k-message, 81 MiB-inbound session saw the host abort six times in two hours; resident-AST memory use was not bounded by sessions.hardMaxBytes.
  • Issue #1198 (closed): compression fired at high frequency during file reads, repeatedly pushing context back under 100K so the task could not complete.
  • Issue #2190 (closed): model-generated <acp> tags leaked into user-visible output.
  • Issue #3011: a zero-fold forked clone hit context_length_exceeded 400 on its first turn.
  • Issue #280 (closed): after a macOS sleep/wake cycle, compression never triggered and the session exceeded the window.

The release snapshot lists v0.1.211 through v0.1.218 in November. The title of issue #5624 reports that digest drift dropped to zero after an upgrade to v0.1.212.

License

One flag before adoption: GitHub records the license as a non-standard assertion (“NOASSERTION”), while the README links a LICENSE file and the in-repo paper is explicitly MIT. If you plan to run this inside a company, read the LICENSE file itself before deploying; do not assume MIT-equivalent terms.

A cost example (estimate)

Assume a heavy session sends 30M input tokens through the provider in a day at claude-sonnet-5-5 rates ($2/1M fresh input, $0.10/1M cache read; see current rates):

  • With a healthy 97% prefix-cache hit rate: 0.9M fresh × $2 + 29.1M cached × $0.10 = $1.80 + $2.91 = about $4.71.
  • With the billing share reported in issue #3837, 66.7% billed full price: 20M × $2 + 10M × $0.10 = about $41.

The two input estimates differ by roughly 8.7×. The README’s compression overhead of up to 2% describes a healthy session. To estimate input cost for your session, multiply fresh and cache-read tokens by their respective rates, then add any cache writes at the provider’s write rate.

Who should use it, who should skip it

Try it if you:

  • Run sessions long enough that context-window overflow, not per-turn cost, is the binding constraint
  • Are on a provider with real prompt-cache economics and are willing to monitor hit rate
  • Can tolerate pre-1.0 churn and a cert-MITM or URL-rewriting proxy in front of your model traffic
  • Prefer a self-spawning native plugin where supported. The README documents separate setup paths for Claude Code and Codex.

Skip it if you:

  • Use Claude Desktop’s Code tab (bypasses the proxy entirely today)
  • Need a mature, quiet codebase; the issue velocity here is high
  • Need predictable bill savings. The README estimates compression overhead at up to 2% in a healthy session, and the issue snapshot includes reports of lower cache reuse.

How to trial it safely

  1. Start with the launcher (bili <client>) in a scratch session using non-sensitive data. The proxy can read requests to configured provider hosts.
  2. Compare provider-reported cache reads and fresh input with an unproxied baseline. Use the README’s 96–99% range as a diagnostic reference.
  3. Ask the agent to recall a detail from early in the session; if answers start confusing old queries with current ones (the #6025 shape), that is your signal.
  4. Compare billed input totals for a trial week against a baseline week of similar work using the method in how to measure coding agent token savings.
  5. Keep bili plugin remove <client> and the .bili-bak snapshot in mind if you went the native route.

Alternatives and next reads

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

Billion Context Review: Model-Driven Compression for Month-Long Sessions. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/billion-context-review/

Sources