@qdang46/opencode-dcp-plugin
v1.0.0
Published
OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context (full parity port of @tarquinen/opencode-dcp, rebranded as ◆ DCP rust)
Maintainers
Readme
@qdang46/opencode-dcp-plugin
Dynamic Context Pruning plugin for OpenCode
Full-parity TypeScript port of @tarquinen/opencode-dcp (v3.1.x). Same hooks, TUI panel, compress tools, notifications, persistence, and config as upstream.
Installation
Local (dev / pin)
In both ~/.config/opencode/opencode.jsonc and ~/.config/opencode/tui.json:
{
"plugin": [
"file:///Users/you/Projects/dynamic_context_pruning/opencode-dcp-plugin"
]
}OpenCode 1.17 loads TUI plugins from
tui.jsonseparately from server plugins inopencode.jsonc. Use an absolutefile://path (outsidenode_modules) so OpenTUI JSX transforms correctly (opencode#33884).
npm
opencode plugin @qdang46/opencode-dcp-plugin@latest --globalRestart OpenCode completely after install.
Usage
| Command | What happens |
|---------|----------------|
| /dcp | TUI dialog panel — Context / Stats / Manual mode / compress prompt hint |
| /dcp-compress [focus] | Chat slash: queues a manual compress prompt; model must call compress |
| /dcp context | Ignored chat message with token breakdown |
| /dcp stats | Ignored chat message with session + all-time stats |
| /dcp sweep | Flush pending prune strategies |
| /dcp manual on\|off | Toggle manual mode (persisted) |
| /dcp decompress <id> | Restore a compressed block |
| /dcp recompress <id> | Re-activate a decompressed block |
LLM tools (when compress permission allows):
compress— range mode (startId/endId) or message mode (messageId), per config
Configuration
~/.config/opencode/dcp.jsonc (or project .opencode/dcp.jsonc):
{
"enabled": true,
"strategies": {
"deduplication": { "enabled": true },
"purgeErrors": { "enabled": true }
},
"compress": {
"mode": "range", // or "message"
"permission": "allow",
"showCompression": true
},
"pruneNotification": "detailed", // off | minimal | detailed
"pruneNotificationType": "chat", // chat | toast
"manualMode": { "enabled": false },
"commands": { "enabled": true }
}Full schema: dcp.schema.json.
Architecture
OpenCode server process
index.ts (Plugin)
→ hooks (messages.transform, system, commands, events)
→ strategies (dedup, purge-errors)
→ compress tools (range | message)
→ state persistence (~/.local/share/opencode/storage/plugin/dcp/)
OpenCode TUI process
tui.tsx
→ /dcp → PanelDialog (Context / Stats / Manual)Same structure as upstream @tarquinen/opencode-dcp. Prune mutates OpenCode tool parts in place (placeholder outputs) — no IR round-trip.
Development
cd opencode-dcp-plugin
npm install --legacy-peer-deps
npm run build # tsup → dist/index.js + tsc declarations
npm run typecheckAfter changing TUI sources, restart OpenCode (TUI loads tui.tsx live via file://).
Do not leave nested
node_modules/@opentuiorsolid-jsin the plugin package when loading viafile://— OpenCode must use its host renderer.
Credits
Based on @tarquinen/opencode-dcp (AGPL-3.0) by tarquinen.
License
MIT — see LICENSE.
