[BUG] API Error: 400 — thinking or redacted_thinking blocks in the latest assistant message cannot be modified.
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?
When working in an active session (mid-conversation, not at session start), Claude Code throws an API 400 error:
"thinking or redacted_thinking blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response."
This has happened twice in the same workspace. Both times it occurred mid-session after a response that used extended thinking. The error appears immediately ("Baked for 0s"), suggesting it fails on the next API call without retrying.
The workspace uses SessionStart and PreToolUse hooks that inject additionalContext into the conversation. Suspected cause: a hook firing after a thinking-heavy response causes context reconstruction that alters or strips the immutable thinking blocks, which the API then rejects.
Workaround: /clear resets the conversation and resolves it temporarily.
What Should Happen?
Claude Code should handle thinking blocks correctly when hooks inject context ▎ mid-session, and the conversation should continue without error.
Error Messages/Logs
Steps to Reproduce
"Use a workspace with SessionStart/PreToolUse hooks. Have an extended conversation where thinking blocks appear. A hook fires mid-session. Next API call throws 400."
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
No response
Claude Code Version
2.1.154 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
- Steps to reproduce: "Use a workspace with SessionStart/PreToolUse hooks. Have an
extended conversation where thinking blocks appear. A hook fires mid-session. Next
API call throws 400."
- Expected: Session continues normally
- Actual: API Error 400, session broken
- Claude Code version: Run claude --version in terminal and paste the output
- OS: macOS (Darwin 25.5.0)
Same error!
Hitting this on Windows (CC 2.1.131, Anthropic API, Opus) with two specific async triggers that sharpen the repro beyond "a hook fires mid-session." In both, an out-of-band message gets injected while the latest assistant message contains an extended-thinking block, and the retry can't reconstruct the thinking block byte-identical:
/loopdynamic-mode wakeup firing while a thinking-heavy turn is the latest assistant message:✻ Claude resuming /loop wakeup API Error: 400 thinking or redacted_thinking blocks in the latest assistant message cannot be modified- Background command completion notification (
run_in_background: true) landing mid-stream during a thinking turn, same 400.
There's also a second, related 400 that I don't see captured in the existing reports — it appears on the same poisoned turn and is what makes the session unrecoverable (every subsequent wakeup re-hits it):
API Error: 400 diagnostics.previous_message_id: must be the `id` from a prior /v1/messages response (starts with `msg_`)
So once the thinking block is mutated, the diagnostics retry sends a previous_message_id that no longer maps to a real msg_ id, and the conversation is bricked until /clear.
Common factor across all variants: an asynchronous injection (hook, /loop wakeup, or background-task completion) arrives while extended thinking is the latest assistant content. The async sources differ; the mutation of the immutable thinking block is the same. Suggest the fix treat thinking blocks as immutable across all context-reconstruction paths, not just hooks.
Workaround confirmed: /clear (or, for /loop, not rescheduling the next wakeup).
Confirming this on another setup — same exact error, reproduces in normal mid-session use with no manual editing of thinking blocks on my end.
API Error: 400 messages.1.content.17: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.
Environment
- Claude Code: 2.1.143
- Model: claude-opus-4-8
- OS: macOS (Darwin 25.4.0)
Notes
- Started only after the Opus 4.8 release; never saw it on prior models.
messages.1.content.17points at a thinking/redacted_thinking block in the latest assistant message being re-sent in a form that no longer matches the original signed block — consistent with a history-reconstruction / replay path (compaction, retry, or a hook re-entering the turn) mutating or re-ordering content blocks before resend.- Happens on multi-tool turns in particular.
Just hit this as well. API Error: 400 messages.79.content.7: thinkingorredacted_thinking blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.
Claude Code version 2.1.154, model Opus 4.8 on xhigh effort.
First time ever observed, would argue this is something introduced with the release of 4.8.