feat: disable OpenCode compaction and add proactive token budget pruning#21
Merged
tuanhung303 merged 1 commit intomasterfrom Feb 9, 2026
Merged
Conversation
Replace OpenCode's built-in compaction (which drops all history before a summary) with a plugin-managed proactive pruning strategy that preserves granular context. - Config hook disables OpenCode auto-compaction and tool output pruning - New proactivePrune strategy: at 70% context prunes old tool outputs, at 85% also prunes reasoning blocks - Compacting safety net hook preserves plugin state (todos, tracked files, stats) if compaction ever triggers - Configurable thresholds via TokenBudget schema (warningThreshold, criticalThreshold, targetPercent, protectedRecentTurns) - 13 E2E tests covering all threshold and config scenarios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
confighook — prevents OpenCode from summarizing and dropping conversation history before the plugin can process itproactivePrunestrategy that manages token budget at the plugin level: prunes old tool outputs at 70% context usage, adds reasoning block pruning at 85%compactinghook preserves plugin state (active todos, tracked files, pruning stats) in any compaction summary if compaction is ever re-enabledProblem
OpenCode's auto-compaction runs before the plugin's
experimental.chat.messages.transformhook, so when it triggers it drops all history — overriding the plugin's granular pruning. The plugin never sees the messages OpenCode already removed.Solution
compaction: { auto: false, prune: false }so OpenCode never triggers its own compactionproactivePrunestrategy replaces OpenCode's role in managing context window pressure with configurable thresholdscompactinghook acts as a last-resort safety net if a user re-enables compaction manuallyFiles Changed
index.tslib/strategies/proactive-prune.tslib/strategies/index.tsproactivePrunelib/hooks.tsproactivePrunein PRUNE_STRATEGIES pipelinelib/config/schema.tsTokenBudgetSchemawith configurable thresholdslib/config/defaults.tstests/e2e/proactive-pruning.test.tstests/hooks.test.tstests/integration/opt-in-defaults.test.tsTest Results
npm linkverified