claude-code - 💡(How to fix) Fix [BUG] VSCode: Switching to a lighter model mid-session leaves session stuck — misleading error makes recovery non-obvious. [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

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#52152Fetched 2026-04-23 07:35:16
View on GitHub
Comments
1
Participants
1
Timeline
8
Reactions
0
Participants
Timeline (top)
labeled ×6commented ×1renamed ×1

If you interrupt Claude mid-task and switch to a lighter model (e.g. Opus → Sonnet), the session can become completely stuck: every message returns "Prompt is too long" and /compact also fails. The error shown during /compact is misleading and points the user in the wrong direction. The actual recovery is simple (switch back to the original model → /compact) but nothing in the product tells you this.

Error Message

The error shown during /compact is misleading and points the user in the wrong direction. `Error: Error during compaction: API Error: Extra usage is required for 1M context · API error (attempt 5/11): 429

The Misleading Error

When /compact fails on Sonnet, the error shown is: The error misdirects users toward a paid plan upgrade when the real solution is free and

  • OR warn: "Your session (637k tokens) exceeds Sonnet's context window (180k). Option C — Fix the misleading error message:

Root Cause

The session's 637k tokens fit within Opus's standard context window but exceed Sonnet's (~180k effective). Claude Code allows the model switch without checking this. Once on Sonnet, the session is too large to process and /compact also fails because compaction itself must fit within the active model's window.

From the VS Code output log: autocompact: tokens=636851 threshold=167000 effectiveWindow=180000

API error (attempt 5/11): 429 {"type":"rate_limit_error","message":"Extra usage is required for long context requests."} request_id: req_011CaK9SET6PcTvXrkZa5eZ1

RAW_BUFFERClick to expand / collapse

Summary

If you interrupt Claude mid-task and switch to a lighter model (e.g. Opus → Sonnet), the session can become completely stuck: every message returns "Prompt is too long" and /compact also fails. The error shown during /compact is misleading and points the user in the wrong direction. The actual recovery is simple (switch back to the original model → /compact) but nothing in the product tells you this.

Environment

  • Claude Code version: 2.1.117.320 (VS Code extension)
  • Platform: Windows 11 Enterprise
  • Session built on: claude-opus-4-7 (standard — not 1M, no extra usage)
  • Switched to: claude-sonnet-4-6 (via /model default)

Exact Sequence of Events

  1. Long coding session running on standard Opus. Context accumulated to ~637k tokens.
  2. Rate-limit warning appears (~92%). User presses Stop to interrupt Claude mid-task.
  3. User runs /model default → switches to Sonnet (lighter model).
  4. Waits ~50 minutes for rate limit to reset.
  5. Sends continue"Prompt is too long"
  6. Sends continue again → "Prompt is too long" again. Session stuck.
  7. Tries /compact → fails with:
    Error: Error during compaction: API Error: Extra usage is required for 1M context · enable extra usage at claude.ai/settings/usage, or use --model to switch to standard context
  8. Switches back to standard claude-opus-4-7 (no 1M, no extra usage plan).
  9. Runs /compactsucceeds: Compacted chat · manual · 637k tokens freed
  10. Sends continue → session resumes normally.

Root Cause

The session's 637k tokens fit within Opus's standard context window but exceed Sonnet's (~180k effective). Claude Code allows the model switch without checking this. Once on Sonnet, the session is too large to process and /compact also fails because compaction itself must fit within the active model's window.

From the VS Code output log: autocompact: tokens=636851 threshold=167000 effectiveWindow=180000

API error (attempt 5/11): 429 {"type":"rate_limit_error","message":"Extra usage is required for long context requests."} request_id: req_011CaK9SET6PcTvXrkZa5eZ1

The Misleading Error

When /compact fails on Sonnet, the error shown is:

"Extra usage is required for 1M context · enable extra usage at claude.ai/settings/usage, or use --model to switch to standard context"

This is inaccurate and misleading in this scenario:

  • The user was never on a 1M context model — the session was built on standard Opus
  • "Extra usage" is not needed — no paid upgrade is required
  • "Switch to standard context" is the opposite of what helps — the user needs to switch back to the larger model (Opus), not a smaller "standard" one
  • The actual fix requires zero new permissions: just /model back to Opus → /compact

The error misdirects users toward a paid plan upgrade when the real solution is free and already available to them.

Suggested Fixes

Option A — Prevent it before it happens (ideal):
Before completing a model switch, check if the session's current token count exceeds the target model's effective context window. If it does:

  • Auto-compact using the current model first, then switch (show a status line: "Compacting session before switching to Sonnet…")
  • OR warn: "Your session (637k tokens) exceeds Sonnet's context window (180k). Run /compact first, or stay on Opus."

Option B — Show recovery guidance when already stuck:
When both a user message and /compact fail on the current model, display:
"Session context is too large for this model. Switch back to [claude-opus-4-7] and run /compact to recover your session — no extra usage or plan change required."

Option C — Fix the misleading error message:
Replace the current "Extra usage is required for 1M context" message (which implies a paid upgrade is needed) with one that accurately describes the situation:
"Session context (637k tokens) exceeds Sonnet's standard context window. Switch back to Opus with /model claude-opus-4-7, run /compact, then switch to your preferred model."

Screenshot

<img width="1296" height="885" alt="Image" src="https://github.com/user-attachments/assets/6352cdaf-f116-4953-a87c-830c0463aa92" />

Related Issues

  • #23377 — Session-breaking "Prompt is too long" with no recovery path (open/critical). Same symptom, different trigger — no model switch involved, just organic context exhaustion.
  • #15896 — VS Code /compact failure after "Prompt is too long". Overlapping symptom.
  • #14472 — CLI resume deadlock when context exceeds limit. Same "can't compact when over limit" pattern.

extent analysis

TL;DR

Switching back to the original model (Opus) and running /compact can resolve the issue when a session becomes stuck after switching to a lighter model (Sonnet).

Guidance

  • To prevent the issue, consider implementing a check before completing a model switch to ensure the session's current token count does not exceed the target model's effective context window.
  • If the session is already stuck, display guidance to the user to switch back to the original model and run /compact to recover the session.
  • The misleading error message should be revised to accurately describe the situation and provide the correct recovery steps.
  • Consider auto-compact using the current model before switching to a lighter model to prevent the issue.

Example

No code snippet is provided as the issue is more related to the logic and error handling of the application.

Notes

The provided solutions are based on the information given in the issue and may not cover all possible scenarios. It's essential to test and verify the fixes to ensure they work as expected.

Recommendation

Apply workaround: Switch back to the original model (Opus) and run /compact when the session becomes stuck after switching to a lighter model (Sonnet), as this approach has been proven to resolve the issue without requiring any paid upgrades or changes to the user's plan.

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