Automatically reduces token usage in OpenCode by managing conversation context.
Installation
Install from the CLI:
opencode plugin @tarquinen/opencode-dcp@latest --global
This installs the package and adds it to your global OpenCode config.
Project Status
Development on DCP has slowed because most new context-management work has moved to Sleev and the sleev CLI. Sleev is a local proxy for Claude Code, Codex, and OpenCode that builds on DCP's core ideas with newer context-management features and will work with any harness/client.
DCP remains available for OpenCode plugin users, but new features are landing in Sleev first. If you are starting fresh, we recommend trying Sleev:
npm i -g sleev sleev
How It Works
DCP reduces context size through a compress tool and automatic cleanup. Your session history is never modified — DCP replaces pruned content with placeholders before sending requests to your LLM.
Compress
Compress is a tool exposed to your model that replaces closed, stale conversation content with high-fidelity technical summaries. You can think of this as a much smarter version of Opencode's compaction process. Instead of triggering statically when your session reaches its maximum context and on the entire coding session, Compress allows the model to pick when to activate based on task completion, and to only compress the specific messages that are no longer needed verbatim.
DCP supports two compression modes:
rangemode compresses contiguous spans of conversation into one or more summaries.messagemode (experimental) compresses individual raw messages independently, letting the model manage context much more surgically.
In range mode, when a new compression overlaps an earlier one, the earlier summary is nested inside the new one so information is preserved through layers of compression rather than diluted away. In both modes, protected tool outputs (such as subagents and skills) and protected file patterns are kept in compression summaries, ensuring that the most important information is never lost. You can also enable protectUserMessages to preserve your messages verbatim during compression, though note that large prompts (e.g. copy-pasting log files in the prompt) will then never be compressed away.
Deduplication
Identifies repeated tool calls (same tool, same arguments) and keeps only the most recent output. Recalculated when the compress tool runs, so prompt cache is only impacted alongside compression.
Purge Errors
Prunes inputs from errored tool calls after a configurable number of turns (default: 4). Error messages are preserved; only the potentially large input content is removed. Recalculated on compress tool use.
Configuration
DCP uses its own config file, searched in order:
- Global:
~/.config/opencode/dcp.jsonc(ordcp.json), created automatically on first run - Custom config directory:
$OPENCODE_CONFIG_DIR/dcp.jsonc(ordcp.json), ifOPENCODE_CONFIG_DIRis set - Project:
.opencode/dcp.jsonc(ordcp.json) in your project's.opencodedirectory
Each level overrides the previous, so project settings take priority over global. Restart OpenCode after making config changes.
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.
Important
Defaults are applied automatically. Expand this if you want to review or override settings.
Commands
DCP provides a TUI panel and one prompt-producing slash command:
/dcp— Opens the DCP panel with context, stats, and manual-mode controls./dcp-compress [focus]— Asks the model to run one compression pass. Optional focus text directs what content to compress, following the activecompress.mode.
Prompt Overrides
DCP exposes six editable prompts:
systemcompress-rangecompress-messagecontext-limit-nudgeturn-nudgeiteration-nudge
This feature is disabled by default. Set experimental.customPrompts to true in your DCP config to activate it.
When enabled, managed defaults are written to ~/.config/opencode/dcp-prompts/defaults/ as plain-text prompt files. A single README.md in that directory explains each prompt and how to create overrides.
To customize behavior, add a file with the same name under an overrides directory and edit it as plain text.
To reset an override, delete the matching file from your overrides directory.
Protected Tools
By default, these tools are always protected from pruning:
task, skill, todowrite, todoread, compress, batch, plan_enter, plan_exit, write, edit
The protectedTools arrays in commands and strategies add to this default list.
For the compress tool, compress.protectedTools ensures specific tool outputs are appended to the compressed summary. By default it includes task, skill, todowrite, and todoread.
Impact on Prompt Caching
LLM providers cache prompts based on exact prefix matching. When DCP prunes content, it changes messages, which invalidates cached prefixes from that point forward.
Trade-off: You lose some cache reads but gain token savings from reduced context size and fewer hallucinations from stale context. In most cases, especially in long sessions, the savings outweigh the cache miss cost.
Note
In testing, cache hit rates were approximately 85% with DCP vs 90% without.
No impact for:
- Request-based billing — Some providers charge per request, not tokens.
- Uniform token pricing — Providers like Cerebras that bill cached and uncached tokens at the same rate.
License
AGPL-3.0-or-later
