Documentation
Everything you need to run billion-context locally and connect your agents. Exhaustive references live in the repository: docs/configuration.md, docs/technical-notes.md, docs/plugin-protocol.md, docs/session-identity.md.
Quickstart
One npm package, Node 22+. Install it, then start the local compression proxy:
npm install -g billion-context --prefix=~/.local # Node 22+ (nvm / Homebrew / Windows: drop --prefix)
bili # start the proxy (or: bili pi / claude / codex / omp / … to launch an agent through it)
Everything binds loopback only — nothing is exposed externally. Every instance serves the same built-in dashboard under its own address:
http://127.0.0.1:8787/__bili/
Next stop: the panel below — configuration, session stats, and live logs all live there.
Web UI
Access: open http://127.0.0.1:8787/__bili/ once the proxy is up — every instance serves this same built-in dashboard on its own loopback address (ACP_PORT overrides). Or just type /acp in your agent — the panel footer carries a direct link to the current session.
Every running instance serves a built-in dashboard at /__bili/:
- Overview — total sessions and requests, gross and net savings, global hit rate with miss breakdown, protocol distribution.
- Sessions — usage cards, context trajectory chart, cache economics with fold detail, compression blocks, and the Markdown handoff document (copy or download).
- Configuration — view and edit the JSON config; changes apply immediately.
- Connect — per-instance wiring guide with copyable commands.
- Logs — live tail of the daemon log, filterable by session id or keyword, downloadable as plain text.
- Blog — a few release notes and long-form articles rendered inside the panel itself: bundled with the install, offline-readable; the always-fresh full library lives on GitHub Pages.
Connect clients
Three ways to put the proxy between your agent and the model. Pick whichever fits your client:
Native plugin — recommended
Installs a thin plugin straight into the client (the original file is backed up once); deepest integration, with native in-conversation tools. Covers pi · omp · claude · codex · opencode · dsh · kimi · hermes · zcode:
Click any command chip to copy it.
For opencode, bili plugin install opencode --with-mcp also registers its MCP tools.
Launcher — works for any agent
Zero config edits: wraps any CLI agent and injects the proxy + compression state automatically. Each launch brings up a fresh throwaway proxy instance:
bili pi # or: bili codex / claude / omp / opencode / hermes /
dsh / codebuddy / qoder / trae / jcode / kimi / gemini / iflow /
qwen / mcode / aider / copilot / amp / goose (full list: bili --help)
Your own arguments pass straight through: bili pi -r.
Generic proxy — URL prefix routing
Any client that accepts a custom endpoint works out of the box: point its base URL at the prefix below, keeping the original upstream address as the tail:
http://localhost:8787/bili/https://api.openai.com/v1 # example
Replace the trailing https://api.openai.com/v1 with each client's original upstream address — see the table below for exactly where to put it.
Per-client integration detail:
| Client | Methods | Key mechanism | Command (click to copy) |
|---|---|---|---|
| pi | pluginlauncher | file-free extension + env | |
| omp | pluginlauncher | file-free env | |
| claude | pluginlauncher | env base URL + managed settings | |
| codex | pluginlauncher | config.toml provider / openai_base_url | |
| opencode | pluginlauncher | base_url (+ --with-mcp) | |
| dsh | pluginlauncher | --patch plugin · DSH_HOME overlay | |
| kimi | pluginlauncher | KIMI_CODE_HOME / managed OAuth | |
| hermes | pluginlauncher | HTTPS_PROXY + MITM CA | |
| zcode | plugin | native plugin · /bili/ prefix · GUI cert-MITM | |
| jcode | launcher | HTTPS_PROXY + CA (api.z.ai) | |
| gemini | launcher | GOOGLE_GEMINI_BASE_URL | |
| iflow | launcher | IFLOW_BASE_URL | |
| qwen | launcher | MITM · DashScope/Qwen hosts | |
| mcode | launcher | MiniMax yaml endpoints | |
| aider | launcher | OPENAI_API_BASE / .aider.conf.yml | |
| copilot | launcher | MITM · githubcopilot.com | |
| amp | launcher | MITM · ampcode.com | |
| goose | launcher | OPENAI_HOST / ANTHROPIC_HOST redirect | |
| trae | launcher | TRAE_CLI_API_HOST | |
| codebuddy | launcher | CODEBUDDY_BASE_URL | |
| qoder | launcher | MITM hosts whitelist |
Clients that hard-code HTTPS upstreams are handled by an automatic certificate: domains the client reaches are whitelisted on first sight. Need another host? Add it explicitly:
bili pi --mitm-domain api.foo.com
Commands
bili- Start the standalone proxy daemon (default port 8787).
bili <client>- Bring up a throwaway proxy + launch the chosen client against it — no config edits.
bili plugin install|list|update|remove- Manage the per-client plugins and their update lanes.
bili test pi- Non-polluting smoke test through the proxy.
bili export [session] [--full]- List sessions, or export one as a Markdown handoff document (--full restores original messages).
bili sessions ls|rm|archive|restore [id]- Manage persisted sessions: list with size and storage status, delete, archive or restore one by id.
bili storage gc [--days N] [--dry-run]- Run the storage sweep now: archive sessions past their age, release unreferenced content, shrink index.db (--dry-run prints the plan only).
bili doctor- Audit every install lane: versions, owners, running proxies (read-only).
bili update- Check for and install a newer version now.
/acp- Live context panel inside your agent — includes this session's web-dashboard link.
/acp-cache- Token economics report for the session: new content vs cache hits vs compression repay.
Configuration
Everything lives in one JSON file, created automatically on first run and hot-reloaded while you edit:
~/.config/billion-context/billion-context.json # { } is valid — defaults cover most setups
Configure it in the panel instead of by hand: the configuration page (here on a launcher agent's instance) validates every edit, offers quick-config controls, and writes this same file — environment variables still win over it when set.
Full parameter reference
Every knob in detail. Generated from the same seed as the repository's docs/configuration.md (CI drift-guarded), so the site and the repo docs stay one copy.
compress — every knob
| Parameter | Type | What it does |
|---|---|---|
| modelContextLimit | number | "N%" | Effective context window (tokens or "N%"): denominator of the usage ratio and a hard preflight wall. Highest-priority window source — overrides per-route / per-model declarations plus the top-level default. |
| maxContextLimit | number | "N%" | Forced-compression nudge threshold (default "75%"): once history passes this share of the window the nudge fires immediately, bypassing the growth gates. Not a hard cap. |
| emergencyThresholdPercent | number | % | Default "95%": emergency truncation of oversized tool outputs when history passes this share of the window (must be ≥ maxContextLimit). |
| outputHeadroomMaxPct | number | % | Cap (0–1, default 0.25) on the share of the window reserved for output via max_tokens. |
| nudgeGrowthTokens | number | Growth gate (default 50000): nudges fire only when a foldable range exceeds baseline growth by this many tokens. |
| tierNudgeTokens | object {t1?, t2?, t3?} | Per-tier token-mass trigger thresholds for the T1/T2/T3 paths; each unset sub-field keeps its derived value (T1 = growth step, T2/T3 = step × 1.5). |
| minPressureBenefitTokens | number (≥ 0) | Minimum reclaimable tokens for a pressure-band nudge to fire (default max(5000, limit × 1%)); explicit 0 restores legacy any-pending behavior (#3211). |
| requireUsageSampleForPressure | boolean | When the decision meter has no billing sample this round (aborted turn, short-TTL expiry), pressure-band nudges are deferred for at most compress.maxEstimateHoldRounds rounds (default 2) until either a usage-grade reading decides or the bound runs out and the estimate decides (legacy); billed readings keep byte-identical behavior while within the hold. Set false to restore immediate estimate-driven pressure injection. |
| maxEstimateHoldRounds | number | When the decision meter has no billing sample this round (aborted turn, short-TTL expiry), pressure-band nudges are deferred one round until a usage-grade reading decides; billed readings keep byte-identical behavior. Set false to restore estimate-driven pressure injection. |
| nudgeModelDecided | boolean | Model-decided nudge timing (off by default): an armed tier-1 nudge first asks the model, over the session's cached prefix, whether compressing now helps the current task; a strict-JSON yes injects a directive with a program-finalized span, anything else injects nothing this round. |
| nudgeDecisionMaxTokens | number | Output budget (tokens) of the model-decision side call (default 200). Must be > 0. |
| requireNudge | boolean | Forbid unprompted compression (off by default): a model compress call is refused unless a nudge credit is live — a delivered nudge opens a 20-model-round window, refreshed by each new nudge; the refusal returns an error receipt instead of folding. |
| requireRecommendation | boolean | Forbid out-of-bounds compression (off by default): only ranges bili currently recommends may be folded; subdividing a listed span or refolding an existing block stays legal. |
| postComPressTail | boolean | Off by default: the success receipt stops re-advising remaining foldable ranges and the uncovered-history note. Enable compress.postComPressTail to restore the recommendation (then at most once per nudge cycle). |
| streamSummary | boolean | Force streaming (SSE) summarization from the first attempt — stream-mandating upstreams now self-heal via a one-shot SSE probe on any non-streaming 400 (#2494); kept as the escape hatch for gateways that time out long non-streaming calls (e.g. Cloudflare 524), which the self-learn cannot detect, or to skip the one probe round-trip. |
| preserveRecentMessages | number | Kernel default 3 (tuned 5 → 3, #3058): the most recent messages stay soft-protected from folds. |
| preserveRecentTokens | number | Kernel default ≈5000: the most recent tokens stay soft-protected from folds. |
| minCompressRangeChars | number (deprecated alias: minCompressRange) | Smallest foldable range, in characters (kernel default ≈5000) — shorter ranges never fold. |
| maxSummaryLength | number | Hard cap, in characters, on one generated summary (kernel default 20000): longer replies are rejected whole by the kernel check or the external-summary executor. External summarizers receive this exact cap in their instructions (#3635); 0 disables the cap. |
| minSummaryLength | number | Floor, in characters, for generated summaries (kernel default 50): a single range must meet it on its own; a multi-range batch passes when its COMBINED summaries reach it — one lazy paragraph no longer sinks the whole batch (#5894). 0 disables the floor. External summarizers remain held to the per-summary floor (#3635). |
| reconcile | "off" | "warn" | "repair" | "off" | "warn" | "repair" (default repair): reconcile folded state when the client rewinds or rewrites history between turns. |
| promptPack | string (builtin: "default", "lean") | Compression prompt pack, resolved project pack → user pack → builtin. Builtins: "default" and "lean" (one-line tool descriptions). Not gated by acknowledgePromptsRisk. |
| tiers | boolean | On by default: tiered T1→T3 distillation spreads folding cost across generations. |
| protectedUserPatterns | string[] | Protect host-marked current-task prompts from folding (literal substrings). |
| protectedTools | string[] | Hard exclusion across all history: results of listed tools never fold (use with care). |
| protectedLatestTools | string[] | Protects only the LATEST instance of cumulative-snapshot tools whose newest result supersedes older ones (e.g. todo lists). |
| neverPreserveRecentTools | string[] ([] valid) | Excluded from the recent protection zone (immediately compressible); default ["decompress", "search_context", "read", "bash"]. An empty array is valid — it excludes nothing (maximum protection). |
| preserveRecentTools | string[] | Subtraction form: recent-zone tools minus this list get full protection. An empty array here is rejected as a typo. |
| visibilityMarkers | boolean | Append 📦/❌ visibility markers after compress/decompress/search_context/acp_status results (on by default; off stops imitated narration). |
| messageTimestamps | boolean | Message timestamps (#4313): first-sight wall-clock stamps shown as time= on compression tags, coverage spans in receipts and Occurred lines in summaries; ON by default. Set `compress.messageTimestamps: false` or env BILI_MESSAGE_TIMESTAMPS=0 to keep every byte identical to pre-feature master. Env wins when defined (0 forces off, any other value forces on); resolved once per instance — changing the flag needs a restart, and the first restart with the flag on pays one frozen-prefix cache rewrite per active session. |
| rules | boolean | Off by default: persistent model reminders delivered through an injected acp_rule tool, hard-protected from folds. pi/omp expose an /acp-rule command. Proxy-mode only — inert in plugin mode. |
| injectTool | boolean | Register the acp_compress tool for clients (on by default; global level only). |
| injectNudge | boolean | Send growth nudges as the window fills (on by default; global level only). |
| reasoning | { drop?, threshold?, tail? } | { drop?, threshold?, tail? } — drop finished-round reasoning runs longer than 2048 chars (drop: true by default; tail: false keeps it scoped to compress turns only); strict-reasoning upstreams need drop:false. |
absorb— opt-in instant distillation of tool results into short abstracts; originals go to the content store; by default only image-bearing results qualify (enabled, minToolTokens (default 1000), contextThresholdPct, excludeTools, mediaOnly (default true), toolName "absorb").degenerateRetry— retry budget for zero-visible-output turns; the continuation nudge rides the retry body only, never persisted (maxAttempts (default 1, 0 = off, max 5), nudges (1–8 custom sentences)).blockOps— opt-in compressed-block lifecycle tools (acp_retire / acp_restore / acp_rewrite); off by default so the wire surface stays byte-identical to pre-#5765 (enabled).ccr— content cache & retrieve: large outputs are stored losslessly beside the session and replaced by a head excerpt plus pointer; the model fetches originals back viaacp_retrieve. No cap or eviction; on by default in proxy mode since v2 (enabled, minToolTokens (~4000), excludeTools, toolName "acp_retrieve", maxHeadChars).search— search-behavior settings for search_context; currently holdsplanAware.search.planAware— off by default: when on, search_context candidates are re-ranked against current plan state (latest-wins todos + last user turn); off keeps byte-identical lexical results.prompts— override the kernel doctrine texts (compressPhilosophy, howToCompressRules, tier2DistillRules, tier3CondenseRules); load-bearing for quality — gated behind acknowledgePromptsRisk.reasoningGuard— auto-repair of reasoning-lattice truncation on gpt-5.x/6.x (≤3 continue-nudge rounds, marker "Continue thinking...") (enabled, maxContinue, maxTierN, markerText, base, offset, debugLog).outputSteering— { enabled? false, verbosityLevel? 2 (0–4), effortRouting? }: appends a conciseness directive to the system-prompt tail; clamps mechanical continuation requests.priceProfile— w / r / q ratios normalized to the input price (write / cache-read / output); unset ⇒ models.dev $/Mtok registry rows, kernel fallback {1, 0.1, 4}. Report-only — never affects triggers or the wire.externalSummary— optional chain of external summary models, each target a "provider/model" reference into theproviderstable; disabled unlessenabledis true, targets tried in order with fall-through (enabled, targets, budget {totalTimeoutMs, targetTimeoutMs, maxSummaryBytes}, concurrency, autoFold, autoFoldTargetTokens). Whole-chain replace semantics at all three compress levels.acknowledgePromptsRisk— must be true before custom prompts take effect.
providers — route table fields
Keys are upstream URL prefixes — longest match wins, boundary-safe. https:// keys match /bili/ traffic; mitm:// keys match login-client traffic on the MITM lane. An entry with no fields is still an ordinary compressed lane.
| Field | Type | What it does |
|---|---|---|
| models | record name → { context?, output?, compress?, benefit? } | Record of model name → {context?, output?, compress?, benefit?}: declares each model's context window, output ceiling, and per-model compression overrides (benefit marks free-quota billing). Not a traffic filter. |
| proxy | string ("" = explicit direct) | Per-route outbound proxy URL; empty string = explicitly direct. |
| compressProtocol | "tools" (default) | "marker" | Which ACP injection surface this lane speaks: native tools (default) or prompt markers. |
| protocol | "anthropic" | "openai" | "responses" | "google" | Declare this lane's wire protocol. A client-side /bili/<protocol>/ URL marker outranks the declaration; unparseable bodies relay verbatim. |
| compress | object (level 2) | Any compress field can be overridden here — level 2 of the global→provider→model merge (per-field, deepest wins). |
| compat | { roles?, dropFields? } | { roles?, dropFields? } — remap roles the upstream rejects (e.g. developer→system); provider entries beat the global block per key; dropFields strips fields strict schemas reject (additive union). |
| direct | boolean | Client-side exemption: traffic for this upstream is never pointed at bili at all — unlike passthrough, it does not even terminate there. |
| passthrough | boolean | Route-scoped byte-for-byte relay with no session state — for anti-fraud upstreams. |
| imageBilling | "auto" | "pixels" | "bytes" | Image-token counting basis for this route: auto (→ pixels), pixels, or bytes (explicit opt-in for byte relays). |
| imageTokenCap | number | Per-image token cost cap for this route; unset = uncapped. |
| resign | scheme → { enabled?, passthrough?, credentialRef? } | Per-route overrides of the global resign map (level 2, deepest wins). |
| bind | string (named entries only) | Named (non-URL) entry: deep-merged onto the bound URL lane at config load as an alias. Without bind a named entry stays routing-inert. |
| apiKeyEnv | string (env var name) | Lane credential override (#2336): requests forwarded through this lane carry this env variable's value instead of the client's own credential — x-api-key / x-goog-api-key replaced outright, Bearer authorization replaced, injected when absent. Exactly one of apiKeyEnv / credentialRef per entry. |
| credentialRef | string (store name) | Lane credential override via the private summary-credential store (`secret:NAME` semantics); exactly one of apiKeyEnv / credentialRef per entry. |
| calibration | { disabled?: boolean, max?: number } | Per-route k̂ calibration policy (#3211): `disabled` suppresses the learned factor on this route; `max` clamps it (0 < max ≤ 4). Applied at publication time — the learned ring stays raw. |
| compactionOptIn | boolean | Named entries only: opt a non-http(s)-baseUrl provider into compaction ownership (pi/omp lanes); unions with env BILI_NON_HTTP_PROVIDERS. |
Other top-level fields
- Server & core
port— listen port (default 8787).host— bind address (default 127.0.0.1; "::" is dual-stack, 0.0.0.0 exposes outward).sessionHeader— HTTP header carrying the session id (default x-acp-session).log— file logging master switch (on by default).logFile— explicit path for bili.log (env ACP_LOG_FILE wins).debug— verbose per-request logging.dumpSse— raw SSE stream dump level for debugging.passthrough— global raw-relay switch (off by default; ACP_PASSTHROUGH / --passthrough win over the file).- Upstream & billing
upstream— fallback upstream base URL (ACP_UPSTREAM overrides).proxy— global outbound proxy. Resolution: per-route → BILI_UPSTREAM_PROXY → Web UI → this value → HTTP(S)_PROXY env → Windows system proxy → direct. Empty string = explicitly direct; SOCKS5 is rejected.modelEndpointPatterns— declare model endpoints on non-standard paths (URL prefix → wire family); empty = built-in path tables only.modelContextLimit— legacy global DEFAULT window (default 200000): last-resort fallback when no other source resolves a limit for the model; does NOT cap a natively-resolved window (#5908); prefer compress.modelContextLimit.imageBilling— global image-token estimation: "auto" (default → pixels), "pixels" or "bytes" (explicit opt-in for byte relays).imageTokenCap— global per-image token cap; unset = uncapped (BILI_IMAGE_TOKEN_CAP wins, read live).imageRescale— egress downscale switch; large outbound images sent shrunken, originals kept byte-exact in session storage.egressTransforms— user-registerable egress body-rewrite pipeline (ESM plugins, fail-open, hot-reloadable).billing.prices— per-model USD/Mtok prices feeding the panel's spend + savings views.- Behavior toggles
rollout— canary gating: features enable for a percent of installs, bucketed on a stable per-machine UUID; nested base rolls B out only inside A's cohort.maskHosts— mask non-public host names in logs as <private-host> (on by default; credentials are always masked).security.adminRelay— relay the /__bili/ admin surface through the embedding host's web entry (off by default; fail-closed).subagentSplit— Claude subagents get their own session namespace (on by default).personaSplit— Responses-wire instructions-fingerprint split (on by default; set false / BILI_PERSONA_SPLIT=0 to opt out).forkAdoption— adopt anonymous forks into their parent session (off by default).autoModeForge.enabled— answer Claude Code auto-mode classifier calls locally with a forged allow verdict (on by default;BILI_AUTO_MODE_FORGE=0= pure passthrough).affinitySimhash— simhash chain-alignment re-attaches sessions after pervasive client rewrites (on by default).resumeInheritance— inherited refs/blocks on resume (cc --resume) (on by default).chainContentDetection— recognize bili-owned traffic by body content (off; false-positive risk).chainEgressStamp— model-visible stamp on egress messages (off; burns tokens).stableSystemAnchor— best-effort wire-layer prefix-cache anchor (off; plain-proxy lanes).compat— wire-compatibility block: role remaps, stream error shape, strict-schema field drops, cache-control handling.- MITM lane
providersPath— external routes file path (env ACP_PROVIDERS beats both it and inline providers).mitm.enabled/mitm.domains— HTTPS interception switch and whitelist domains for login clients.mitm.handshakeTimeoutMs— TLS handshake timeout (default 10000).- Process blocks
network— transport timeouts, replays & the 429 egress governor: upstreamTimeoutMs 720000 · upstreamFirstByteMs 720000 · requestWatchdogMs 2× · replayRetryMax 3 · replayRetryBaseMs 1500 · keepAliveTimeoutMs 5000 · clientErrorBackstopMs 30000 · exposureLogIntervalMs 3600000 · streamKeepAliveMs 15000 · preflightHoldMs 30000 · preflightDeadEndCooldownMs 300000 · proxyKeepAliveMaxMs 55000 · throttle429Enabled false · throttle429MaxConsecutive 5 · throttle429BaseDelayMs 2000 · throttle429MaxDelayMs 30000 · throttle429Scope credential.guardrails— pi/omp plugin tool-output + stream text-run guardrails: bashTimeout 60 · maxOutputBytes 50000 · repetition true · textRunThreshold 200.persist— session persistence to disk: enabled true · zstd false · debounceMs 500 · maxDelayMs 5000 · tailTokens 16384 · epermAlertThreshold 5 · epermAlertRepeatMs 0.sessions— session pool & GC: max 256 · warmMax 0 · warmMaxBytes 67108864 · residentMaxBytes 4294967296 · hardMaxBytes = residentMaxBytes · gc { enabled false · maxAgeDays 7 · maxTokens 1000000 · intervalMs 3600000 }.storage— unified storage sidecar: unified legacy — file tier selects the lane-wide storage mode; env BILI_STORAGE_UNIFIED wins when set.update— self-update channel: registry "npmjs" · checkIntervalMs 180000.- Diagnostics & updates
diagnostics— local troubleshooting knobs: dumpBody false · dumpReq true · rawDumpDir · dump4xx false (+MaxBytes 2 MiB) · renderNone/noInjectTool/noCompressPrompt false · countTokensPassthrough false · compressProtocol "tools".fakeCompletion— retry loop for truncated final chunks: retries 0 (opt-in) · bufCapBytes 16 MiB.autoUpdate— automatic version checks (on by default; disable via ACP_AUTO_UPDATE=0 or --no-auto-update).autoRestartOnUpdate— restart the daemon automatically once a newer version is installed (opt-in).updateTag— npm dist-tag channel: latest (default), dev, or pr.advisoryCheck/advisoryUrl— critical-defect advisory watcher (on by default; force-installs the recommended fix when your version is affected).releaseNotesCheck/releaseNotesUrl— release-notes feed for the panel (on by default; fetch + cache only, never installs).- Advanced scalars
codexCompact— intercept | pass (default intercept): handle Codex's compaction requests in bili or forward upstream — explicit forms plus the inline auto-compact transiting as an ordinary turn (prompt-form detection, #3008; overridden compact_prompt transits verbatim).ccrRetrievalTtlMs— lifetime of CCR retrieval pointers (default 600000; 0 disables retrieval).decompressTmpCap— size cap for temporary decompressed blocks (default 50).native.attachExternal— let launcher-less native plugins attach to an external daemon (off by default).
Environment variables win over the config file — precedence: env > file > built-in default, and a set variable owns the knob even if its value looks invalid. Common ones:
ACP_PORT=8787 # listen port
ACP_HOST=127.0.0.1 # bind address
ACP_UPSTREAM=https://api.anthropic.com # fallback upstream base URL
ACP_PASSTHROUGH=1 # force passthrough on (wins over file)
ACP_PROVIDERS=/path/to/routes.json # external routes file (beats inline)
BILI_CONFIG_FILE=~/.config/... # override the config file path
BILI_SESSIONS_DIR=~/.local/share/... # where session records are stored
BILI_UPSTREAM_PROXY=http://host:port # outbound egress proxy
ACP_MODEL_CONTEXT_LIMIT=200000 # global context window override
BILI_MITM_DOMAINS=api.foo.com # add MITM whitelist domains
BILI_REPLAY_RETRY_MAX=3 # transport-failure replays
BILI_SESSION_GC=1 # enable session garbage collection
BILI_IMAGE_TOKEN_CAP=8192 # per-image token budget
BILI_SUBAGENT_SPLIT=0 # disable subagent session split
BILI_FORK_ADOPTION=1 # adopt anonymous forks into parent session
ACP_LOG_FILE=/path/to/bili.log # explicit log path
ACP_COMPRESS_TOOL=0 # disable the injected compress tool
ACP_COMPRESS_NUDGE=0 # disable growth nudges
How compression works
The same four mechanisms as the front page, condensed:
- Folded, not rewritten When history outgrows its budget, only the newly consumed slice is folded into a compact summary block — once, per block. The window oscillates in a bounded band instead of growing without limit: production sessions run months at ten-thousand-plus calls. Any block decompresses back to full text when you need the detail.
- The provider's cache stays warm A fold deactivates old ranges without touching the front of the conversation, so the prompt-cache prefix survives turn after turn — 94.2% of active input was served from cache in the study. Rewrite-style compaction invalidates the whole prefix and re-bills it. This does not.
- The model decides what to forget A versioned compression doctrine lives in the system prompt; a growth-gated nudge says when folding pays off. The agent judges what the task still needs, may refuse, and compresses between steps — never mid-step.
- Every token is accounted Each request is sampled into a per-session ledger — new content, cache reads, compression repay, TTL expiry — plotted in percentage points on a trajectory chart. Audit real savings with
/acpin the terminal or the built-in web UI at/__bili/.
The full treatment, with numbers: read the preprint.
Privacy
billion-context runs only on your machine and binds loopback by default. It forwards model traffic — OAuth tokens pass through untouched, unauthenticated probes aside — and uploads nothing.
Session records stay local (~/.local/share/billion-context/sessions); the log sits beside the state dir. Export any session with bili export, delete files whenever you like.
FAQ
Which Node version?
Node 22 or newer — required by the npm package.
Does it work on Windows?
Recommended: WSL2. Inside WSL everything uses 127.0.0.1 as usual; a Windows-side client should reach the proxy via the WSL host IP, or simply run the client inside WSL too.
Do I pay for the proxy itself?
No — it's free and open source (MIT plus an attribution clause). Token savings come from smaller contexts and your provider's prompt caching; the economics panel shows the real per-session numbers.
How do I upgrade?
Run bili update (or reinstall via npm). Use bili doctor before and after to audit every install lane.
I can't reach the dashboard?
Check the daemon is running (bili doctor) and the port isn't changed (default 8787 for the standalone daemon; launcher lanes start at 18787). The dashboard binds 127.0.0.1 only — from another machine or phone you need an SSH port-forward or an explicit ACP_HOST setting.
How do I check my cache hit rate?
Don't dig through logs — type /acp-cache in your client: a summary report prints in the terminal headed by a clickable Web UI link (the session page adds the hit-rate chart plus per-break attribution). Rule of thumb: a healthy session sits at 95–97%; compression itself costs ≤2%. When lower, the usual suspects in order: ① upstream cache-TTL expiry, ② a mid-session model switch (re-bills the whole stable prefix), ③ a bili bug — report it with the page attached. /acp-cache full lists every fold & line item; HTTP equivalent: GET /__bili/cache-report.
What does /acp show?
In clients with the native plugin (opencode, dsh), /acp renders the ACP status panel of the current conversation straight from the proxy — session, blocks, compressible ranges, usage; before the first model request it shows an idle notice. /acp-cache [full] prints the cache report above.
Can I query sessions and config over the web?
Yes — open http://localhost:8787: overview dashboard, session list with per-session detail, live logs, a config editor, and an upstream connectivity test. Everything is also plain JSON for scripting (/__bili/stats, /__bili/sessions, /__bili/config, …).
When does compression happen?
It is model-driven: the injected context tools are called by the model as context grows, growth nudges (~50K-token steps by design, adjustable via compress.nudgeGrowthTokens) prompt it along the way, and preflight fires as a hard backstop when the input alone exceeds the window. Watch it live with /acp or the web UI.
Why does the first compaction wait until ~200k?
Compaction triggers on growth intervals, not absolute window position: by default the first soft compaction fires 50k tokens past the boot content (compress.nudgeGrowthTokens, flat and window-independent) — with a ~100k boot it may wait until ~200k. To make it fire earlier: trim the system prompt / disable unneeded tools / prune skills, lower compress.nudgeGrowthTokens to ~50k, or enable lean mode.
Is bili transparent? How do I turn it off?
Unrecognized endpoints forward unchanged, and every mode reverses cleanly: bili plugin remove <client> for native installs; stop using the launcher command / env vars / /bili/ prefix for the other two — traffic goes direct again immediately. Per-client mechanics: docs/clients.md.
Where are logs and session data stored?
Log: ~/.local/state/billion-context/bili.log (also mirrored to stderr); session state: ~/.local/share/billion-context/ (XDG-overridable). Full paths: docs/configuration.md.
Resources
- billion-context — GitHub
- acp-kernel — the compression kernel
- npm package
- Paper / preprint
- QQ: 1056132097 / 1108730198