[BUG] cache_control cannot be set for 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?
Bug: cache_control cannot be set for empty text blocks
Version: Claude Code v2.1.121
OS: macOS
Steps to reproduce:
- Create a project with multiple agents in
.claude/agents/ - Run any slash command that activates those agents
- Error appears immediately
Error message:
API Error: 400 {"type":"invalid_request_error","message":"messages.0.content.X.text: cache_control cannot be set for empty text blocks"}
Root cause (observed):
Claude Code appends a ## MEMORY.md block to each agent file at runtime. When MEMORY.md is empty, this creates an empty text block with cache_control set, which the API rejects.
Expected behavior:
Command executes normally. If MEMORY.md is empty, the block should be omitted or cache_control should not be applied.
What Should Happen?
Slash commands should execute normally when agent MEMORY.md files are empty. The empty MEMORY.md block should either be omitted from the request or cache_control should not be applied to it.
Error Messages/Logs
**Error message:**
API Error: 400 {"type":"invalid_request_error","message":"messages.0.content.X.text: cache_control cannot be set for empty text blocks"}
Steps to Reproduce
- Create a project with multiple agent files in
.claude/agents/ - Start Claude Code:
claude - Run any slash command that activates those agents:
/Tras_El_Cristal - Error appears immediately — command never executes
Note: All agent MEMORY.md files are empty (fresh project).
The bug occurs because Claude Code appends an empty ## MEMORY.md
block to each agent at runtime and sets cache_control on it.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.121
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 ↗