Image processing failure silently passes oversized images into context, bricking sessions
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When the native image processor (sharp) fails to resize an oversized image (e.g., module not available, unsupported format, corrupt image), the error path silently passes the raw, unresized image into the conversation context. If the conversation has accumulated many images, this triggers the API's stricter many-image dimension limit (2000px), returning:
API Error: 400 "image dimensions exceed max allowed size for many-image requests: 2000 pixels"
Since the oversized image is now embedded in the conversation history, every subsequent request fails with the same error. The session is permanently bricked until the user runs /clear or restarts.
Root Cause
The image resize pipeline already correctly targets 2000x2000px (WB=2000, ZB=2000 in the bundled code). The problem is not the target dimension — it's what happens when the resize fails.
The image processing error classifier handles several failure modes (module not found, unsupported format, corrupt header, dimension exceeded, OOM, timeout, Vips errors), but when these errors occur during resize of an oversized image, the code falls through and includes the original oversized image in the message context anyway.
The v2.1.42 fix ("Fixed image dimension limit errors to suggest /compact") only added a text suggestion in the API error handler:
"An image in the conversation exceeds the dimension limit for many-image requests (2000px). Run /compact to remove old images from context"
This doesn't actually fix the session — the oversized image remains in context, and every subsequent API call (including any triggered by /compact) continues to fail with the same error.
Related: #16173, #13480, #2939
What Should Happen?
When the image processor fails to resize an oversized image, do not include the raw image in context. Instead, return a text block:
{
"type": "text",
"text": "Could not process image: dimensions exceed 2000px and the image processor failed. Please resize the image manually or use a smaller image."
}
This keeps the session healthy and gives the user actionable feedback.
Additionally, the API error handler for "image dimensions exceed max allowed size for many-image requests" should trigger auto-compact rather than just suggesting /compact, since at that point the session is already unrecoverable without intervention.
Steps to Reproduce
- Start a Claude Code session on a system where the native image processor may fail (or simulate a failure)
- Accumulate several images in the conversation through screenshots or the Read tool
- Include an image that exceeds 2000px in any dimension where the resize fails (e.g., unsupported format)
- The raw oversized image enters context silently
- The API returns the 400 "many-image" dimension error
- Every subsequent prompt fails with the same error — session is bricked
Claude Code Version
2.1.76
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
zsh
This issue has 12 comments on GitHub. Read the full discussion on GitHub ↗