[BUG] API 400 text content blocks must be non-empty after pasting an image with Enter, contaminates session permanently

Resolved 💬 8 comments Opened Apr 28, 2026 by raphaelhiguera Closed Jun 25, 2026

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?

When pasting an image into the chat input and pressing Enter immediately (without typing accompanying text), claude.ai/code serializes the message with an empty trailing text block that has cache_control applied. The Anthropic API rejects the request with HTTP 400, and because the malformed message stays in the conversation history, every subsequent request in the same session fails with the same error. The session is dead until I start a new one.
Errors observed:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"}}
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.58.content.1.text: cache_control cannot be set for empty text blocks"}}

What Should Happen?

The frontend should never send an empty text block in content[]. Empty text blocks should be filtered out before serialization, and cache_control should never be applied to empty text blocks. For image-only user messages, the payload should be content: [{type: "image", ...}] with no trailing empty text block.
Currently, when the user pastes an image and presses Enter without typing text, the frontend produces content: [{type: "image", ...}, {type: "text", text: ""}] with cache_control on the empty trailing block. This shape is invalid per the API contract and the request fails.

Error Messages/Logs

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011CaWBueBPT5K18W9QUR2fh"}
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.58.content.1.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011CaWBtHJzUweTAjCYLQMvC"}
Other request_ids observed in the same broken session:
req_011CaWBwk59itC3G3puYzg6p
req_011CaWC1xGEpSBP6eR2bE1L1
req_011CaWC7mVWE664vJ7hRRcJN

Steps to Reproduce

  1. Open any session in claude.ai/code.
  2. Paste an image (Cmd/Ctrl+V) into the input.
  3. Press Enter immediately, without typing any text.
  4. From that point on, every message returns 400 with the errors above.
  5. The only recovery is to start a new session.

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

NA

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

IMPORTANT CONTEXT: This bug occurs in claude.ai/code (the web app), not in the Claude Code CLI. Some fields above (Terminal/Shell, Claude Code Version) don't apply directly — please consider this report against the web frontend.
Suggested fix
In the message serializer:

  1. Before applying cache_control, filter out blocks where type === "text" && text.trim() === "".
  2. After tool_use blocks, do not append a trailing empty text block — only emit a text block if the model produced text.
  3. For image-only user messages, ensure the payload is content: [{type: "image", ...}] without a trailing empty text block.

Impact
This blocks long sessions in claude.ai/code for users who share screenshots — a very common pattern. Every contaminated session is unrecoverable, forcing context loss. Several internal sessions have died this way over the past week.
Related
This appears to share root cause with the issue we observed when @modelcontextprotocol/server-memory was active in long sessions — we removed Memory and the bug persisted, which led us to identify the image+Enter trigger as the dominant path.
Browser: [poné el que uses, ej: Chrome 130 / Firefox / Safari]
Surface: claude.ai/code (web)

View original on GitHub ↗

This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗