Opencode-DCP/opencode-dynamic-context-pruning
Dynamic context pruning plugin for OpenCode - intelligently manages conversation context to optimize token usage
What it solves
It reduces token usage and prevents hallucinations caused by stale context in OpenCode sessions. It manages the conversation history to ensure the LLM doesn't exceed its context window or waste tokens on redundant information.
How it works
DCP manages context without modifying the original session history, instead replacing pruned content with placeholders before sending requests to the LLM. It uses three primary mechanisms:
- Compression: A tool that allows the model to replace stale or closed conversation spans (range mode) or individual messages (message mode) with high-fidelity technical summaries. It can nest summaries to preserve information across multiple compression layers.
- Deduplication: Identifies and removes repeated tool calls with the same arguments, keeping only the most recent output.
- Error Purging: Removes the input content of errored tool calls after a configurable number of turns, while preserving the error message itself.
Who it’s for
Users of OpenCode who are working in long coding sessions and want to optimize token consumption and maintain model performance.
Highlights
- Model-Driven Compression: The LLM decides when to compress based on task completion rather than relying on static triggers.
- Flexible Modes: Supports both contiguous range compression and surgical individual message compression.
- Configurable Protection: Allows users to protect specific tool outputs, file patterns, or user messages from being pruned.
- Customizable Prompts: Offers editable prompt overrides for system behavior and compression nudges.
Related
- Project
- Project
- Project
- Project
- Dispatch