You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: Auto compaction not triggering reliably with Anthropic models #6068
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>
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.
Activity
github-actions commentedon 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
fix(session): prevent context overflow by adding safety margin to com…
Leksat commentedon Jan 5, 2026
Same for me.
I use opencode v1.1.2 connected to Claude Max plan. Right pane shows
But get
prompt is too long: 203185 tokens > 200000 maximumanyways. Confusing 😕github-actions commentedon 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 commentedon 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:
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:
That would likely reduce the “prompt too long first, compaction later” failure mode this issue describes.