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

  1. Read tool should detect actual file content type (magic bytes, not extension) before sending to image API
  2. 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

View original on GitHub ↗

4 Comments

github-actions[bot] · 6 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/24387
  2. https://github.com/anthropics/claude-code/issues/19031
  3. https://github.com/anthropics/claude-code/issues/32764

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

acabreragnz · 6 months ago

Additional finding — loop is task-context dependent

Tested with a subagent asked to simply "read /tmp/fake_image.jpg" → it failed with 400 and 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.

acabreragnz · 6 months ago

Closing as duplicate of #24387 which describes the exact same root cause. 👍 that issue instead.

github-actions[bot] · 6 months ago

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.