[BUG]: Auto compaction not triggering reliably with Anthropic models #3805

Open
opened 2026-02-16 17:41:32 -05:00 by yindo · 2 comments
Owner

Originally created by @ramarivera on GitHub (Dec 23, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

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

  1. Start a session with an Anthropic model (e.g., claude-sonnet-4-20250514)
  2. Have an extended conversation with multiple tool calls and file edits
  3. Continue working until context approaches the model's token limit (e.g., 131072 or 200000)
  4. 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

  • OpenCode version: 1.0.191 (current)
  • Operating System: macOS
  • Related issue: #6034 (Prompt Compression feature request)
  • Recent relevant commits:
    • eab177f - feat(plugin): allow compaction hook to replace prompt entirely (#5907)
    • 8dfef67 - [FEATURE]: Show context usage in OpenCode Desktop (#5979)

Questions

  1. Did anything change in the auto compaction logic recently?
  2. Are there any new configuration options affecting compaction behavior?
  3. Is there any way to adjust the threshold or make compaction more aggressive?

Thanks for investigating this!

Originally created by @ramarivera on GitHub (Dec 23, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description 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 1. Start a session with an Anthropic model (e.g., claude-sonnet-4-20250514) 2. Have an extended conversation with multiple tool calls and file edits 3. Continue working until context approaches the model's token limit (e.g., 131072 or 200000) 4. 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 ```bash # Running with verbose logging can provide more details: OPENCODE_LOG=* opencode run <project> ``` ### Additional Context - **OpenCode version**: 1.0.191 (current) - **Operating System**: macOS - **Related issue**: #6034 (Prompt Compression feature request) - Recent relevant commits: - eab177f - feat(plugin): allow compaction hook to replace prompt entirely (#5907) - 8dfef67 - [FEATURE]: Show context usage in OpenCode Desktop (#5979) ### Questions 1. Did anything change in the auto compaction logic recently? 2. Are there any new configuration options affecting compaction behavior? 3. Is there any way to adjust the threshold or make compaction more aggressive? --- Thanks for investigating this!
Author
Owner

@github-actions[bot] commented on GitHub (Dec 23, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #5360: prompt is too long (reports similar 'prompt is too long' errors with Anthropic)
  • #4845: prompt is too long unrecoverable (reports 'prompt is too long' errors with Opus 4.5 that are unrecoverable)
  • #5178: Allow continuation after context overflow (related feature request for handling context overflow)
  • #5934: Session Todo-list is forgotten after compaction (related compaction behavior issue)
  • #4416: Auto compaction happens much earlier than expected when caching is enabled (related auto compaction threshold issue)

Feel free to ignore if none of these address your specific case.

For keybind-related issues, please also check our pinned keybinds documentation: #4997

@github-actions[bot] commented on GitHub (Dec 23, 2025): This issue might be a duplicate of existing issues. Please check: - #5360: prompt is too long (reports similar 'prompt is too long' errors with Anthropic) - #4845: prompt is too long unrecoverable (reports 'prompt is too long' errors with Opus 4.5 that are unrecoverable) - #5178: Allow continuation after context overflow (related feature request for handling context overflow) - #5934: Session Todo-list is forgotten after compaction (related compaction behavior issue) - #4416: Auto compaction happens much earlier than expected when caching is enabled (related auto compaction threshold issue) Feel free to ignore if none of these address your specific case. For keybind-related issues, please also check our pinned keybinds documentation: #4997
Author
Owner

@Leksat commented on GitHub (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 😕

@Leksat commented on GitHub (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 😕
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3805