Package Exports
- @tuanhung303/opencode-acp
- @tuanhung303/opencode-acp/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@tuanhung303/opencode-acp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
OpenCode Agent Context Pruning (ACP)
Automatically reduces token usage in OpenCode by removing redundant or obsolete content from conversation history.
⚡ Performance Fork: Optimized with aggressive defaults and four additional pruning strategies: Prune Thinking, Head-Tail Truncation, Read Consolidation, and Placeholder Compression.
Pruning Architecture
graph TD
A[New Turn] --> B{Strategy Type}
subgraph "Automatic (Zero Cost)"
B --> C[Deduplication]
B --> D[Supersede Writes]
B --> E[Purge Errors]
B --> F[Read Consolidation]
B --> G[Prune Thinking]
B --> H[Head-Tail Truncation]
C --> |Removes identical calls| I[Context Saved]
D --> |Prunes writes after reads| I
E --> |Strips failed call inputs| I
F --> |Stale reads point to new| I
G --> |Strips reasoning/thinking| I
H --> |Middle-out truncation| I
end
subgraph "LLM-Driven (High Precision)"
A --> J[AI Nudge]
J --> |Suggests Cleanup| K{Agent Action}
K --> L[Discard Tool]
K --> M[Extract Tool]
L --> |Direct removal| I
M --> |Summarize then remove| I
endInstallation
Add to your OpenCode config:
// opencode.jsonc
{
"plugin": ["@tuanhung303/opencode-acp@latest"],
}Core Strategies
🚀 Automatic Strategies (Instant & Free)
- Head-Tail Truncation (⚡ Default): Preserves the first 20% and last 30% of tool outputs, removing the middle section. Optimized for the "Lost in the Middle" phenomenon.
- Read Consolidation: When the same file is read multiple times, older outputs are replaced with pointers to the newest version.
- Prune Thinking: Strips ephemeral reasoning blocks (Claude
<thinking>or OpenAIreasoning) from older messages. - Supersede Writes: Automatically prunes
writetool inputs once a subsequentreadof the same file confirms the state. - Deduplication: Eliminates identical tool calls while preserving the most recent result.
- Purge Errors: Automatically clears inputs from failed tool calls after 2 turns.
🧠 LLM-Driven Tools
discard: The agent manually removes tool content that is no longer relevant to the current task.extract: The agent distills valuable findings into a concise summary before purging the raw data.
Configuration Defaults
This fork utilizes more aggressive defaults than the upstream version to maximize context efficiency:
| Feature | Upstream | ACP Fork |
|---|---|---|
purgeErrors.turns |
4 | 2 |
nudgeFrequency |
10 | 5 |
supersedeWrites |
Disabled | Enabled |
pruneThinking |
N/A | Enabled |
headTailTruncation |
N/A | Enabled |
Configuration File
The plugin automatically creates a config at ~/.config/opencode/acp.jsonc. You can also use project-level overrides in .opencode/acp.jsonc.
{
"strategies": {
"pruneThinking": { "enabled": true, "delayTurns": 1 },
"headTailTruncation": {
"enabled": true,
"headRatio": 0.2,
"tailRatio": 0.3,
},
"readConsolidation": { "enabled": true },
},
}Commands
/acp context: Visualize token usage and savings./acp stats: Cumulative efficiency report./acp sweep: Force a manual cleanup of the current session.
License
MIT