Fix guides · Claude Code ·
Fix Claude Code "thinking blocks cannot be modified" (400)
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0: thinking or redacted_thinking blocks in the latest assistant message cannot be modified"}}
The API rejects your request because your code changed the thinking blocks in the latest assistant message before sending it back, for example in a custom tool-use loop. The fix is to send that assistant message back exactly as received, then append the tool_result blocks. Do not edit, drop, or reorder thinking blocks.
Common causes – and how to tell which one you have
1. Code filters thinking blocks out before resending
How to tell: Your loop strips thinking blocks to save tokens or clean up the history. Check that your code does not filter, reorder, or rebuild assistant content before sending it back to the API.
Fix: Send the assistant message unchanged, including thinking blocks, then append the tool_result blocks. If you need to save tokens, consider trimming context in older turns rather than editing the latest assistant message.
2. Code rebuilds or reorders content blocks
How to tell: Your code constructs a new content array, sorts blocks, or moves text before thinking. To diagnose, check that no such logic modifies the assistant message before sending it back.
Fix: Echo the assistant message as received. Append tool_result blocks after it. Do not sort, move, or rebuild content.
3. Messages merged or split across turns
How to tell: Your integration merges several assistant messages into one, or splits one into several, when managing context. Check that message boundaries are preserved.
Fix: Keep message boundaries exactly as the API returned them. Merge nothing, split nothing, and preserve block order.
How to fix it
- Read the error: it names the message and block, e.g. messages.1.content.0, and says thinking or redacted_thinking blocks in the latest assistant message cannot be modified.
- Check whether Claude Code is running through a proxy, gateway, or custom integration that modifies the assistant message before it is resent. Look at any middleware or proxy scripts in your setup.
- Find where your code rebuilds or filters assistant content before sending it back to the API.
- Stop filtering, reordering, or editing thinking and redacted_thinking blocks. Send the whole assistant message unchanged, then append the tool_result blocks one per tool_use, with results first.
- Re-run the request and confirm it returns 200 instead of the 400.
Using Lovable, Bolt or v0?
The error can appear when a proxy, gateway, or custom integration between Claude Code and the Anthropic API modifies the assistant message before it is resent. If you are not running a custom loop or proxy, check whether a middleware layer is altering the message. If so, configure that layer to pass the message unchanged.
Using Cursor, Claude Code or Windsurf?
Ask the agent to find the code path that builds the messages array for the Anthropic API call and show how assistant content is handled between turns. Have it print the assistant message before and after that step to prove nothing was filtered, reordered, or rebuilt. Then verify the request returns 200.
The “fix” to avoid
Agents often delete the thinking blocks, set thinking to disabled, or retry the same request. Deleting blocks is exactly the modification the error names, disabling thinking changes behaviour, and retrying fails again. Return the message unchanged instead.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
My API calls fail with HTTP 400 invalid_request_error: messages.1.content.0: thinking or redacted_thinking blocks in the latest assistant message cannot be modified. Find where my code or my Claude Code setup modifies the assistant message before resending. Check for proxy, gateway, or custom integration layers that rebuild or filter assistant content. Fix: return the last assistant message exactly as received, including all thinking and redacted_thinking blocks, then append the tool_result blocks one per tool_use with results first. Do not filter thinking blocks, do not reorder content, and do not merge messages. Verify the request returns 200.
Questions people ask
Does this mean my API key or model is wrong?
No. The request reached the API and was rejected for its message structure, not for auth or model. The problem is that thinking blocks in the latest assistant message were changed before resending.
Can I drop thinking blocks to save tokens?
Not from the latest assistant message in a tool-use turn: the API requires that message to be unchanged. Earlier assistant turns in the history can have their context trimmed if needed to save tokens.
Where does the error point?
It names the message index and block index, such as messages.1.content.0, where the API found a modified thinking block. Use it to locate the message in your request, then compare it with what the API originally returned.