Explore agent crashes on corrupt/stub PNG files (API 400: "Could not process image")

Resolved 💬 3 comments Opened Mar 10, 2026 by saint-cygnum Closed Mar 14, 2026

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

  1. Place a near-empty PNG file (e.g., 69 bytes — just the PNG header, no actual image data) in a project directory
  2. Launch an Explore agent that scans that directory
  3. The Read tool detects the .png extension 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.

View original on GitHub ↗

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