Persistent "thinking block" API Error (400) in Extended Conversations

Resolved 💬 3 comments Opened Jan 25, 2026 by RAG7782 Closed Jan 29, 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?

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 --version to check)
  • Node.js Version: (run node --version to 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:

  1. Claude generating chapter content (~500-700 lines each)
  2. Writing to files in iCloud Drive
  3. 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:

  1. Tool use blocks being inserted without preceding thinking blocks
  2. State corruption when resuming after long operations
  3. 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

  1. Open Claude Code and start a writing session in extended thinking mode
  2. Generate content for multiple chapters sequentially (save each as .md file in iCloud Drive)
  3. After 10+ successful chapter generations, continue generating the next chapter
  4. The error will appear after processing a message with extended thinking blocks
  5. 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_

View original on GitHub ↗

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