Explore agent crashes on corrupt/stub PNG files (API 400: "Could not process image")
Description
When the Explore agent (or any subagent using the Read tool) encounters a corrupt or stub PNG file, it crashes with an unrecoverable API 400 error instead of gracefully skipping the file.
Steps to Reproduce
- Place a near-empty PNG file (e.g., 69 bytes — just the PNG header, no actual image data) in a project directory
- Launch an Explore agent that scans that directory
- The Read tool detects the
.pngextension and attempts to send it to the API as an image
Expected Behavior
The agent should gracefully handle the malformed image — either skip it, log a warning, or fall back to treating it as a binary file.
Actual Behavior
The API returns a 400 error:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"},"request_id":"req_011CYvB5E7MK1MK2gxSEh1pt"}
The agent does not recover. Clicking "continue" retries and hits the same error again, making the agent unusable until the corrupt file is removed from disk.
Environment
- Claude Code VSCode extension
- Model: claude-opus-4-6
- OS: Linux (WSL2)
Root Cause Analysis
The Read tool identifies files by extension and sends .png files to the API as images. There's no validation that the file contains a valid, decodable image before sending it. A 69-byte file with a PNG header but no image data is enough to trigger image processing, but the API rejects it.
Suggested Fix
Validate image files before sending to the API — check minimum file size and/or attempt to decode headers. If validation fails, either skip the file or return a text message like "Could not read image: file appears corrupt" instead of crashing the agent.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗