claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Session becomes completely unrecoverable due to thinking block API error

Open rmaher001 opened this issue 1 year ago • 3 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

Bug Description

During an extended Claude Code session, an API error occurs that makes the session completely unrecoverable. The error is related to thinking blocks being modified. Once this error occurs:

  • Cannot continue the conversation (any input triggers the error)
  • /compact fails with the same error
  • /clear - untested but context loss is unacceptable
  • The only option is to abandon the session and lose all context

This is a critical bug because it causes complete loss of work-in-progress with no recovery path.

Error Message

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.49.content.1: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response."},"request_id":"req_011CVeW1YWWvLQ7fem8ut3YA"}

Environment

  • Claude Code Version: 2.0.55
  • Platform: macOS (Mac Mini M4 Pro, 64GB RAM)
  • macOS Version: 15.6.1 (Build 24G90)
  • Terminal: VS Code integrated terminal
  • Node Version: v22.16.0

Steps to Reproduce

  1. Use Claude Code for an extended session (in this case, 49+ messages based on error)
  2. At some point during normal usage, the error occurs
  3. Any subsequent input (including /compact) triggers the same error
  4. Session is completely stuck with no way to recover context

Expected Behavior

  1. Thinking blocks should be managed internally without corruption
  2. If corruption occurs, /compact should be able to recover by summarizing and starting fresh
  3. At minimum, there should be a way to export/save context before being forced to abandon the session

Actual Behavior

Session becomes completely unusable. User is forced to lose all conversation context and start over.

Impact

  • Severity: High
  • Complete loss of conversation context
  • Loss of work-in-progress
  • No recovery mechanism available
  • Forces user to restart and manually reconstruct context

Related Issues

This appears related to #11323 which describes a similar thinking block error after Ctrl+C interruption, though in this case no interruption was involved.

Additional Context

  • Error occurred during normal usage, no Ctrl+C or interruption
  • The session was working normally until this error appeared
  • Multiple installation paths detected (npm-local and npm-global) but this is likely unrelated

Suggested Fix

  1. Ensure thinking blocks are never corrupted during normal session flow
  2. Add a recovery mechanism (e.g., /compact --force or /recover) that can salvage context even when message structure is invalid
  3. Add ability to export conversation context before clearing

rmaher001 avatar Nov 30 '25 18:11 rmaher001

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/10199
  2. https://github.com/anthropics/claude-code/issues/12130
  3. https://github.com/anthropics/claude-code/issues/12525

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Nov 30 '25 18:11 github-actions[bot]

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.11.content.7: thinking or redacted_thinking blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response."},"request_id":"req_011CVeZdvHJiCjKEhhjYmCvv"}

athilasb avatar Nov 30 '25 18:11 athilasb

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 31 '25 10:12 github-actions[bot]

I am experiencing the same problem https://github.com/anthropics/claude-code/issues/19460#issuecomment-3771849168

portdeveloper avatar Jan 21 '26 07:01 portdeveloper

Also experiencing this.

machielvdw avatar Feb 06 '26 11:02 machielvdw

saw the same thing in #25062

ehsan avatar Feb 11 '26 19:02 ehsan

Workaround confirmed working — claude-code-thinking-blocks-fix by @miteshashar recovered my bricked session. This looks like the same root cause as #12311.

Long session (~6,600 lines, heavy subagent use) hit the "thinking blocks cannot be modified" error and became completely unresponsive — no message, /compact, /debug, or even /feedback worked.

I asked Claude Code about it in a new session and it found the community repair tool, diagnosed the issue, and applied the fix — all within the conversation. Diagnosis found 12 corruption points from streaming interleaving of parallel subagent responses. Needed two passes of the targeted fix to fully clean up (first pass left one residual from a merged thinking block). Session resumed successfully.

  claude-session-fix-thinking diagnose SESSION_ID   # 12 corruption points
  claude-session-fix-thinking fix SESSION_ID         # 11 fixed, 1 residual
  claude-session-fix-thinking fix SESSION_ID         # residual cleaned
  claude-session-fix-thinking diagnose SESSION_ID   # clean
  claude --resume SESSION_ID                         # working

For anyone hitting this: try the targeted fix first — it preserves thinking blocks where possible and creates backups automatically. Run diagnose after to verify clean, and do a second pass if needed. The nuke option (strips all thinking blocks) is available as a fallback.

adam0white avatar Feb 16 '26 20:02 adam0white

Glad it worked for you to recover your session, @adam0white. I'd been planning to check out the issues and post this on the relevant one. Superb that you beat me to it!

miteshashar avatar Feb 16 '26 20:02 miteshashar

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Mar 16 '26 22:03 github-actions[bot]

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Mar 24 '26 14:03 github-actions[bot]