Prompt is too long error blocks work without graceful recovery
Bug Description
Pasting an image (screenshot) into Claude Code while the agent is processing causes an instant "Conversation too long" error that kills the session with no recovery. This happens because a single base64-encoded screenshot can consume ~334K tokens, which instantly overflows the 180K context window — bypassing autocompact entirely.
Root Cause (from logs)
A single full-screen screenshot encoded as base64 in the message payload consumes approximately 334,000 tokens. The autocompact threshold is 167,000 tokens with an effective window of 180,000. There is no pre-check that validates whether an incoming image will exceed the context limit before adding it to the conversation.
Exact sequence from logs (2026-04-16)
23:43:15 — User sends text message. autocompact: tokens=17,616 (post-compact, healthy)
23:43:19 — User pastes a screenshot (base64 PNG image)
23:44:19 — autocompact: tokens=351,512 (jumped from 17K → 351K)
23:44:19 — ERROR: "Conversation too long. Press esc twice..."
Session is dead.
The same pattern occurred 6 times today across different sessions:
- 15:35:29 (3 crashes in quick succession as user retried)
- 17:20:32
- 23:44:19
- 23:47:31
Steps to Reproduce
- Open Claude Code in VS Code extension
- Start a conversation (any amount of context)
- While the agent is processing (thinking/running tools), paste a screenshot
- The session immediately dies with "Conversation too long"
Note: This also happens when the agent is NOT processing — any large screenshot can overflow the context.
Expected Behavior
- Images should be resized/compressed before being added to the conversation if they would exceed the context limit
- Or: a pre-check should reject oversized images with a clear error message ("Image too large, please resize") instead of killing the session
- Or: images should be processed through a vision-optimized pipeline that doesn't consume 334K tokens for a single screenshot
- The session should NEVER die silently from a user action (pasting an image)
Actual Behavior
- Base64 image is added to the conversation without any size check
- A single screenshot instantly consumes ~334K tokens (nearly 2x the entire context window)
- autocompact cannot help because the single message already exceeds the window
- Session dies with an unrecoverable error
Environment
- Claude Code VS Code extension v2.1.42
- Linux (Ubuntu 24.04)
- Model: Claude Opus 4.6
- Context window: 180,000 tokens effective, 167,000 autocompact threshold
Impact
This is a workflow-breaking issue. Users who paste screenshots for visual context (Telegram output, UI state, error screenshots) lose their entire session instantly. The error gives no indication of what caused it or how to avoid it. The "Press esc twice" suggestion doesn't help in the VS Code extension.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗