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:
- Every subsequent API call resends the full context (including the problematic images)
- Every call fails with the same error
/compactalso fails — because compaction itself requires an API call that includes the same context/exitsays "Bye!" but the session continues and keeps failing- The user is trapped in a dead session with no way to recover except force-killing the terminal
Expected Behavior
- 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.
- 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
- Emergency compaction:
/compactshould 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
- Start a Claude Code session
- Upload or generate 20+ images in the conversation (e.g., via chrome-devtools MCP extracting charts from a paper)
- Every subsequent interaction fails with "Could not process image"
/compactfails,/exitfails, 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
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗