claude-code - 💡(How to fix) Fix [BUG] API 400 Error and Session crash when reading conf files with obfuscated image extensions (e.g., .conf renamed to .png) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#50840Fetched 2026-04-20 12:11:35
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Error Message

Read 1 file (ctrl+o to expand) └ API Error: 400 { "type": "error", "error": "type": "invalid_request_error", "message": "Could not process image" }, "request_id": "req_672CaLCcaoe6XzzuOEYw3"}

It appears that when Claude Code builds the API payload, it strictly relies on the .png extension to format the block (e.g., attempting to process it as an image/base64 block) rather than relying on its actual text content. The Anthropic API then rejects the malformed image payload, resulting in a 400 error. Because this malformed request state is saved in the chat history, the session remains broken until rewound.

Root Cause

It appears that when Claude Code builds the API payload, it strictly relies on the .png extension to format the block (e.g., attempting to process it as an image/base64 block) rather than relying on its actual text content. The Anthropic API then rejects the malformed image payload, resulting in a 400 error. Because this malformed request state is saved in the chat history, the session remains broken until rewound.

Code Example

Read 1 file (ctrl+o to expand)
API Error: 400 { "type": "error", "error":  "type": "invalid_request_error", "message": "Could not process image" }, "request_id": "req_672CaLCcaoe6XzzuOEYw3"}

It appears that when Claude Code builds the API payload, it strictly relies on the .png extension to format the block (e.g., attempting to process it as an image/base64 block) rather than relying on its actual text content. The Anthropic API then rejects the malformed image payload, resulting in a 400 error. Because this malformed request state is saved in the chat history, the session remains broken until rewound.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

I encountered a severe issue where reading and modifying a configuration file [ Managed by deployment configuration pipeline, File size around 60 KB ] with an obfuscated extension reliably triggers an HTTP 400 API error and corrupts the current session state.

In my scenario, I had a .conf file that was uploaded to a server with its extension intentionally obfuscated as .png. When sync the entire project , Claude Code correctly recognizes that it is not a real image file. However, when I explicitly prompt Claude Code to read and modify this specific file, it triggers a continuous 400 Bad Request error.

Claude Code correctly recognized that it was a config file rather than an actual PNG. Furthermore, I explicitly instructed it to read the file as plain text. It proceeded to initiate the read operation... [Read Tool]

What Should Happen?

Once this error is triggered, the session gets stuck in a broken state. I attempted the following to recover: Failed: Ran /compact – Issue persisted. Failed: Exited the tool and used resume to reload the session – Issue persisted (repeated 3 times). Success: Used /rewind to roll back the conversation history before the file read attempt. This was the only way to save the session.

Error Messages/Logs

Read 1 file (ctrl+o to expand)
└ API Error: 400 { "type": "error", "error":  "type": "invalid_request_error", "message": "Could not process image" }, "request_id": "req_672CaLCcaoe6XzzuOEYw3"}

It appears that when Claude Code builds the API payload, it strictly relies on the .png extension to format the block (e.g., attempting to process it as an image/base64 block) rather than relying on its actual text content. The Anthropic API then rejects the malformed image payload, resulting in a 400 error. Because this malformed request state is saved in the chat history, the session remains broken until rewound.

Steps to Reproduce

  1. Create some [ In my situation is more then 5 ] standard text configuration file (e.g., settings.conf) 60-70kb.
  2. Obfuscate the extension by renaming it to an image format (e.g., settings.png).
  3. Include this file in the project context and ask Claude Code to read and modify its contents.
  4. The API will throw an HTTP 400 error.

Claude Code should gracefully handle mismatched MIME types/extensions. It should either read the file as raw text if the contents are plainly readable, or return a local error indicating the file format is unsupported, without attempting a malformed API call that poisons the session history.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.114 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Extension obfuscation is common practice. We change it all the time, SVG, JPG, GIF. Hitting this 400 error on my first production tweak with Claude Code was definitely a rough start.

<img width="1886" height="328" alt="Image" src="https://github.com/user-attachments/assets/18f99b56-2579-4f9d-a4c8-43cff487755e" />

extent analysis

TL;DR

The issue can be fixed by modifying Claude Code to handle mismatched MIME types/extensions, allowing it to read files as raw text or return a local error when the file format is unsupported.

Guidance

  • Verify that the issue is indeed caused by the mismatch between the file extension and its actual content by checking the API payload construction in Claude Code.
  • Check if there are any existing configuration options or flags that can be used to force Claude Code to read files as plain text, regardless of their extension.
  • Consider implementing a workaround that checks the file's magic number or header to determine its actual type before attempting to read or modify it.
  • Review the Anthropic API documentation to see if there are any specific requirements or recommendations for handling files with mismatched MIME types/extensions.

Example

No code snippet is provided as the issue does not contain sufficient information about the internal workings of Claude Code or the Anthropic API.

Notes

The issue seems to be a regression, as it worked in a previous version of Claude Code. The fact that the issue persists even after attempting to recover the session using /compact and exiting and resuming the tool suggests that the problem is deeply rooted in the way Claude Code handles file types.

Recommendation

Apply a workaround that checks the file's actual type before attempting to read or modify it, as the root cause of the issue seems to be the mismatch between the file extension and its actual content. This will prevent the API from throwing a 400 error and corrupting the session state.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING