[BUG] [BUG] Claude Code on the Web: empty text block with cache_control causes 400 after sending an image, permanently breaks the session
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Summary
Sending an image in a Claude Code on the Web session can produce an empty text content block that has cache_control attached. Anthropic API rejects this with a 400 error (cache_control cannot be set for empty text blocks). Once the bad block is in the conversation history, every subsequent turn fails with the same error — the session is permanently unusable and there is no in-UI way to delete the offending message.
Environment
- Claude Code on the Web (claude.ai/code), not the CLI
- Browser: Chrome (please fill in your version — in browser menu → About Chrome)
- OS: macOS (please fill in your version)
- Session: multiple, across different repos (
mixue_usa_franchise_Websiteand others) - Repo has
.claude/settings.jsonwith aUserPromptSubmithook injecting additionalContext
Steps to Reproduce
- Open a Claude Code on the Web session on any repo
- Paste or attach an image (e.g. screenshot from clipboard) without typing any accompanying text and send
- Wait for the response — it may succeed once or fail immediately
- Send any follow-up message (text or image)
- Observe: every subsequent turn fails with the 400 error shown below
Expected Behavior
- Empty text blocks should not have
cache_controlattached on the client side - Or: the API should tolerate empty blocks gracefully
- Or: the UI should let users remove/edit the offending assistant message after such an error
Actual Behavior
- The session enters a permanently broken state
Try sending it againretries all produce the same 400- Editing the most recent user message does not help if the bad block is upstream
- The only recovery is to edit a message from before the bad block or abandon the session
Error Payload
API Error: 400 {
"type":"error",
"error":{
"type":"invalid_request_error",
"message":"messages.84.content.2.text: cache_control cannot be set for empty text blocks"
},
"request_id":"req_011CaMsuUqS3LiLHbcMvTSbf"
}
Additional related request_ids from the same broken session:
req_011CaMsgBnQAWK1wzzMMYC4e— earlier variant:messages: text content blocks must be non-emptyreq_011CaMsQ44cNwYHivCHXT6gq—messages.680.content.4.text: cache_control cannot be set for empty text blocksreq_011CaMscjQonwGjBfBdHWwnE—messages.68?.content.7.text: cache_control cannot be set for empty text blocks
All from within the same session, different turns, different message indices — suggesting multiple empty blocks accumulated over time.
Impact
- Session is unrecoverable through normal UI actions
- Hours of conversation context lost
- Workflow forced into "start a new session" pattern
Workaround I Found
Always type at least one character of accompanying text when attaching an image. Pasting an image with an empty caption appears to be the trigger. Non-empty captions have not reproduced the issue for me.
Suggested Fix Direction
On the client side (Claude Code on the Web), before constructing the API request:
- Strip content blocks whose
textis empty, OR - Do not attach
cache_controlto empty text blocks, OR - Coerce empty text blocks to a single-space placeholder
Screenshots
[Attach screenshot of the error banner + UI here — drag the PNG into this comment box]
What Should Happen?
Summary
Sending an image in a Claude Code on the Web session can produce an empty text content block that has cache_control attached. Anthropic API rejects this with a 400 error (cache_control cannot be set for empty text blocks). Once the bad block is in the conversation history, every subsequent turn fails with the same error — the session is permanently unusable and there is no in-UI way to delete the offending message.
Environment
- Claude Code on the Web (claude.ai/code), not the CLI
- Browser: Chrome (please fill in your version — in browser menu → About Chrome)
- OS: macOS (please fill in your version)
- Session: multiple, across different repos (
mixue_usa_franchise_Websiteand others) - Repo has
.claude/settings.jsonwith aUserPromptSubmithook injecting additionalContext
Steps to Reproduce
- Open a Claude Code on the Web session on any repo
- Paste or attach an image (e.g. screenshot from clipboard) without typing any accompanying text and send
- Wait for the response — it may succeed once or fail immediately
- Send any follow-up message (text or image)
- Observe: every subsequent turn fails with the 400 error shown below
Expected Behavior
- Empty text blocks should not have
cache_controlattached on the client side - Or: the API should tolerate empty blocks gracefully
- Or: the UI should let users remove/edit the offending assistant message after such an error
Actual Behavior
- The session enters a permanently broken state
Try sending it againretries all produce the same 400- Editing the most recent user message does not help if the bad block is upstream
- The only recovery is to edit a message from before the bad block or abandon the session
Error Payload
API Error: 400 {
"type":"error",
"error":{
"type":"invalid_request_error",
"message":"messages.84.content.2.text: cache_control cannot be set for empty text blocks"
},
"request_id":"req_011CaMsuUqS3LiLHbcMvTSbf"
}
Additional related request_ids from the same broken session:
req_011CaMsgBnQAWK1wzzMMYC4e— earlier variant:messages: text content blocks must be non-emptyreq_011CaMsQ44cNwYHivCHXT6gq—messages.680.content.4.text: cache_control cannot be set for empty text blocksreq_011CaMscjQonwGjBfBdHWwnE—messages.68?.content.7.text: cache_control cannot be set for empty text blocks
All from within the same session, different turns, different message indices — suggesting multiple empty blocks accumulated over time.
Impact
- Session is unrecoverable through normal UI actions
- Hours of conversation context lost
- Workflow forced into "start a new session" pattern
Workaround I Found
Always type at least one character of accompanying text when attaching an image. Pasting an image with an empty caption appears to be the trigger. Non-empty captions have not reproduced the issue for me.
Suggested Fix Direction
On the client side (Claude Code on the Web), before constructing the API request:
- Strip content blocks whose
textis empty, OR - Do not attach
cache_controlto empty text blocks, OR - Coerce empty text blocks to a single-space placeholder
Screenshots
[Attach screenshot of the error banner + UI here — drag the PNG into this comment box]
Error Messages/Logs
Steps to Reproduce
Summary
Sending an image in a Claude Code on the Web session can produce an empty text content block that has cache_control attached. Anthropic API rejects this with a 400 error (cache_control cannot be set for empty text blocks). Once the bad block is in the conversation history, every subsequent turn fails with the same error — the session is permanently unusable and there is no in-UI way to delete the offending message.
Environment
- Claude Code on the Web (claude.ai/code), not the CLI
- Browser: Chrome (please fill in your version — in browser menu → About Chrome)
- OS: macOS (please fill in your version)
- Session: multiple, across different repos (
mixue_usa_franchise_Websiteand others) - Repo has
.claude/settings.jsonwith aUserPromptSubmithook injecting additionalContext
Steps to Reproduce
- Open a Claude Code on the Web session on any repo
- Paste or attach an image (e.g. screenshot from clipboard) without typing any accompanying text and send
- Wait for the response — it may succeed once or fail immediately
- Send any follow-up message (text or image)
- Observe: every subsequent turn fails with the 400 error shown below
Expected Behavior
- Empty text blocks should not have
cache_controlattached on the client side - Or: the API should tolerate empty blocks gracefully
- Or: the UI should let users remove/edit the offending assistant message after such an error
Actual Behavior
- The session enters a permanently broken state
Try sending it againretries all produce the same 400- Editing the most recent user message does not help if the bad block is upstream
- The only recovery is to edit a message from before the bad block or abandon the session
Error Payload
API Error: 400 {
"type":"error",
"error":{
"type":"invalid_request_error",
"message":"messages.84.content.2.text: cache_control cannot be set for empty text blocks"
},
"request_id":"req_011CaMsuUqS3LiLHbcMvTSbf"
}
Additional related request_ids from the same broken session:
req_011CaMsgBnQAWK1wzzMMYC4e— earlier variant:messages: text content blocks must be non-emptyreq_011CaMsQ44cNwYHivCHXT6gq—messages.680.content.4.text: cache_control cannot be set for empty text blocksreq_011CaMscjQonwGjBfBdHWwnE—messages.68?.content.7.text: cache_control cannot be set for empty text blocks
All from within the same session, different turns, different message indices — suggesting multiple empty blocks accumulated over time.
Impact
- Session is unrecoverable through normal UI actions
- Hours of conversation context lost
- Workflow forced into "start a new session" pattern
Workaround I Found
Always type at least one character of accompanying text when attaching an image. Pasting an image with an empty caption appears to be the trigger. Non-empty captions have not reproduced the issue for me.
Suggested Fix Direction
On the client side (Claude Code on the Web), before constructing the API request:
- Strip content blocks whose
textis empty, OR - Do not attach
cache_controlto empty text blocks, OR - Coerce empty text blocks to a single-space placeholder
Screenshots
[Attach screenshot of the error banner + UI here — drag the PNG into this comment box]
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
claude code 4.7
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗