Skip to content

[BUG] API Error 400 - Thinking Block Modification Error #10199

@WamBamBoozle

Description

@WamBamBoozle

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions