Graceful handling when API returns 'Could not process image' - session becomes unrecoverable

Resolved 💬 3 comments Opened Feb 28, 2026 by baochipham942-eng Closed Mar 3, 2026

Problem

When too many images accumulate in the conversation context (e.g., >20 images from user uploads or MCP tool results), the Anthropic API returns:

API Error: 400
{"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}

This error makes the entire session unrecoverable:

  1. Every subsequent API call resends the full context (including the problematic images)
  2. Every call fails with the same error
  3. /compact also fails — because compaction itself requires an API call that includes the same context
  4. /exit says "Bye!" but the session continues and keeps failing
  5. The user is trapped in a dead session with no way to recover except force-killing the terminal

Expected Behavior

  1. Pre-flight image count check: Before sending a request, count the number of image blocks in the conversation context. If approaching the API limit (~20), warn the user and suggest compacting or splitting the work.
  1. Graceful error recovery: When receiving "Could not process image" error, Claude Code should:
  • Detect this specific error pattern
  • Automatically strip/drop the problematic image(s) from the context
  • Retry the request without the images
  • Inform the user that some images were dropped to recover the session
  1. Emergency compaction: /compact should have a fallback mode that strips all image blocks from context before attempting the compaction API call, so it can always succeed as a last resort.

Reproduction Steps

  1. Start a Claude Code session
  2. Upload or generate 20+ images in the conversation (e.g., via chrome-devtools MCP extracting charts from a paper)
  3. Every subsequent interaction fails with "Could not process image"
  4. /compact fails, /exit fails, session is dead

Impact

  • Lost a 23-hour session ($66+ in API costs)
  • All conversation context lost (file changes on disk were preserved)
  • No warning before hitting the limit
  • No recovery mechanism once the limit is hit

Environment

  • Claude Code (latest)
  • macOS

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗