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

[BUG] API Error 400 - Thinking Block Modification Error

Open WamBamBoozle opened this issue 2 months ago • 30 comments

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?

The Claude Code session became completely unresponsive with repeated API 400 errors. Every subsequent user input triggered the same error, making recovery impossible.

Symptom: Session entered an error loop where the conversation history reached a corrupted state:

  1. A previous assistant response contained thinking blocks
  2. The system attempted to modify or replay that message's thinking blocks
  3. The API correctly rejected this (thinking blocks are immutable once sent)
  4. The error persisted because the corrupted state remained in conversation history

Error Pattern: The error occurred at messages.71.content.8 (71st message, 8th content block), indicating:

  • Deep conversation history (71 messages)
  • Specific content block contained thinking blocks that couldn't be modified
  • Every subsequent user input triggered the same error

Contributing Factors:

  • Long session: Nearly 15k lines of transcript suggests extended conversation
  • Complex workflow: Multiple tool calls, file reads, git operations
  • Repeated questions: Same question asked multiple times may have confused state
  • Message editing attempt: The system may have tried to edit/retry previous responses

Impact:

  • Session Status: Completely unrecoverable
  • User Action: Had to save transcript and start new session
  • Work Status: Context lost mid-conversation about a technical topic
  • Data Loss: Any uncommitted mental state/context

What Was Lost:

  • Active conversation context and unresolved questions
  • Current working state and recent discussion topics
  • Mental model of the problem being discussed

What Should Happen?

Expected Behavior:

  • Claude Code should handle long conversations gracefully without entering unrecoverable error states
  • If thinking blocks cannot be modified (as per API constraint), the system should detect this condition before submitting the request
  • When errors occur, the system should offer graceful degradation options

Ideal Recovery Flow:

  1. Detect when conversation state is approaching problematic conditions
  2. Offer to summarize current state
  3. Save context to file automatically
  4. Start fresh session with context restored
  5. Or provide mechanism to "rewind" conversation history to before corrupted state

Preventive Measures That Should Exist:

  • Conversation state validation to detect when thinking blocks are being modified
  • Message history pruning or summarization for very long conversations
  • Threshold warnings when conversation history reaches risky size (>10k lines)
  • Checkpoint mechanism to enable rollback to stable state

Error Messages/Logs

### Primary Error Message

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.71.content.8: `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_011CUQZ6ttKtJbU8JQRYyizo"}


### Error Repetition Pattern

Line 14957: User asks question → API Error 400
Line 14961: User asks same question → API Error 400 (same request)
Line 14965: User asks same question → API Error 400 (same request)
Line 14969: User references the error itself → API Error 400
Line 14974: User asks to update memory files → API Error 400


### Technical Details

**API Endpoint**: Anthropic Claude API (claude.code integration)

**Error Type**: `invalid_request_error`

**Error Message Pattern**:

messages.{N}.content.{M}: `thinking` or `redacted_thinking` blocks in the latest
assistant message cannot be modified. These blocks must remain as they were in
the original response.


Where:
- `{N}` = Message index in conversation history (71 in this case)
- `{M}` = Content block index within that message (8 in this case)

**Request IDs**:
- req_011CUQZ6ttKtJbU8JQRYyizo
- req_011CUQZ8XPZgRdbaXt8GJrxy
- req_011CUQZ9SAKKbLfL1g7ieqU8
- req_011CUQZAR1eH1AotrvNzGhx8

**Transcript Available**: Yes (763.4KB, 14,976 lines)

Steps to Reproduce

Context Leading to Error

  1. User and assistant engaged in extended session about a technical topic (~14,976 lines)
  2. Conversation involved multiple rounds of investigation and explanation
  3. Assistant provided detailed technical explanations
  4. User asked follow-up question requesting clarification
  5. Same question was asked 3 times in succession (possibly due to user not seeing response)
  6. ERROR STATE TRIGGERED

Reproduction Steps

  1. Start Claude Code session
  2. Engage in extended conversation with multiple tool calls, file reads, and complex workflows
  3. Reach approximately 71 messages deep in conversation history
  4. Have assistant generate response with thinking blocks
  5. Ask follow-up question that may trigger message retry or state replay
  6. Observe API Error 400 with thinking block modification error
  7. Attempt to continue session → error repeats for all subsequent inputs

Conditions That May Trigger

  • Very long sessions (>10k lines of transcript)
  • Conversation history at ~71 messages or deeper
  • Assistant responses containing thinking blocks
  • Rapid repeated questions (asked 3 times in succession in this case)
  • Complex multi-turn workflows with many tool calls

Warning Signs

  • Session approaching 10k+ lines of transcript
  • Repeated API errors occurring
  • Same question triggering errors multiple times
  • Any API 400 error mentioning thinking blocks

Recovery Actions Taken

  1. User saved full transcript to local file
  2. User started new Claude Code session
  3. User asked new session to review the transcript
  4. User requested this bug report be filed

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.0.25 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

IntelliJ IDEA terminal

Additional Information

No response

WamBamBoozle avatar Oct 23 '25 18:10 WamBamBoozle


Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2171
  2. https://github.com/anthropics/claude-code/issues/1702
  3. https://github.com/anthropics/claude-code/issues/2608

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 Oct 23 '25 18:10 github-actions[bot]

not a duplicate -- all the false positives listed above have different error messages

WamBamBoozle avatar Oct 23 '25 18:10 WamBamBoozle

Experiencing a similar issue with CC throwing 400's.

Claude Code Version: 2.0.25 Login method: Claude Max Account Model: Sonnet 4.5 (default) OS: GNU Guix TERM: xterm-256color (via ssh)

chops avatar Oct 23 '25 19:10 chops

how do you get the API response codes from the CLI ?

bhaskarEEN avatar Nov 03 '25 10:11 bhaskarEEN

It just logged them. I did nothing special.

WamBamBoozle avatar Nov 03 '25 13:11 WamBamBoozle

It just logged them. I did nothing special.

Can you please elaborate ? I am also facing a similar issue but not sure if it is the same in vs code terminal. I wanted to verify if it is the 400 response as you have mentioned. It would be nice if you can share how you log the claude-code's API calls. Please & thank you

bhaskarEEN avatar Nov 03 '25 13:11 bhaskarEEN

I lost the logs

WamBamBoozle avatar Nov 04 '25 20:11 WamBamBoozle

I'm getting a similar error after attempting to /resume a Claude Code terminal session:

  ⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.19: The final block in an assistant
    message cannot be `thinking`."},"request_id":"req_011CV4VkJfmm9mTv9eWV9381"}

It's displayed the first time I send a message since /resume. Disabling thinking (pressing tab) resolved it.

zubin avatar Nov 12 '25 18:11 zubin

@zubin how do you get the API calls logged ?

bhaskarEEN avatar Nov 13 '25 00:11 bhaskarEEN

@zubin how do you get the API calls logged ?

I didn't do anything log-related. Just tried /resume and that text was printed.

zubin avatar Nov 17 '25 21:11 zubin

I am getting this also. As a workaround, instead of a long prompt, I am writing my prompt to a .md file and then instructing claude-code to read and implement the instructions in the .md.

CivilEngineerUK avatar Nov 17 '25 22:11 CivilEngineerUK

experiencing similar issue too, here is the log

{"message":"400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.1.content.0: Invalid `signature` in `thinking` block\"},\"request_id\":\"req_vrtx_011CVMkoUR3ukzE5uNm6Nuip\"}","status":400,"request_id":"req_vrtx_011CVMkoUR3ukzE5uNm6Nuip","modelId":"claude-sonnet-4-5@20250929","providerId":"vertex","details":{"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0: Invalid `signature` in `thinking` block"},"request_id":"req_vrtx_011CVMkoUR3ukzE5uNm6Nuip"}}
Request ID: req_vrtx_011CVMkoUR3ukzE5uNm6Nuip

yanzhi-enso avatar Nov 21 '25 21:11 yanzhi-enso

This started happening to me a few hours ago when using /resume in Claude Code cli. Functions without issue in other cases.

DevinRB avatar Nov 22 '25 02:11 DevinRB

similar issue. API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.9.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_011CVQSt71zTgpRrWfMKDwaZ"}

claude code 2.0.50 , Max user, ubuntu(wsl)

rewinding 2 or 3 messages usually solves this issue for me.

mysehyunhope avatar Nov 23 '25 07:11 mysehyunhope

similar issue. 2.0.50 (Claude Code), Pro User, Mac os

⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.9.content.24: 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_011CVQp9vC1ZRNZGKGyJHSCm"}

Dante-dan avatar Nov 23 '25 12:11 Dante-dan

same problem, turning thinking off does not fix the problem

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.7.content.5: `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_011CVRLyHHZxZ7edDKMNR7K9"}

AlizerUncaged avatar Nov 23 '25 19:11 AlizerUncaged

I just got this for the first time.

  • I first rewound two messages prior to the error first appearing (i.e., to the latest conversation state that previously did not result in the error on the next message), but this did not resolve the error
  • I next tried disabling thinking: messages sent with thinking disabled did not produce the error in that state
  • Re-enabling thinking and sending a message produced the error again
  • I then rewound by an additional message (undoing a step that resulted in a large number of auto accepted edits, though I didn't revert the code), and in this state did not get the error even with thinking enabled

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.21.content.116: 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_011CVRbhLRdv1LZsPvyyGksL"}

bkorpan avatar Nov 23 '25 22:11 bkorpan

+1, lost all progress, gotta copy to restart, any best recovery method?

enkr1 avatar Nov 25 '25 07:11 enkr1

compaction via /compact seemed to fix it for me

tjsb avatar Nov 26 '25 07:11 tjsb

Same here, but compacting does not fix the issue either (nor does disable thinking, or going back to the previous message).

julian-mateu avatar Nov 27 '25 12:11 julian-mateu

Same Once it is happened, I can't use /compact and request any prompt more

GekiteniusY avatar Nov 30 '25 12:11 GekiteniusY

Workaround that worked for me:

I encountered the same error and was able to resolve it by manually removing thinking blocks from the conversation JSONL file.

Steps:

  1. Close Claude Code completely
  2. Find the conversation file:
ls -la ~/.claude/projects/
# Look for the largest/most recent .jsonl file in your project folder
  1. Backup and fix the file:
import json

filepath = "/path/to/your/session.jsonl"

with open(filepath, 'r') as f:
  lines = f.readlines()

with open(filepath, 'w') as f:
  for line in lines:
    if not line.strip():
      continue
    data = json.loads(line)
    if 'message' in data and 'content' in data['message']:
      if isinstance(data['message']['content'], list):
        data['message']['content'] = [
          c for c in data['message']['content'] 
          if c.get('type') not in ('thinking', 'redacted_thinking')
        ]
    f.write(json.dumps(data) + '\n')
  1. Restart Claude Code

This is a temporary workaround until an official fix is released. Hope this helps others facing the same issue!

nahyeongjin1 avatar Dec 02 '25 06:12 nahyeongjin1

@nahyeongjin1 Sounds good! Thanks for sharing!! I'll try it next time it comes up.

GekiteniusY avatar Dec 02 '25 06:12 GekiteniusY

@nahyeongjin1 this workaround worked perfectly for me, thank you 🙏🏽

devguyio avatar Dec 04 '25 10:12 devguyio