[Bug] Read on mislabeled .png causes unrecoverable 'Could not process image' session corruption
Preflight Checklist
- [x] I have searched existing issues and found related reports, but this includes a more precise root cause and reproduction shape
- [x] This is a single bug report
- [x] I am using the latest Claude Code version involved in the failure (session recorded on 2.1.104)
What's Wrong?
Claude Code can permanently corrupt a session when the Read tool is used on a file with an image extension that is not actually an image file on disk.
In my case, a file named flywheel-diagram.png was created by a local export endpoint, but the file contents were actually JSON text:
{"success":true,"format":"png","data":"<base64 PNG bytes>"}
Claude Code appears to infer from the .png path that the file is an image, then sends it as an image content block. The API rejects it with:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}
After that, the bad image stays in context and every subsequent turn fails with the same error. The session becomes unusable until I rewind the session history.
Why this is a distinct bug shape
There are existing reports for:
- valid-but-unprocessable images
- oversized images
- image attachments causing unrecoverable loops
This report is narrower and more actionable:
a file with .png extension contained JSON text, and Claude Code still turned it into an image block instead of rejecting it as non-image content.
So there appear to be two failures:
- Input validation failure —
Readshould verify that a.pngfile is actually a PNG before emitting an image block - Recovery failure — once the image is rejected by the API, Claude Code should drop that image from context instead of poisoning the session forever
Steps to Reproduce
- Create a file named something like
foo.png - Put JSON text into it instead of PNG bytes, for example:
{"success":true,"format":"png","data":"iVBORw0KGgoAAAANSUhEUgAA..."}
- Ask Claude Code to
Readthat file - Claude Code emits an image content block
- Anthropic API returns:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}
- Send any follow-up message
- The same error repeats on every turn; session is effectively bricked
Expected Behavior
Claude Code should do one or more of:
- Inspect file signatures / MIME instead of trusting the filename extension alone
- If the file is not a real image, return text/metadata instead of image content
- If the API rejects an image block, remove that image from context for subsequent turns
- Allow
/compact,/resume, or normal follow-up prompts to proceed after surfacing the failure
Actual Behavior
Readon the mislabeled.pngcaused an image block to enter context- API returned
400 Could not process image - every subsequent turn repeated the same error
- the only recovery was rewinding the session
Concrete Evidence from Session
Session details:
- Claude Code version in transcript metadata:
2.1.104 - Platform: Linux
Observed sequence:
- export command wrote
.../flywheel-diagram.png - Claude Code then executed
Readon that path - the
Readtool result contained an image block whose base64 payload decoded to JSON, not raw PNG bytes - decoding that outer JSON's
datafield produced a valid PNG - local inspection of the file with
filereported:JSON text data - Pillow could not open it as an image
In other words, the file on disk was not a PNG even though it had a .png extension.
Representative Error
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"},"request_id":"req_011Ca3skZB4K7sqrsbuQfnCB"}
After that, later turns in the same session also failed with the same message until rewind.
Environment
- Claude Code CLI
- Version: 2.1.104
- OS: Linux (Ubuntu)
- Working with a local file path read via the built-in
Readtool
Suggested Fix
For Read on image-like paths:
- Validate magic bytes / MIME before constructing an image content block
- If file contents are text/JSON, treat them as text even if the extension is
.png - If image processing fails upstream, quarantine/drop the offending image block from future requests so the session can recover
Related Issues
This seems closely related to other unrecoverable image-context failures, but the mislabeled-file-path case may make the root cause easier to reproduce and fix:
- #47391
- #47804
- #42256
- #44735
- #36511
- #24387
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗