claude-code - 💡(How to fix) Fix [BUG] Switching from Sonnet back to Opus after "prompt too long" error leaves session in broken state [1 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#51657Fetched 2026-04-22 07:56:23
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

Error Message

After accidentally switching from Opus to Sonnet mid-session, Sonnet triggered a "Prompt is too long" error. Switching back to Opus did not recover the session — it remained broken. /compact was unavailable, and opening a new session did not resolve the issue. Switching back to Opus (which supports a larger context window) should clear the error state and allow the session to resume normally.

Error Messages/Logs

Sonnet returns "Prompt is too long" error (Sonnet has a smaller context window)

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?

After accidentally switching from Opus to Sonnet mid-session, Sonnet triggered a "Prompt is too long" error. Switching back to Opus did not recover the session — it remained broken. /compact was unavailable, and opening a new session did not resolve the issue.

What Should Happen?

Switching back to Opus (which supports a larger context window) should clear the error state and allow the session to resume normally.

Error Messages/Logs

Steps to Reproduce

Start a long Claude Code session using Opus with a large codebase context Accidentally switch model to Sonnet (e.g. via /model) Sonnet returns "Prompt is too long" error (Sonnet has a smaller context window) Switch back to Opus Session remains broken — cannot send messages, /compact is unavailable Opening a new session does not resolve the issue

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.34

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

Switching to Sonnet and back to Opus mid-session may require a full session reset or a specific workaround to recover from the "Prompt is too long" error state.

Guidance

  • Verify that the issue persists across different sessions and platforms to rule out environment-specific factors.
  • Attempt to use the /reset command (if available) after switching back to Opus to clear the error state.
  • Check the Claude Code documentation for any model-specific limitations or workarounds when switching between Opus and Sonnet.
  • Consider filing a feature request to improve session recovery when switching between models with different context window sizes.

Example

No specific code snippet is applicable in this case, as the issue appears to be related to model switching and session state management.

Notes

The exact workaround or fix may depend on the internal implementation of Claude Code and the Anthropic API, which is not fully specified in the issue.

Recommendation

Apply workaround: Attempt to use the /reset command (if available) after switching back to Opus to clear the error state, as this may help recover the session without requiring a full restart.

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