claude-code - 💡(How to fix) Fix [Bug] Read on mislabeled .png causes unrecoverable 'Could not process image' session corruption [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47976Fetched 2026-04-15 06:36:57
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
labeled ×5subscribed ×1

Error Message

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

Root Cause

  • I have searched existing issues and found related reports, but this includes a more precise root cause and reproduction shape
  • This is a single bug report
  • I am using the latest Claude Code version involved in the failure (session recorded on 2.1.104)

Code Example

{"success":true,"format":"png","data":"<base64 PNG bytes>"}

---

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

---

{"success":true,"format":"png","data":"iVBORw0KGgoAAAANSUhEUgAA..."}

---

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

---

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"},"request_id":"req_011Ca3skZB4K7sqrsbuQfnCB"}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and found related reports, but this includes a more precise root cause and reproduction shape
  • This is a single bug report
  • 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

extent analysis

TL;DR

Validate file contents and MIME type before constructing an image content block to prevent Claude Code from corrupting a session when reading a file with an image extension that is not an actual image file.

Guidance

  • Inspect file signatures and MIME types instead of relying solely on filename extensions to determine file type.
  • Implement input validation to check if a file with an image extension is actually an image before emitting an image content block.
  • If the API rejects an image block, remove that image from context to allow the session to recover.
  • Consider adding error handling to handle cases where the file contents are text/JSON instead of image data.

Example

No code snippet is provided as the issue is more related to the logic and validation of file types rather than a specific code implementation.

Notes

The suggested fix involves modifying the Read tool to validate file contents and MIME types, which may require updates to the Claude Code CLI. Additionally, the issue is closely related to other unrecoverable image-context failures, and fixing this specific case may not resolve all related issues.

Recommendation

Apply a workaround by validating file contents and MIME types before constructing an image content block, as this is a more targeted solution to the specific issue described.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [Bug] Read on mislabeled .png causes unrecoverable 'Could not process image' session corruption [1 participants]