claude-code - 💡(How to fix) Fix Prompt is too long error blocks work without graceful recovery [3 comments, 3 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#49552Fetched 2026-04-17 08:37:54
View on GitHub
Comments
3
Participants
3
Timeline
10
Reactions
0
Timeline (top)
labeled ×5commented ×3closed ×1cross-referenced ×1

Error Message

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.

Root Cause

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.

Code Example

23:43:15User sends text message. autocompact: tokens=17,616 (post-compact, healthy)
23:43:19User pastes a screenshot (base64 PNG image)
23:44:19 — autocompact: tokens=351,512 (jumped from 17K → 351K)
23:44:19ERROR: "Conversation too long. Press esc twice..."
           Session is dead.
RAW_BUFFERClick to expand / collapse

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

  1. Open Claude Code in VS Code extension
  2. Start a conversation (any amount of context)
  3. While the agent is processing (thinking/running tools), paste a screenshot
  4. 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.

extent analysis

TL;DR

Implement a pre-check to validate the size of incoming images before adding them to the conversation to prevent exceeding the context limit.

Guidance

  • Consider adding a size check for base64-encoded images before they are added to the conversation, rejecting those that would exceed the 167,000 token autocompact threshold or the 180,000 token effective window.
  • Implement image resizing or compression to reduce the token size of large images, ensuring they fit within the context window.
  • Explore using a vision-optimized pipeline for processing images, which might reduce the token consumption for a single screenshot.
  • Provide a clear error message when an image is too large, such as "Image too large, please resize," to inform the user of the issue and how to resolve it.

Example

No specific code example can be provided without knowing the exact implementation details of the Claude Code VS Code extension. However, the logic would involve checking the size of the base64-encoded image and either resizing it, rejecting it with an error message, or processing it through a more efficient pipeline.

Notes

The solution may require adjustments based on the specific requirements of the Claude Code extension and the trade-offs between image quality, token consumption, and user experience. It's also important to consider the user workflow and provide intuitive feedback when an image is too large.

Recommendation

Apply a workaround by implementing a pre-check for image size and providing a clear error message for oversized images, as this directly addresses the root cause of the issue and improves the user experience by preventing silent session deaths.

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