opencode-dynamic-context-pruning  by Opencode-DCP

Dynamic context pruning for AI assistants

Created 1 month ago
334 stars

Top 82.2% on SourcePulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This plugin addresses the challenge of escalating token usage and context bloat in conversational AI systems like OpenCode. It intelligently prunes conversation history, specifically targeting obsolete tool outputs, to optimize token consumption and improve performance. The target audience is OpenCode users seeking to manage costs and enhance the efficiency of their AI interactions, particularly in long-running sessions.

How It Works

The plugin employs a multi-pronged approach combining explicit AI-driven tools and automatic background strategies. It exposes discard and extract tools, allowing the AI to actively remove completed or noisy tool content or distill valuable information into concise summaries before pruning. Automatic strategies include deduplication to retain only the most recent output of repeated tool calls (e.g., file reads), supersedeWrites to prune write operations for files that are subsequently read, and purgeErrors to remove inputs of tools that have consistently failed after a set number of turns. These strategies operate automatically on every request with zero direct LLM cost.

Quick Start & Requirements

Installation involves adding "@tarquinen/opencode-dcp@latest" to the plugin array in your opencode.jsonc configuration file. If using OAuth plugins, this plugin should be listed last. After configuration, simply restart OpenCode. The plugin automatically manages context pruning. Configuration can be managed via ~/.config/opencode/dcp.jsonc, $OPENCODE_CONFIG_DIR/dcp.jsonc, or project-specific .opencode/dcp.jsonc files, with settings merging hierarchically.

Highlighted Details

  • Automatic pruning strategies (deduplication, purgeErrors) run on every request with zero LLM cost.
  • The plugin replaces pruned content with placeholders, preserving the original session history.
  • A trade-off exists with LLM prompt caching: pruned content invalidates cache prefixes, but token savings and reduced context poisoning often outweigh this cost, especially in long sessions.
  • Ideal for providers where usage is counted per request, such as GitHub Copilot and Google Antigravity, as it minimizes negative price impacts.

Maintenance & Community

No specific details regarding maintainers, community channels (like Discord/Slack), or roadmap were present in the provided README.

Licensing & Compatibility

The project is released under the MIT license, which generally permits commercial use and integration into closed-source projects.

Limitations & Caveats

The primary limitation is the potential invalidation of LLM prompt cache prefixes due to message content changes resulting from pruning. This can lead to increased cache misses, though the plugin's design aims for overall token savings and performance gains to compensate.

Health Check
Last Commit

1 day ago

Responsiveness

Inactive

Pull Requests (30d)
110
Issues (30d)
15
Star History
222 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems") and Michael Han Michael Han(Cofounder of Unsloth).

AdalFlow by SylphAI-Inc

0.6%
4k
PyTorch-like library for building and auto-optimizing LLM workflows
Created 1 year ago
Updated 1 week ago
Feedback? Help us improve.