claude-code - 💡(How to fix) Fix [BUG] [BUG] Claude Code on the Web: empty text block with cache_control causes 400 after sending an image, permanently breaks the session [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#52689Fetched 2026-04-24 10:42:21
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
2
Author
Timeline (top)
labeled ×4commented ×1

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.

Error Message

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" }

Root Cause

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.

Fix Action

Fix / Workaround

Workaround I Found

Workaround I Found

Workaround I Found

Code Example

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"
}

---

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"
}

---



---

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"
}
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?

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_Website and others)
  • Repo has .claude/settings.json with a UserPromptSubmit hook injecting additionalContext

Steps to Reproduce

  1. Open a Claude Code on the Web session on any repo
  2. Paste or attach an image (e.g. screenshot from clipboard) without typing any accompanying text and send
  3. Wait for the response — it may succeed once or fail immediately
  4. Send any follow-up message (text or image)
  5. Observe: every subsequent turn fails with the 400 error shown below

Expected Behavior

  • Empty text blocks should not have cache_control attached 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 again retries 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-empty
  • req_011CaMsQ44cNwYHivCHXT6gqmessages.680.content.4.text: cache_control cannot be set for empty text blocks
  • req_011CaMscjQonwGjBfBdHWwnEmessages.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:

  1. Strip content blocks whose text is empty, OR
  2. Do not attach cache_control to empty text blocks, OR
  3. 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_Website and others)
  • Repo has .claude/settings.json with a UserPromptSubmit hook injecting additionalContext

Steps to Reproduce

  1. Open a Claude Code on the Web session on any repo
  2. Paste or attach an image (e.g. screenshot from clipboard) without typing any accompanying text and send
  3. Wait for the response — it may succeed once or fail immediately
  4. Send any follow-up message (text or image)
  5. Observe: every subsequent turn fails with the 400 error shown below

Expected Behavior

  • Empty text blocks should not have cache_control attached 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 again retries 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-empty
  • req_011CaMsQ44cNwYHivCHXT6gqmessages.680.content.4.text: cache_control cannot be set for empty text blocks
  • req_011CaMscjQonwGjBfBdHWwnEmessages.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:

  1. Strip content blocks whose text is empty, OR
  2. Do not attach cache_control to empty text blocks, OR
  3. 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_Website and others)
  • Repo has .claude/settings.json with a UserPromptSubmit hook injecting additionalContext

Steps to Reproduce

  1. Open a Claude Code on the Web session on any repo
  2. Paste or attach an image (e.g. screenshot from clipboard) without typing any accompanying text and send
  3. Wait for the response — it may succeed once or fail immediately
  4. Send any follow-up message (text or image)
  5. Observe: every subsequent turn fails with the 400 error shown below

Expected Behavior

  • Empty text blocks should not have cache_control attached 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 again retries 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-empty
  • req_011CaMsQ44cNwYHivCHXT6gqmessages.680.content.4.text: cache_control cannot be set for empty text blocks
  • req_011CaMscjQonwGjBfBdHWwnEmessages.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:

  1. Strip content blocks whose text is empty, OR
  2. Do not attach cache_control to empty text blocks, OR
  3. 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

extent analysis

TL;DR

The issue can be mitigated by ensuring that empty text blocks do not have cache_control attached or by stripping such blocks before sending the API request.

Guidance

  • Before constructing the API request, strip content blocks whose text is empty to prevent the Anthropic API from rejecting the request with a 400 error.
  • Alternatively, do not attach cache_control to empty text blocks to avoid the error.
  • Coercing empty text blocks to a single-space placeholder could also resolve the issue.
  • When attaching an image, always type at least one character of accompanying text to avoid triggering the error.

Example

No specific code example is provided as the issue seems to be related to the client-side logic of handling empty text blocks and attaching cache_control. However, the suggested fix direction implies modifying the client-side code to handle empty text blocks appropriately.

Notes

The provided information suggests that this is a regression, indicating that the issue was not present in a previous version. The exact version where this started occurring is not specified, but it is happening with Claude Code version 4.7.

Recommendation

Apply the workaround of always typing at least one character of accompanying text when attaching an image until a permanent fix is implemented on the client side to handle empty text blocks correctly.

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