Skip to content

Corrupted image in context causes persistent API 400 errors, breaking the entire chat session #19031

@erold90

Description

@erold90

Bug Description

When Claude Code reads a corrupted/invalid image file (e.g., a .jpg file that actually contains HTML text), the invalid image data remains in the conversation context and causes persistent API 400 errors ("Could not process image") for all subsequent messages, making the entire chat session unusable.

Steps to Reproduce

  1. Have a file with .jpg extension that contains invalid data (e.g., <html><body>404</body></html> - a 404 error page saved as .jpg)
  2. Ask Claude Code to read/analyze this image file
  3. Claude attempts to read it, receives API error 400
  4. Every subsequent message in that chat session fails with the same error, even unrelated messages

Example

⏺ Read(path/to/corrupted.jpg)
  ⎿  Read image (29 bytes)
  ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}

❯ hello  (completely unrelated message)
  ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}

Expected Behavior

  • The error should be handled gracefully without corrupting the conversation context
  • Invalid image data should be validated/sanitized before being added to the context
  • Or at minimum, the user should be able to continue the conversation after an image processing error

Actual Behavior

The chat session becomes completely unusable. The only workaround is to start a new session, losing all conversation history.

Environment

  • Claude Code CLI
  • macOS (Darwin 24.6.0)

Additional Context

The corrupted file in this case was 29 bytes containing <html><body>404</body></html> - likely a failed download that saved the error page instead of the actual image. This is a common scenario when downloading images from URLs that no longer exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiarea:corebugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions