Persistent "thinking block" API Error (400) in Extended Conversations
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
Claude Code throws repeated API 400 errors related to "thinking blocks" during extended writing sessions and persists even after starting new conversations.
Environment
- OS: macOS (Apple Silicon / Intel - please specify)
- Claude Code Version: (run
claude --versionto check) - Node.js Version: (run
node --versionto check) - Installation method: npm / pip / other
Use Case Context
Writing a technical book with multiple chapters. Each chapter is saved as a separate .md file. The workflow involves:
- Claude generating chapter content (~500-700 lines each)
- Writing to files in iCloud Drive
- Proceeding to the next chapter
The error typically appears after 10+ successful chapter generations in a single session.
What's Happening
The error indicates that the conversation became "desynchronized" — Claude Code is sending messages in a format that the API cannot process correctly when the extended thinking mode is active.
Error Messages
Error 1
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages.33.content.0.type: Expected 'thinking'"
}
}
Error 2
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages.28.content: Either 'text' or 'thinking' must be present"
}
}
Suggested Fix
The error messages suggest that the conversation history is not properly maintaining thinking block ordering. Possible causes:
- Tool use blocks being inserted without preceding thinking blocks
- State corruption when resuming after long operations
- Message history not being properly reset between sessions
Additional Notes
- The files are being written successfully up until the error occurs
- The error appears to be on the client side (message construction) rather than the API itself
- This blocks continued use of Claude Code for extended writing projects
What Should Happen?
The error should not occur, or if it does, the system should provide a clear recovery path (e.g., restart the session, clear the message history, or provide an alternative workflow).
Error Messages/Logs
Steps to Reproduce
- Open Claude Code and start a writing session in extended thinking mode
- Generate content for multiple chapters sequentially (save each as .md file in iCloud Drive)
- After 10+ successful chapter generations, continue generating the next chapter
- The error will appear after processing a message with extended thinking blocks
- The error persists even after starting a new conversation
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.19
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 ↗