@moritakaaz/opencode-apcOpencode plugin for aggressive automatic context pruning - triggers compression at 15k tokens to save costs
0
47
近 7 天 13
26.6
生态多维模型
2 个月前
2026-06-07
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@moritakaaz/opencode-apc@1.2.2"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@moritakaaz/opencode-apc@1.2.2"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @moritakaaz/opencode-apcopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
An opencode plugin that wraps @tarquinen/opencode-dcp with aggressive auto-compression defaults. Triggers context pruning at 7k tokens to maximize token savings.
Installation
opencode plugin @moritakaaz/opencode-apc@latest --global
What it does
This plugin automatically manages your conversation context by:
- Compressing stale conversation content into high-fidelity summaries
- Triggering compression early (7k tokens) to save costs
- Deduplicating repeated tool calls
- Pruning errored tool inputs after 2 turns
- Nudging the model to compress every 3 turns with strong force
On first run, it creates dcp.jsonc config files (global and project-level) with aggressive defaults. Existing configs are never overwritten unless they were generated by APC (detected via _apcVersion field) and have an outdated version — in that case, they are automatically upgraded.
Configuration
The plugin writes .opencode/dcp.jsonc with these defaults:
| Setting | Value | Purpose |
|---|---|---|
| maxContextLimit | 7000 | Triggers compression early |
| minContextLimit | 3500 | Floor for compression target |
| nudgeFrequency | 3 | Nudge every 3 turns |
| nudgeForce | "strong" | Assertive nudging |
| deduplication | enabled | Remove duplicate tool calls |
| purgeErrors | turns: 2 | Prune errored inputs after 2 turns |
To customize, edit .opencode/dcp.jsonc in your project and remove the _apcVersion field — the plugin won't overwrite configs without this field.
Important: Config changes require an opencode restart. DCP reads config at session start — edits to
dcp.jsoncwon't take effect until you close and reopen opencode.
When to customize
| Workflow | Recommendation |
|---|---|
| Quick tasks, simple Q&A, small fixes | Use defaults (7k/3500) — maximum token savings |
| Multi-file refactoring, iterative debugging | Raise to 10k/5000 — more working memory |
| Complex code analysis, large codebases | Raise to 10k/5000 + moderate nudge — retain cross-references longer |
| Very long sessions with deep context | Raise to 12k/6000 — but costs more tokens |
Custom config example
For further optimization with more balanced context retention:
// .opencode/dcp.jsonc — custom config (no _apcVersion = plugin won't overwrite)
{
"$schema": "https://raw.githubusercontent.com/Opencode-DCP/opencode-dynamic-context-pruning/master/dcp.schema.json",
"compress": {
"mode": "range",
"permission": "allow",
"maxContextLimit": 10000,
"minContextLimit": 5000,
"nudgeFrequency": 4,
"nudgeForce": "moderate"
},
"manualMode": {
"enabled": false,
"automaticStrategies": true
},
"strategies": {
"deduplication": {
"enabled": true
},
"purgeErrors": {
"enabled": true,
"turns": 3
}
}
}
Differences from defaults:
| Setting | Default | Custom | Why |
|---|---|---|---|
| maxContextLimit | 7000 | 10000 | More working memory for cross-referencing multiple files |
| minContextLimit | 3500 | 5000 | Higher floor retains more detail after compression |
| nudgeFrequency | 3 | 4 | Less frequent nudging — more room for iterative work |
| nudgeForce | "strong" | "moderate" | AI uses its own judgment on when to compress |
| purgeErrors.turns | 2 | 3 | Error messages stay longer — useful for debugging |
Git and .opencode/ directory
The plugin creates a .opencode/dcp.jsonc file in your project. This file is safe to commit — it only contains DCP configuration and helps keep settings consistent across machines or collaborators.
The plugin also generates a .opencode/.gitignore that excludes runtime files (node_modules/, package.json, etc.), so only dcp.jsonc ends up tracked by git.
TL;DR: You can git add .opencode/ without worry. Only the config file will be committed.
Requirements
- opencode with plugin support (
@opencode-ai/plugin >=1.4.3) - Node.js with ESM support
Development
npm install
npm run build # tsc -> dist/
npm test # node:test unit tests
Error Handling
The plugin is designed to be resilient:
- If config files can't be written (permission denied, disk full), a warning is logged but the plugin continues
- If an existing config is malformed or missing required fields, a warning is logged but it's never overwritten (schema-only configs created by DCP are silently accepted)
- If
@tarquinen/opencode-dcpfails to load, the plugin returns empty hooks so opencode doesn't crash
CI
GitHub Actions runs build + tests on Node 20 and 22 for every push/PR to master.
License
ISC