Tarquinen/opencode-dynamic-context-pruning
Dynamic context pruning plugin for OpenCode - intelligently manages conversation context to optimize token usage
What it solves
Dynamic Context Pruning (DCP) reduces token usage and manages context window limits in OpenCode by automatically pruning or summarizing stale conversation history. It prevents the LLM from becoming overwhelmed by large session histories while ensuring critical technical information is preserved.
How it works
DCP acts as a layer that replaces pruned content with placeholders before sending requests to the LLM, without modifying the actual session history. It employs three primary strategies:
- Compression: A tool available to the model that replaces stale conversation spans (range mode) or individual messages (message mode) with high-fidelity technical summaries. It can nest summaries to prevent information loss over multiple compression cycles.
- Deduplication: Identifies and removes repeated tool calls with identical arguments, keeping only the most recent output.
- Error Purging: Removes the large input content of tool calls that resulted in errors after a configurable number of turns, while keeping the error message itself.
Who it’s for
Users of OpenCode who want to lower their token costs and maintain model performance in long-running coding sessions.
Highlights
- Model-Driven Compression: Allows the LLM to decide when and what to compress based on task completion rather than using static thresholds.
- Information Preservation: Protects specific tool outputs (like subagents and skills) and user messages from being pruned.
- Flexible Configuration: Supports global, project-level, and custom config files with detailed controls over context limits and nudge frequencies.
- Manual Control: Includes a TUI panel and slash commands (
/dcp,/dcp-compress) for manual context management.
Related
- Project
- Project
- Project
- Project