Read command fails with API error when file extension doesn't match content type
Resolved 💬 3 comments Opened Aug 4, 2025 by jamesbrink Closed Aug 15, 2025
Environment
- Platform (select one):
- [x] Anthropic API (Claude Max Account)
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: v1.0.67
- Operating System: macOS 15.5 (Darwin 24.5.0 ARM64)
- Terminal: Alacritty
Bug Description
Claude Code's Read command fails with an API error when attempting to read a file with an image extension (.png) that actually contains ASCII/text content. The tool appears to determine file type based solely on file extension rather than inspecting actual file content (e.g., using libmagic or similar content detection).
Steps to Reproduce
- Create a file with an image extension but containing text/ASCII content:
``bash``
echo "Binary file content copied from src/images/watt-media-logo.png" > public/images/watt-media-logo.png
- In Claude Code, attempt to read the file:
````
Read(public/images/watt-media-logo.png)
- Observe the API error response
Confirmed Reproduction
Successfully reproduced in Claude Code session 4537ba6f-f11d-4884-bb8c-ed61eddf265a:
⏺ Bash(echo "Binary file content copied from src/images/watt-media-logo.png" > public/images/watt-media-logo.png)
⎿ (No content)
⏺ Read(public/images/watt-media-logo.png)
⎿ Read image (63 bytes)
⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}
Expected Behavior
Claude Code should:
- Detect the actual file content type (text/ASCII) regardless of file extension
- Successfully read and display the text content
- Or at minimum, handle the mismatch gracefully without throwing an API error
Actual Behavior
- Claude Code assumes the file is an image based on the
.pngextension - Attempts to process it as an image
- Returns API Error 400:
{"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}} - The error prevents reading the actual file content
Additional Context
- The file in question was corrupted during a GitHub Action workflow, resulting in a
.pngfile containing ASCII text - Running
cat public/images/watt-media-logo.pngsuccessfully displays:Binary file content copied from src/images/watt-media-logo.png - This suggests proper file type detection (similar to how the
filecommand uses libmagic) would prevent this issue - The error occurs even when explicitly instructing Claude Code not to read the file, suggesting the type detection happens before user input is considered
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗