百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

opencode-acp

> 编程语言
开源

主动上下文压缩 — 由模型驱动的 OpenCode 上下文管理,20w token 就足够了。

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

主动上下文压缩 — 由模型驱动的 OpenCode 上下文管理,20w token 就足够了。

English | 中文

Active Context Pruning for OpenCode

The model decides when and what to compress — not a hard limit.

200K tokens is enough.


Paper / Preprint

  • Model-Driven Incremental Hierarchical Compression: Training-Free Multi-Generational Context Management for Long-Lived Coding Agents (English, v0.2)

The paper itself is open-sourced under the MIT License as part of the codebase (paper/). It is a living document — anyone may edit it; improvements are welcome via pull request.

A production-scale longitudinal study: 4.5 months, 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.


opencode plugin opencode-acp@stable --global


Community

Discussion, help, and updates on QQ — one group covers all three projects (billion-context, billion-context-pi, opencode-acp):

QQ Group: 1056132097


Why ACP

ACP hands all context-management authority to the model itself — not relying on external models or any complex external mechanism to do context management. It is, to date, the best context-management implementation on the market.

This brings two concrete effects:

  • 200K tokens is enough. Across 30,000+ API calls in 50 real engineering sessions, 97% of requests stayed under 200K tokens — p90 at 150K, p95 at 180K. Every API call re-bills the full context, so keeping context low directly reduces cost — even with a 90%+ prompt-cache hit rate, the non-cached portion is billed at full price.
  • It supports ultra-long sessions without losing key content — observed at 3,300+ messages and 300M+ cumulative tokens per session; architecturally supports up to 100,000 messages (5-digit message-ID space).

Which do I need?

Pick by your client:

Client Use
pi billion-context-pi (in-process extension)
opencode opencode-acp (in-process extension)
omp billion-context via bili omp (built-in plugin)
everything else (no context hook) billion-context — bili (launcher, preferred) or /bili/ prefix

Proven at scale

Real engineering context, in practice.

Across 6 active engineering sessions (11,000+ API calls), context p90 stays at 150K–190K (15–19%), p95 at 160K–210K (16–21%) of the 1M window — with an aggregate prompt-cache hit ratio of 91%. (Why aggregate — not per-session — matters is explained in Impact on Prompt Caching, where it turns out to save far more tokens than traditional compression.)

Session Duration Messages API calls Cumulative Cache hit Context p50 Context p90 Context p95
0b89319b 230h (9.5d) 3,344 2,796 339M 93% 108K (11%) 167K (17%) 210K (21%)
0a3be0cd 130h (5.4d) 3,183 2,499 276M 91% 104K (10%) 145K (15%) 153K (15%)
0b2cd5a7 131h (5.4d) 2,560 2,181 314M 91% 142K (14%) 191K (19%) 197K (20%)
08f2d501 37h (1.5d) 1,985 1,888 196M 95% 100K (10%) 156K (16%) 168K (17%)
1410c791† 865h (36d) 1,279 1,100 218M 87% 132K (13%) 407K (41%) 427K (43%)
096cf8c4 72h (3d) 1,041 918 91M 89% 92K (9%) 148K (15%) 161K (16%)

† Bug-testing session; p95 is abnormally high. Excluding it, p95 stays ≤ 210K across all other sessions.

(Context percentages are of the 1M window.)


Installation

bash
opencode plugin opencode-acp@stable --global

Or add to your opencode config:

json
{
    "plugin": {
        "opencode-acp": "stable"
    }
}

How It Works

ACP hands the context-compression tool directly to the model. The model is 100% responsible for context compression. The model's primary tools are compress and decompress, supported by acp_status (context monitoring) and search_context (search compressed content). Compression uses a three-tier LSM-tree architecture (T1 capture → T2 distill → T3 condense) that keeps context bounded for years. A hardcoded 100% GC fallback acts as a safety net when the context window is completely full.

Lifecycle — Three-Tier Compression

ACP uses a three-tier LSM-tree compression architecture, inspired by database storage engines. Each tier compresses the previous tier's output, creating progressively denser summaries with natural frequency decrease:

mermaid
stateDiagram-v2
    Raw --> Tier1 : compress (every ~7 turns)
    Tier1 --> Tier2 : distill (every ~250 turns)
    Tier2 --> Tier3 : condense (every ~2500 turns)
    Tier1 --> Raw : decompress
    Tier2 --> Raw : decompress (recursive)
    Tier3 --> Raw : decompress (recursive)
    Tier1 --> GC_Truncated : GC at 100% context
Tier Name Input Output Compression ratio When it fires
T1 Capture Raw conversation Detailed summary ~45× Context exceeds maxContextLimit
T2 Distill T1 summaries (≥ nudgeGrowthTokens) Condensed decisions/outcomes ~10× T1 summaries accumulate past threshold
T3 Condense T2 summaries (≥ nudgeGrowthTokens) Bare facts (1-3 per block) ~5× T2 summaries accumulate past threshold

How triggers work:

  • T1 fires when raw context exceeds the configured limit. The model sees compressible ranges and writes a detailed summary preserving file paths, signatures, decisions, and rationale.
  • T2 fires when T1 summary tokens reach nudgeGrowthTokens (fixed default 50000). The model distills old T1 blocks — keeping decisions and outcomes, dropping verbose process details.
  • T3 fires when T2 summary tokens reach the same threshold. The model condenses to bare facts (shipped releases, key bugs, architecture decisions).

Each tier has an independent cadence counter — T2 firing doesn't block T3. T1 has priority via a !shouldInject guard: if T1 fires, T2/T3 wait until next turn. This ensures raw context compression happens first (it has the biggest impact).

Session capacity — total tokens a single session can process from empty → T1 → T2 → T3 → context limit (real-calibrated: 500 API calls/day, ~9.6K new tokens/call, T1=45x/T2=10x/T3=3x):

Context limit 1 month 3 months At limit Limit reached
1M 1.9B tok 10.5B tok 68.9B tok day 259 (~8.6 mo)
400K 1.9B tok 10.3B tok 10.3B tok day 89 (~3 mo)
400K (200 calls/day) 559M tok 2.5B tok 9.5B tok day 212 (~7 mo)

Token savings — without ACP, context grows unbounded and the session crashes after ~100 API calls (~0.2 days). With ACP, context is bounded by compression:

Metric Without ACP With ACP (1M model)
Session lifetime ~0.2 days 259 days (1295x longer)
Total tokens processed ~52M 68.9B (1325x more work)

The core value: ACP doesn't just reduce per-call token cost — it enables a single session to process 1000x more total work by keeping context bounded across the full session lifetime.

The model uses the same compress tool for all tiers. T2/T3 compressions use block IDs as boundaries (compress({ content: [{ startId: "b5", endId: "b20", summary: "..." }] })). Tier is auto-detected from consumed blocks.

Compression strategy (Tier 1)

The system injects a prompt telling the model the current context ratio, the compression ratio, whether context is idle, and compression suggestions. When the trigger ratio is hit, content is compressed in priority order:

  1. Agent/subagent review & consultation results (largest block of uncompressed content)
  2. Verbose command output (build/test runs, git diff/log/status, directory listings)
  3. Exploration that led nowhere (failed approaches, dead-end searches)
  4. Redundant tool results (reading the same file repeatedly, repeated status checks)
  5. Intermediate steps of completed multi-step tasks
  6. Resolved discussion threads (once a decision is recorded)
  7. Large file contents already used

After compression, the original content is replaced by a short block that references the original (recoverable via decompress).

Decompression strategy

The model decides when to decompress. When the context is large enough to interfere with the model's self-attention, short blocks lead the model to compress some content first, handle the urgent matter, then decompress what it needs in later work.

GC safety net

When context reaches 100%, the system automatically truncates old-gen block summaries to prevent overflow. This is a last-resort safety net — with three-tier compression, the GC rarely activates because T2/T3 distillation keeps summary overhead bounded.

Quality gate (non-blocking, off by default)

After each compress call, ACP can run a pluggable quality gate to detect summaries that catastrophically lost content (e.g., a 5K-token range compressed to a 147-char summary with none of the technical keywords). Failures only emit logger.warn — they never reject the compression (the result is already committed to state and visible to the model).

The default algorithm (rouge-recall-v1) is a two-layer gate calibrated against 6,913 real-world blocks:

  • L1 (length floor): Catches catastrophic retention failures — summaries shorter than 200 chars OR with ** Full parameter reference:** See CONFIGURATION.md for a complete reference of every configurable parameter with type, default value, and description.

[!IMPORTANT] Disable OpenCode's built-in auto-compaction. ACP handles context management itself — OpenCode's compaction conflicts with ACP and can cause issues (re-expanded messages, lost compression state). Add to your opencode.json:

jsonc
{
    "compaction": {
        "auto": false,
    },
}

Or set the environment variable: OPENCODE_DISABLE_AUTOCOMPACT=1

[!NOTE] If you use models with smaller context windows, such as GitHub Copilot models or local models, lower compress.minContextLimit and compress.maxContextLimit in your configuration to match the available context.

Default Configuration (click to expand)

…

jsonc { "compress": { "maxContextLimit": "80%", "providers": { "anthropic": { "nudgeGrowthTokens": 20000, "models": { "claude-sonnet-4.6": { "maxContextLimit": "70%", "nudgeForce": "strong" } } }, "openai": { "nudgeGrowthTokens": 40000 } } } }


Resolution is **per field**: model > provider > global. Unknown provider/model IDs fall back to the global value. A nested `maxContextLimit` also wins over the legacy flat `modelMaxLimits` map. Overrides deep-merge across the three config layers (global → config dir → project) per provider/model key.

Not overridable here: `permission`, the deprecated `minContextLimit` / `modelMinLimits` family, and the flat `modelMaxLimits` / `modelMinLimits` maps themselves. Note: `modelMaxLimits` is **not** deprecated — it stays fully supported; a nested `maxContextLimit` simply outranks it.

See the [`compres

Issues· 35 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言