claude-code - 💡(How to fix) Fix [BUG] [BUG] Switching from Opus 4.7 1M to Sonnet mid-session (~700k tokens) breaks session completely — no recovery possible [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52709Fetched 2026-04-24 10:41:46
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

Error Message

Repeated API Error: Prompt is too long Expected behavior: Switching models mid-session should either trigger /compact automatically or warn the user that the accumulated context exceeds the new model's limit. The session should never become fully locked with no recovery path. Warn the user that the current context (~700k tokens) exceeds the new model's limit and ask for confirmation before switching

Error Messages/Logs

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

I was working in a session using Opus 4.7 with 1M context window, with approximately 700k tokens accumulated. I switched models to Sonnet mid-session. After switching, the session became completely broken:

Repeated API Error: Prompt is too long This conversation has reached its length limit. Start a new session to continue. Usage limit reached displayed in the input bar Could not type, delete, or press Enter /compact was not triggered automatically The only interactive element was the Create PR button

The session eventually unblocked after clicking Create PR multiple times, but this was not a reliable or intentional fix. Expected behavior: Switching models mid-session should either trigger /compact automatically or warn the user that the accumulated context exceeds the new model's limit. The session should never become fully locked with no recovery path.

Environment:

Plan: Claude Max 5x Model: Opus 4.7 1M → switched to Sonnet 4.6 Interface: Claude Code Desktop App

What Should Happen?

When switching models mid-session, Claude Code should detect that the accumulated context exceeds the new model's token limit and either:

Automatically trigger /compact to reduce the context before switching Warn the user that the current context (~700k tokens) exceeds the new model's limit and ask for confirmation before switching If the switch already happened and the limit is exceeded, offer a recovery option (like a forced /compact) instead of locking the session completely with no way out

The session should never reach a fully locked state where the user cannot type, delete, or execute any command.

Error Messages/Logs

Steps to Reproduce

Steps to reproduce:

Start a long session with Opus 4.7 1M context Accumulate ~700k tokens Switch to Sonnet mid-session Session locks completely

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.110 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Other

Additional Information

No response

extent analysis

TL;DR

The issue can be mitigated by automatically triggering /compact when switching models mid-session to reduce the context before switching, or by warning the user that the current context exceeds the new model's limit.

Guidance

  • When switching models, check if the accumulated context exceeds the new model's token limit and trigger /compact automatically if necessary.
  • Consider adding a warning to the user when the current context exceeds the new model's limit, asking for confirmation before switching.
  • If the switch has already occurred and the limit is exceeded, provide a recovery option, such as a forced /compact, to prevent the session from becoming fully locked.
  • Review the model switching logic to ensure it handles context limits correctly and provides a reliable recovery path.

Example

No code snippet is provided as the issue does not include specific code details.

Notes

The issue seems to be a regression, as it worked in a previous version. The exact cause of the regression is unclear, but it is related to the model switching logic and context limit handling.

Recommendation

Apply a workaround by modifying the model switching logic to automatically trigger /compact when necessary, or by adding a warning to the user when the context limit is exceeded. This will help prevent the session from becoming fully locked and provide a more reliable user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] [BUG] Switching from Opus 4.7 1M to Sonnet mid-session (~700k tokens) breaks session completely — no recovery possible [1 comments, 2 participants]