Read tool enters infinite retry loop when .jpg file contains HTML (400 'Could not process image')
Status Fixed / completed
Maintainer reply None cached
Activity 4 comments · opened Mar 21, 2026 · 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
4 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Additional finding — loop is task-context dependent
Tested with a subagent asked to simply "read /tmp/fake_image.jpg" → it failed with
400and stopped correctly.The infinite loop seems to occur when Claude has a higher-level goal that requires processing the images (e.g., "look at these 4 attachments to understand the event"). In that context, Claude keeps retrying because it feels it needs the image content to complete the task — each retry fails with
400, and the loop continues.Suggested fix refinement: after a
400 Could not process image, Claude should treat the file as unreadable and continue the task without it — not retry.Closing as duplicate of #24387 which describes the exact same root cause. 👍 that issue instead.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.