Fork of p4r4d0xb0x/opencode-dcp
(which is itself a fork of @tarquinen/opencode-dcp),
patched so the plugin loads and runs on OpenCode 2.2.2+, installed as a
local plugin instead of an npm package.
The published @p4r4d0xb0x/opencode-dcp@4.0.2 cannot load on OpenCode 2.2.x:
its runtime import of the pinned @opencode-ai/plugin@0.0.0-beta-18992 pulls
schema modules that call Schema.isStartsWith, which the host's aliased
effect/Schema build does not export —
TypeError: Schema.isStartsWith is not a function ('Schema.isStartsWith("wrk")')
at plugin-load time. The @opencode-ai/* scope is additionally shadowed by
older V1 SDK installs under ~/.config/opencode/node_modules.
- SDK retargeted to
@opencode/plugin@2.2.2— the host-aliased V2 scope (@opencode/plugin,@opencode/plugin/tui,effect/*aliases in the host). - Vendored
Plugin.define/Rpc.define(they are identity/validation passthroughs), so the server bundle has zero bare runtime imports beyond node builtins — immune to host module-redirect traps. - Self-contained builds (tsup): bundles
@anthropic-ai/tokenizer+jsonc-parser, no chunk splitting, ESM banner providingrequire,__filename,__dirnamefor the bundled CJS tokenizer. The tokenizer'stiktoken_bg.wasmis placed by the deploy script where the loader'snode_modulesancestor search finds it. - API drift fixes vs. the beta SDK the fork was written against:
ctx.catalog.model.list→ctx.model.list,session.command({command})→({name}). flattenThemerewritten for the 2.2.2ResolvedThemetoken tree (base/muted/stateful RGBA,background.raised), wrapped in a terminal-defaults fallback so a future theme-shape change can never crash the TUI (fixestheme.background.surface.offsetcrash in the DCP panel).todowrite/todoreadremoved fromCOMPRESS_DEFAULT_PROTECTED_TOOLS(lib/config.ts) — these names were injected into every session's system-reminder and primed agent-trained models into calling a todo tool OpenCode doesn't register by default (experimental.todo: false), causing unparsed tool calls / raw Hermes markup leaks. The internal pruning-protection default (DEFAULT_PROTECTED_TOOLS) still lists them (never shown to models; no-op if unregistered). Re-enable viadcp.jsonc(compress.protectedTools: ["todowrite", "todoread"]) if the tools ever get registered — the merge is additive.npm run deployinstalls everything as a directory plugin.
Requirements: Node 20+, and OpenCode ≥ 2.2.2 with the @opencode/plugin
version matching it (devDependencies pin @opencode/plugin@2.2.2 — bump it
to your opencode --version if you run a newer host).
git clone git@github.com:FoMiN12/opencode-dcp.git
cd opencode-dcp
npm install
npm run deploynpm run deploy copies the built bundles to
~/.config/opencode/plugins/opencode-dcp/ (index.js server plugin, tui.js
terminal plugin, package.json) and places tiktoken_bg.wasm under
~/.config/opencode/node_modules/tiktoken/lite/.
Then:
- Put your
dcp.jsoncin~/.config/opencode/(config format is unchanged from upstream — see below). Recommended for local builds:"autoUpdate": false. - Restart the opencode service and TUI.
- Verify:
opencode plugin listshowsopencode-dcp · local;/dcpopens the status panel;/dcp-compressforces compression.
Uninstall: rm -rf ~/.config/opencode/plugins/opencode-dcp and
rm -rf ~/.config/opencode/node_modules/tiktoken.
⚠️ If you also want OpenCode's own auto-compaction disabled (DCP as the only context mechanism), set"compaction": { "auto": false }in~/.config/opencode/opencode.json.
Everything below is the original upstream README (config reference, commands, behavior).
Automatically reduces token usage in OpenCode by managing conversation context.
@p4r4d0xb0x/opencode-dcp is a fork of @tarquinen/opencode-dcp ported to the OpenCode 2 plugin API (opencode2). It tracks upstream and keeps the same configuration file, commands, and pruning behavior. For OpenCode 1 keep using the upstream package.
Install from the CLI:
opencode2 plugin add @p4r4d0xb0x/opencode-dcp@latestOr add it to plugins in your global ~/.config/opencode/opencode.json(c):
Restart the background service (opencode2 service restart) after installing or updating.
- Permissions. The
compresstool declares thecompresspermission action. A rule such as{ "action": "compress", "resource": "*", "effect": "deny" }(globally or underagents.<id>.permissions) removes the tool for that agent, exactly likepermission.compress: "deny"did in OpenCode 1. OpenCode 2 (beta) cannot prompt for plugin tools, socompress.permission: "ask"behaves like"allow". - Subagents. The tool is hidden from subagent sessions unless
experimental.allowSubAgentsis enabled; OpenCode 2'ssubagenttool is treated like OpenCode 1'stasktool for protection and result expansion. - Notifications.
pruneNotificationType: "chat"posts a synthetic message that is shown in the session but never sent to the model."toast"requires the DCP TUI plugin (loaded automatically with the package) and is delivered through the plugin RPC channel. - Prefill guard. DCP guarantees every request it touches ends with a user or tool message, so models without assistant prefill support (Claude Opus 4.5+) never fail with
This model does not support assistant message prefill. - Auto-update.
autoUpdatechecks npm for a newer version; when found, the cached install is cleared so the next start picks it up.opencode2 plugin update @p4r4d0xb0x/opencode-dcpdoes the same on demand.
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
sleevDCP 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 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.
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.
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.
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.
Default Configuration (click to expand)
{
"$schema": "https://raw.githubusercontent.com/p4r4d0xb0x/opencode-dcp/master/dcp.schema.json",
// Enable or disable the plugin
"enabled": true,
// Automatically update npm-installed DCP when a newer npm latest is available.
// Version-locked plugin specs are not updated.
"autoUpdate": true,
// Enable debug logging to ~/.config/opencode/logs/dcp/
"debug": false,
// Notification display: "off", "minimal", or "detailed"
"pruneNotification": "detailed",
// Notification type: "chat" (in-conversation) or "toast" (system toast)
"pruneNotificationType": "chat",
// Slash commands configuration
"commands": {
"enabled": true,
// Additional tools to protect from pruning via commands (e.g., /dcp sweep)
"protectedTools": [],
},
// Manual mode: disables autonomous context management,
// tools only run when explicitly triggered via /dcp commands
"manualMode": {
"enabled": false,
// When true, automatic cleanup (deduplication, purgeErrors)
// still runs even in manual mode
"automaticStrategies": true,
},
// Protect from pruning for <turns> message turns past tool invocation
"turnProtection": {
"enabled": false,
"turns": 4,
},
// Experimental settings
"experimental": {
// Allow DCP processing in subagent sessions
"allowSubAgents": false,
// Enable user-editable prompt overrides under dcp-prompts directories
// When false (default), prompt override files/directories are ignored
"customPrompts": false,
},
// Protect file operations from pruning via glob patterns
// Patterns match tool parameters.filePath (e.g. read/write/edit)
"protectedFilePatterns": [],
// Unified context compression tool and behavior settings
"compress": {
// Compression mode: "range" (compress spans into block summaries)
// or experimental "message" (compress individual raw messages)
"mode": "range",
// Permission mode: "allow" (no prompt), "ask" (prompt), "deny" (tool not registered)
"permission": "allow",
// Show compression content in a chat notification
"showCompression": false,
// Let active summary tokens extend the effective maxContextLimit
"summaryBuffer": true,
// Soft upper threshold: above this, DCP keeps injecting strong
// compression nudges (based on nudgeFrequency), so compression is
// much more likely. Accepts: number or "X%" of model context window.
"maxContextLimit": 100000,
// Soft lower threshold for reminder nudges: below this, turn/iteration
// reminders are off (compression less likely). At/above this, reminders
// are on. Accepts: number or "X%" of model context window.
"minContextLimit": 50000,
// Optional per-model override for maxContextLimit by providerID/modelID.
// If present, this wins over the global maxContextLimit.
// Accepts: number or "X%".
// Example:
// "modelMaxLimits": {
// "openai/gpt-5.3-codex": 120000,
// "anthropic/claude-sonnet-4.6": "80%"
// },
// Optional per-model override for minContextLimit.
// If present, this wins over the global minContextLimit.
// "modelMinLimits": {
// "openai/gpt-5.3-codex": 50000,
// "anthropic/claude-sonnet-4.6": "25%"
// },
// How often the context-limit nudge fires (1 = every fetch, 5 = every 5th)
"nudgeFrequency": 5,
// Start adding compression reminders after this many
// messages have happened since the last user message
"iterationNudgeThreshold": 15,
// Controls how likely compression is after user messages
// ("strong" = more likely, "soft" = less likely)
"nudgeForce": "soft",
// Tool names whose completed outputs are appended to the compression
"protectedTools": [],
// Preserve text wrapped in <protect>...</protect> when compressed
"protectTags": false,
// Preserve your messages during compression.
// Warning: large copy-pasted prompts will never be compressed away
"protectUserMessages": false,
},
// Automatic pruning strategies
"strategies": {
// Remove duplicate tool calls (same tool with same arguments)
"deduplication": {
"enabled": true,
// Additional tools to protect from pruning
"protectedTools": [],
},
// Prune tool inputs for errored tools after X turns
"purgeErrors": {
"enabled": true,
// Number of turns before errored tool inputs are pruned
"turns": 4,
// Additional tools to protect from pruning
"protectedTools": [],
},
},
}DCP provides a TUI panel plus server-side slash commands (available in every client):
/dcp— Opens the DCP panel with context, stats, and manual-mode controls (TUI)./dcp <context|stats|sweep [n]|manual [on|off]|decompress <n>|recompress <n>|help>— Runs the matching DCP command and posts the result in the session./dcp-compress [focus]— Asks the model to run one compression pass. Optional focus text directs what content to compress, following the activecompress.mode.
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.
By default, these tools are always protected from pruning:
task, subagent, 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, subagent, skill, todowrite, and todoread.
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.
AGPL-3.0-or-later

{ "plugins": ["@p4r4d0xb0x/opencode-dcp"], }