[Bug] Read on mislabeled .png causes unrecoverable 'Could not process image' session corruption

Resolved 💬 8 comments Opened Apr 14, 2026 by eltmon Closed May 19, 2026

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:

  1. Input validation failureRead should verify that a .png file is actually a PNG before emitting an image block
  2. 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

  1. Create a file named something like foo.png
  2. Put JSON text into it instead of PNG bytes, for example:
{"success":true,"format":"png","data":"iVBORw0KGgoAAAANSUhEUgAA..."}
  1. Ask Claude Code to Read that file
  2. Claude Code emits an image content block
  3. Anthropic API returns:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}
  1. Send any follow-up message
  2. The same error repeats on every turn; session is effectively bricked

Expected Behavior

Claude Code should do one or more of:

  1. Inspect file signatures / MIME instead of trusting the filename extension alone
  2. If the file is not a real image, return text/metadata instead of image content
  3. If the API rejects an image block, remove that image from context for subsequent turns
  4. Allow /compact, /resume, or normal follow-up prompts to proceed after surfacing the failure

Actual Behavior

  • Read on the mislabeled .png caused 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 Read on that path
  • the Read tool result contained an image block whose base64 payload decoded to JSON, not raw PNG bytes
  • decoding that outer JSON's data field produced a valid PNG
  • local inspection of the file with file reported: 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 Read tool

Suggested Fix

For Read on image-like paths:

  1. Validate magic bytes / MIME before constructing an image content block
  2. If file contents are text/JSON, treat them as text even if the extension is .png
  3. 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

View original on GitHub ↗

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