[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-73805":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":9,"rankLanguage":9,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":9,"pushedAt":9,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":15,"starSnapshotCount":15,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},73805,"opencode-dynamic-context-pruning","Opencode-DCP\u002Fopencode-dynamic-context-pruning","Opencode-DCP","Dynamic context pruning plugin for OpenCode - intelligently manages conversation context to optimize token usage",null,"TypeScript",3290,178,13,26,0,64,182,555,192,108.76,"GNU Affero General Public License v3.0",false,"master",true,[],"2026-06-12 04:01:11","# Dynamic Context Pruning Plugin\n\n[![ko-fi](https:\u002F\u002Fko-fi.com\u002Fimg\u002Fgithubbutton_sm.svg)](https:\u002F\u002Fko-fi.com\u002Fdansmolsky)\n[![npm version](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002F@tarquinen\u002Fopencode-dcp.svg)](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@tarquinen\u002Fopencode-dcp)\n\nAutomatically reduces token usage in OpenCode by managing conversation context.\n\n![DCP in action](assets\u002Fimages\u002Fdcp-demo9.png)\n\n## Installation\n\nInstall from the CLI:\n\n```bash\nopencode plugin @tarquinen\u002Fopencode-dcp@latest --global\n```\n\nThis installs the package and adds it to your global OpenCode config.\n\n## How It Works\n\nDCP 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.\n\n### Compress\n\nCompress 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.\n\nDCP supports two compression modes:\n\n- `range` mode compresses contiguous spans of conversation into one or more summaries.\n- `message` mode (experimental) compresses individual raw messages independently, letting the model manage context much more surgically.\n\nIn `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.\n\n### Deduplication\n\nIdentifies 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.\n\n### Purge Errors\n\nPrunes 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.\n\n## Configuration\n\nDCP uses its own config file, searched in order:\n\n1. Global: `~\u002F.config\u002Fopencode\u002Fdcp.jsonc` (or `dcp.json`), created automatically on first run\n2. Custom config directory: `$OPENCODE_CONFIG_DIR\u002Fdcp.jsonc` (or `dcp.json`), if `OPENCODE_CONFIG_DIR` is set\n3. Project: `.opencode\u002Fdcp.jsonc` (or `dcp.json`) in your project's `.opencode` directory\n\nEach level overrides the previous, so project settings take priority over global. Restart OpenCode after making config changes.\n\n> [!NOTE]\n> 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.\n\n> [!IMPORTANT]\n> Defaults are applied automatically. Expand this if you want to review or override settings.\n\n\u003Cdetails>\n\u003Csummary>\u003Cstrong>Default Configuration\u003C\u002Fstrong> (click to expand)\u003C\u002Fsummary>\n\n```jsonc\n{\n    \"$schema\": \"https:\u002F\u002Fraw.githubusercontent.com\u002FOpencode-DCP\u002Fopencode-dynamic-context-pruning\u002Fmaster\u002Fdcp.schema.json\",\n    \u002F\u002F Enable or disable the plugin\n    \"enabled\": true,\n    \u002F\u002F Automatically update npm-installed DCP when a newer npm latest is available.\n    \u002F\u002F Version-locked plugin specs are not updated.\n    \"autoUpdate\": true,\n    \u002F\u002F Enable debug logging to ~\u002F.config\u002Fopencode\u002Flogs\u002Fdcp\u002F\n    \"debug\": false,\n    \u002F\u002F Notification display: \"off\", \"minimal\", or \"detailed\"\n    \"pruneNotification\": \"detailed\",\n    \u002F\u002F Notification type: \"chat\" (in-conversation) or \"toast\" (system toast)\n    \"pruneNotificationType\": \"chat\",\n    \u002F\u002F Slash commands configuration\n    \"commands\": {\n        \"enabled\": true,\n        \u002F\u002F Additional tools to protect from pruning via commands (e.g., \u002Fdcp sweep)\n        \"protectedTools\": [],\n    },\n    \u002F\u002F Manual mode: disables autonomous context management,\n    \u002F\u002F tools only run when explicitly triggered via \u002Fdcp commands\n    \"manualMode\": {\n        \"enabled\": false,\n        \u002F\u002F When true, automatic cleanup (deduplication, purgeErrors)\n        \u002F\u002F still runs even in manual mode\n        \"automaticStrategies\": true,\n    },\n    \u002F\u002F Protect from pruning for \u003Cturns> message turns past tool invocation\n    \"turnProtection\": {\n        \"enabled\": false,\n        \"turns\": 4,\n    },\n    \u002F\u002F Experimental settings\n    \"experimental\": {\n        \u002F\u002F Allow DCP processing in subagent sessions\n        \"allowSubAgents\": false,\n        \u002F\u002F Enable user-editable prompt overrides under dcp-prompts directories\n        \u002F\u002F When false (default), prompt override files\u002Fdirectories are ignored\n        \"customPrompts\": false,\n    },\n    \u002F\u002F Protect file operations from pruning via glob patterns\n    \u002F\u002F Patterns match tool parameters.filePath (e.g. read\u002Fwrite\u002Fedit)\n    \"protectedFilePatterns\": [],\n    \u002F\u002F Unified context compression tool and behavior settings\n    \"compress\": {\n        \u002F\u002F Compression mode: \"range\" (compress spans into block summaries)\n        \u002F\u002F or experimental \"message\" (compress individual raw messages)\n        \"mode\": \"range\",\n        \u002F\u002F Permission mode: \"allow\" (no prompt), \"ask\" (prompt), \"deny\" (tool not registered)\n        \"permission\": \"allow\",\n        \u002F\u002F Show compression content in a chat notification\n        \"showCompression\": false,\n        \u002F\u002F Let active summary tokens extend the effective maxContextLimit\n        \"summaryBuffer\": true,\n        \u002F\u002F Soft upper threshold: above this, DCP keeps injecting strong\n        \u002F\u002F compression nudges (based on nudgeFrequency), so compression is\n        \u002F\u002F much more likely. Accepts: number or \"X%\" of model context window.\n        \"maxContextLimit\": 100000,\n        \u002F\u002F Soft lower threshold for reminder nudges: below this, turn\u002Fiteration\n        \u002F\u002F reminders are off (compression less likely). At\u002Fabove this, reminders\n        \u002F\u002F are on. Accepts: number or \"X%\" of model context window.\n        \"minContextLimit\": 50000,\n        \u002F\u002F Optional per-model override for maxContextLimit by providerID\u002FmodelID.\n        \u002F\u002F If present, this wins over the global maxContextLimit.\n        \u002F\u002F Accepts: number or \"X%\".\n        \u002F\u002F Example:\n        \u002F\u002F \"modelMaxLimits\": {\n        \u002F\u002F     \"openai\u002Fgpt-5.3-codex\": 120000,\n        \u002F\u002F     \"anthropic\u002Fclaude-sonnet-4.6\": \"80%\"\n        \u002F\u002F },\n        \u002F\u002F Optional per-model override for minContextLimit.\n        \u002F\u002F If present, this wins over the global minContextLimit.\n        \u002F\u002F \"modelMinLimits\": {\n        \u002F\u002F     \"openai\u002Fgpt-5.3-codex\": 50000,\n        \u002F\u002F     \"anthropic\u002Fclaude-sonnet-4.6\": \"25%\"\n        \u002F\u002F },\n        \u002F\u002F How often the context-limit nudge fires (1 = every fetch, 5 = every 5th)\n        \"nudgeFrequency\": 5,\n        \u002F\u002F Start adding compression reminders after this many\n        \u002F\u002F messages have happened since the last user message\n        \"iterationNudgeThreshold\": 15,\n        \u002F\u002F Controls how likely compression is after user messages\n        \u002F\u002F (\"strong\" = more likely, \"soft\" = less likely)\n        \"nudgeForce\": \"soft\",\n        \u002F\u002F Tool names whose completed outputs are appended to the compression\n        \"protectedTools\": [],\n        \u002F\u002F Preserve text wrapped in \u003Cprotect>...\u003C\u002Fprotect> when compressed\n        \"protectTags\": false,\n        \u002F\u002F Preserve your messages during compression.\n        \u002F\u002F Warning: large copy-pasted prompts will never be compressed away\n        \"protectUserMessages\": false,\n    },\n    \u002F\u002F Automatic pruning strategies\n    \"strategies\": {\n        \u002F\u002F Remove duplicate tool calls (same tool with same arguments)\n        \"deduplication\": {\n            \"enabled\": true,\n            \u002F\u002F Additional tools to protect from pruning\n            \"protectedTools\": [],\n        },\n        \u002F\u002F Prune tool inputs for errored tools after X turns\n        \"purgeErrors\": {\n            \"enabled\": true,\n            \u002F\u002F Number of turns before errored tool inputs are pruned\n            \"turns\": 4,\n            \u002F\u002F Additional tools to protect from pruning\n            \"protectedTools\": [],\n        },\n    },\n}\n```\n\n\u003C\u002Fdetails>\n\n### Commands\n\nDCP provides a `\u002Fdcp` slash command:\n\n- `\u002Fdcp` — Shows available DCP commands\n- `\u002Fdcp context` — Shows a breakdown of your current session's token usage by category (system, user, assistant, tools, etc.) and how much has been saved through pruning.\n- `\u002Fdcp stats` — Shows cumulative pruning statistics across all sessions.\n- `\u002Fdcp sweep` — Prunes all tools since the last user message. Accepts an optional count: `\u002Fdcp sweep 10` prunes the last 10 tools. Respects `commands.protectedTools`.\n- `\u002Fdcp manual [on|off]` — Toggle manual mode or set explicit state. When on, the AI will not autonomously use context management tools.\n- `\u002Fdcp compress [focus]` — Trigger a single compress tool execution. Optional focus text directs what content to compress, following the active `compress.mode`.\n- `\u002Fdcp decompress \u003Cn>` — Restore a specific active compression by ID (for example `\u002Fdcp decompress 2`). Running without an argument shows available compression IDs, token sizes, and topics.\n- `\u002Fdcp recompress \u003Cn>` — Re-apply a user-decompressed compression by ID (for example `\u002Fdcp recompress 2`). Running without an argument shows recompressible IDs, token sizes, and topics.\n\n### Prompt Overrides\n\nDCP exposes six editable prompts:\n\n- `system`\n- `compress-range`\n- `compress-message`\n- `context-limit-nudge`\n- `turn-nudge`\n- `iteration-nudge`\n\nThis feature is disabled by default. Set `experimental.customPrompts` to `true` in your DCP config to activate it.\n\nWhen enabled, managed defaults are written to `~\u002F.config\u002Fopencode\u002Fdcp-prompts\u002Fdefaults\u002F` as plain-text prompt files. A single `README.md` in that directory explains each prompt and how to create overrides.\n\nTo customize behavior, add a file with the same name under an overrides directory and edit it as plain text.\n\nTo reset an override, delete the matching file from your overrides directory.\n\n### Protected Tools\n\nBy default, these tools are always protected from pruning:\n`task`, `skill`, `todowrite`, `todoread`, `compress`, `batch`, `plan_enter`, `plan_exit`, `write`, `edit`\n\nThe `protectedTools` arrays in `commands` and `strategies` add to this default list.\n\nFor the `compress` tool, `compress.protectedTools` ensures specific tool outputs are appended to the compressed summary. By default it includes `task`, `skill`, `todowrite`, and `todoread`.\n\n## Impact on Prompt Caching\n\nLLM providers cache prompts based on exact prefix matching. When DCP prunes content, it changes messages, which invalidates cached prefixes from that point forward.\n\n**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.\n\n> [!NOTE]\n> In testing, cache hit rates were approximately 85% with DCP vs 90% without.\n\n**No impact for:**\n\n- **Request-based billing** — Providers like GitHub Copilot that charge per request, not tokens.\n- **Uniform token pricing** — Providers like Cerebras that bill cached and uncached tokens at the same rate.\n\n## License\n\nAGPL-3.0-or-later\n","Opencode-DCP\u002Fopencode-dynamic-context-pruning 是一个用于OpenCode的动态上下文剪枝插件，旨在通过智能管理对话上下文来优化令牌使用。其核心功能包括压缩工具和自动清理机制，能够识别并压缩不再需要的对话内容，同时保留关键信息。该插件支持两种压缩模式：范围模式和消息模式（实验性），前者可以将连续的对话段压缩为摘要，后者则独立处理单个消息。此外，它还具有去重和错误清除功能，以进一步减少不必要的数据传输。此项目特别适用于需要长时间运行且涉及大量交互的开发场景中，帮助开发者更高效地利用资源。",2,"2026-06-11 03:47:25","high_star"]