Read tool enters infinite retry loop when .jpg file contains HTML (400 'Could not process image')
Resolved 💬 4 comments Opened Mar 21, 2026 by acabreragnz Closed Mar 21, 2026
Bug Description
When a file has a .jpg extension but contains HTML content, the Read tool attempts to process it as an image, the API returns 400 invalid_request_error: Could not process image, and Claude Code enters an infinite retry loop that the user cannot escape from within the same session.
Minimal Reproducible Example
No external services needed — just create a fake image locally:
echo '<!doctype html><html><head><title>Login</title></head><body><h1>Please log in</h1></body></html>' > /tmp/fake_image.jpg
Then ask Claude Code to read it:
"Read the file /tmp/fake_image.jpg"
Result: Claude sends it to the image API → 400 Could not process image → infinite retry loop.
How This Happens in Practice
Any URL that returns HTML instead of an image (auth redirects, login walls, CDN errors) when downloaded with curl and saved with a .jpg extension will trigger this. Example:
# URL requires auth → server returns HTML login page → saved as .jpg
curl -sL "https://some-service.com/protected/image.jpg" -o /tmp/img.jpg
file /tmp/img.jpg # → HTML document, ASCII text
Expected Behavior
Readtool should detect actual file content type (magic bytes, not extension) before sending to image API- If API returns
400 Could not process image, Claude Code should surface the error once and stop — no retries
Actual Behavior
API Error: 400 {"type":"invalid_request_error","message":"Could not process image"}repeated multiple times- Claude keeps retrying with the same broken file
- Session gets stuck — user has to abandon the conversation
Environment
- Platform: Linux (Ubuntu), zsh
- Claude Code version: claude/main-NiROL
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗