[BUG] Session crashes with API 400 errors after very short session - cache_control on empty text blocks
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?
After a very short session (only a few messages), Claude Code becomes completely unusable and returns repeated API 400 errors. The session cannot be continued even after clicking "Try again" or resuming the session.
Three distinct errors appeared in sequence:
Error 1:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.48.content.3.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011Cac7YqWzBPSvKV2qdzjSZ"}
Error 2:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac7jsf2hxnRYKm1Sv8HA"}
Error 3 (after "Resumed session"):
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac9WxydYfKGoUGdUeV8r"}
The session was very short — not a long context issue. Claude Code appears to be generating malformed message history with empty text blocks that have cache_control set on them, which the API rejects. Resuming the session does not fix it. The only workaround is starting a brand new session and losing all prior work.
This is costing paying users money and time.
What Should Happen?
After a very short session (only a few messages), Claude Code becomes completely unusable and returns repeated API 400 errors. The session cannot be continued even after clicking "Try again" or resuming the session.
Three distinct errors appeared in sequence:
Error 1:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.48.content.3.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011Cac7YqWzBPSvKV2qdzjSZ"}
Error 2:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac7jsf2hxnRYKm1Sv8HA"}
Error 3 (after "Resumed session"):
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac9WxydYfKGoUGdUeV8r"}
The session was very short — not a long context issue. Claude Code appears to be generating malformed message history with empty text blocks that have cache_control set on them, which the API rejects. Resuming the session does not fix it. The only workaround is starting a brand new session and losing all prior work.
This is costing paying users money and time.
Error Messages/Logs
After a very short session (only a few messages), Claude Code becomes completely unusable and returns repeated API 400 errors. The session cannot be continued even after clicking "Try again" or resuming the session.
Three distinct errors appeared in sequence:
Error 1:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.48.content.3.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011Cac7YqWzBPSvKV2qdzjSZ"}
Error 2:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac7jsf2hxnRYKm1Sv8HA"}
Error 3 (after "Resumed session"):
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac9WxydYfKGoUGdUeV8r"}
The session was very short — not a long context issue. Claude Code appears to be generating malformed message history with empty text blocks that have cache_control set on them, which the API rejects. Resuming the session does not fix it. The only workaround is starting a brand new session and losing all prior work.
This is costing paying users money and time.
Steps to Reproduce
After a very short session (only a few messages), Claude Code becomes completely unusable and returns repeated API 400 errors. The session cannot be continued even after clicking "Try again" or resuming the session.
Three distinct errors appeared in sequence:
Error 1:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.48.content.3.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011Cac7YqWzBPSvKV2qdzjSZ"}
Error 2:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac7jsf2hxnRYKm1Sv8HA"}
Error 3 (after "Resumed session"):
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Cac9WxydYfKGoUGdUeV8r"}
The session was very short — not a long context issue. Claude Code appears to be generating malformed message history with empty text blocks that have cache_control set on them, which the API rejects. Resuming the session does not fix it. The only workaround is starting a brand new session and losing all prior work.
This is costing paying users money and time.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
Sonnet 4.6
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Other
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗