opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: implement smart pruning

Open processtrader opened this issue 5 days ago • 3 comments

Summary

This PR implements Smart Pruning, a new context management system that replaces the basic FIFO approach with a tiered priority system to preserve critical information longer.

Key Changes

  • Tiered Pruning: Tools are now classified into 3 tiers with separate token budgets:
    • Content (60k tokens): High value (read, webfetch) - Summarized when pruned
    • Navigation (15k tokens): Ephemeral (ls, grep) - Compressed when pruned
    • Action (Protected): Important (edit, write) - Never pruned
  • LLM Summarization: Instead of deleting content entirely, pruned content is now replaced with concise (<100 token) LLM-generated summaries.
    • Uses the user's configured model or falls back to the provider's default "small model".
  • Tool Compression: Navigation tools now gracefully degrade (e.g., grep keeps first 5 matches, bash keeps exit code + last 10 lines).
  • Configuration: Added full configuration support in opencode.json for budgets, custom tool classification, and summarization settings.

Fixes https://github.com/anomalyco/opencode/issues/7459

processtrader avatar Jan 07 '26 14:01 processtrader