# billion-context

> A proxy that compresses long coding-agent chats so one session can run for weeks

- Repository: https://github.com/ranxianglei/billion-context
- Category: Token & cost savings
- Stars: 2,417 · Forks: 207 · Language: TypeScript · License: not stated
- Experience: Some experience
- Page: https://ir.adyog.com/repos/ranxianglei/billion-context/

Long coding sessions fill the model's context window, and providers charge per token. When the window is full, the session gets worse or stops. billion-context tries to keep one session going for days by compressing the parts of the conversation already used.

It works as a proxy. You start your agent with a `bili <client>` launcher, or point its base URL at the proxy. The proxy reads each request (Anthropic or OpenAI format), runs compression from the acp-kernel library, adds four context tools, forwards the request to the real model API and rewrites the streamed reply.

The README says it differs from a host's built-in summarizer in three ways. Compression is incremental, so summaries cover small ranges. It is reversible, so the model can restore the original text. And it keeps the prompt prefix stable, so the provider's prefix cache still works. The model decides when and what to compress. The README links a paper with a 4.5-month field study; those figures are the authors' own.

## What it does

- **Model-driven compression**: The proxy adds a `compress` tool. The model calls it to fold a range of messages into a detailed summary, and the proxy runs it server-side.
- **Reversible summaries**: `decompress` restores a compressed range when exact details are needed again. `search_context` searches both summaries and visible messages.
- **Context usage overview**: `acp_status` shows how much context is used and which ranges can still be compressed.
- **Many supported clients**: A table covers Claude Code, Codex, OpenCode, pi, Gemini CLI, Aider, Goose, Zed and others. Each has a launcher, a native plugin, or a `/bili/` URL prefix, depending on what the client allows.
- **Cache diagnostics**: The `/acp` and `/acp-cache` commands help find out why the prefix-cache hit rate is low.

## What you could build

- Run a single Claude Code or Codex session for days without it hitting the context limit.
- Cut token spend on long agent sessions by compressing history already used.
- Work with a model that has a small context window, around 100K tokens.
- Search and restore older parts of a long session when exact details are needed.
- Read the linked paper to study how multi-generation context compression works.

## Who it's for

Developers who run coding agents for long sessions and are comfortable with the command line, npm and proxy or base-URL settings.

## Get started

Install the package with npm, then find your client in the README's table and start it through the matching launcher, for example `bili claude` or `bili codex`. Some clients use `bili plugin install <client>` instead.

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

Tags: context-compression, proxy, coding-agents, token-savings, llm
