opencode
opencode copied to clipboard
feat: implement smart pruning
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
- Content (60k tokens): High value (
- 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.,
grepkeeps first 5 matches,bashkeeps exit code + last 10 lines). - Configuration: Added full configuration support in
opencode.jsonfor budgets, custom tool classification, and summarization settings.
Fixes https://github.com/anomalyco/opencode/issues/7459