GeezerVison is showing github.com — [BUG]: Auto compaction not triggering reliably with Anthropic models · Issue #6068 · anomalyco/opencode
[BUG]: Auto compaction not triggering reliably with Anthropic models #6068DescriptionDescription
Auto compaction seems to have stopped working reliably with Anthropic models. Previously, when context tokens approached the model's limit, opencode would automatically trigger compaction to summarize the session. Now, we're getting 'prompt is too long' errors more frequently without auto compaction kicking in.
Steps To Reproduce
- Start a session with an Anthropic model (e.g., claude-sonnet-4-20250514)
- Have an extended conversation with multiple tool calls and file edits
- Continue working until context approaches the model's token limit (e.g., 131072 or 200000)
- Observe that instead of auto compaction running, you receive errors like:
This model's maximum context length is 131072 tokens. However, you requested N tokens...
or
prompt is too long: X tokens > Y maximum
Expected Behavior
Opencode should automatically trigger session compaction BEFORE hitting the model's context limit, summarizing previous messages to free up context for continuing the conversation.
Actual Behavior
Auto compaction is not triggering automatically, leading to 'prompt too long' errors that stop the session. Manual compaction (via keybind) still works.
Relevant Log Output
# Running with verbose logging can provide more details:
OPENCODE_LOG=* opencode run <project>
Additional Context
Questions
- Did anything change in the auto compaction logic recently?
- Are there any new configuration options affecting compaction behavior?
- Is there any way to adjust the threshold or make compaction more aggressive?
Thanks for investigating this! Reacted by Alexander Tkachev Activitygithub-actions commented on Dec 23, 2025 This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
For keybind-related issues, please also check our pinned keybinds documentation: #4997 added a commit that references this issue on Jan 1, 2026This issue will close once commit 5707d22 is merged into the 'dev' branch.5707d22 Leksat commented on Jan 5, 2026 Same for me.
I use opencode v1.1.2 connected to Claude Max plan. Right pane shows
Context
107,981 tokens
54% used
But get prompt is too long: 203185 tokens > 200000 maximum anyways. Confusing 😕 github-actions commented on Mar 25, 2026 To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one. alario-tang commented on Mar 31, 2026 I think this issue is partly about trigger timing, not only model/provider behavior.
From reading the current code, auto-compaction seems to be driven mostly by:
- post-step token usage crossing threshold
- provider-side overflow / context rejection
That means the system is still often reacting after a request was already too large, instead of shrinking context before the next risky request is sent.
A useful improvement here may be a lightweight pre-request pass before normal generation, for example:
- prune older completed tool output earlier
- reserve a stricter output budget
- compact proactively before provider rejection, not after
That would likely reduce the “prompt too long first, compaction later” failure mode this issue describes.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|