claude-code - 💡(How to fix) Fix [BUG] Session resume fails with 400 error: thinking blocks saved with empty "thinking" field [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46843Fetched 2026-04-12 13:31:36
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

Error Message

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.215.content.0.thinking: each thinking block must contain thinking"},"request_id":"req_011CZy7RDZvZ1HG8dSQFz22t"}

Root Cause

Root cause found in .jsonl session file: assistant messages contain thinking blocks with a valid signature but empty thinking field:

Fix Action

Fix / Workaround

Workaround (manually patch the .jsonl before resuming):

Code Example

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.215.content.0.thinking: each thinking block must contain thinking"},"request_id":"req_011CZy7RDZvZ1HG8dSQFz22t"}
RAW_BUFFERClick to expand / collapse

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?

When resuming a session with --resume, the API returns a 400 error on every message. The session .jsonl file contains thinking blocks with an empty "thinking" field ("thinking": ""), which the API rejects. This makes the session completely unusable after resume.

What Should Happen?

Claude Code should not save thinking blocks with an empty "thinking" field, or should filter them out automatically when building the message history for API calls on session resume.

Error Messages/Logs

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.215.content.0.thinking: each thinking block must contain thinking"},"request_id":"req_011CZy7RDZvZ1HG8dSQFz22t"}

Steps to Reproduce

  1. Start a session with extended thinking enabled
  2. Have a long conversation (200+ messages) that generates multiple thinking blocks
  3. Exit the session
  4. Resume the session: claude --resume <session-id>
  5. Send any message
  6. Observe 400 API error on every attempt

Root cause found in .jsonl session file: assistant messages contain thinking blocks with a valid signature but empty thinking field:

{ "type": "thinking", "thinking": "", "signature": "EvgSCls..." }

Workaround (manually patch the .jsonl before resuming):

import json path = '~/.claude/projects/<project>/<session-id>.jsonl' with open(path, 'r') as f: lines = [l for l in f.readlines() if l.strip()] fixed = [] for line in lines: data = json.loads(line) msg = data.get('message') if msg and isinstance(msg.get('content'), list): msg['content'] = [ b for b in msg['content'] if not (b.get('type') == 'thinking' and not b.get('thinking')) ] fixed.append(json.dumps(data)) with open(path, 'w') as f: f.write('\n'.join(fixed))

This removed 42 corrupted blocks out of 570 total messages in our session.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.101

Claude Code Version

2.1.101

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

The session had 570 messages total. 42 thinking blocks were saved with empty "thinking" field but valid "signature". The error always points to the same message index (215) regardless of what message is sent, confirming the corruption is in the stored history, not the new input.

extent analysis

TL;DR

Manually patching the session .jsonl file to remove thinking blocks with empty "thinking" fields resolves the 400 API error issue when resuming a session.

Guidance

  • Verify the issue by checking the session .jsonl file for thinking blocks with empty "thinking" fields and valid signatures.
  • Apply the provided workaround by running the Python script to remove corrupted thinking blocks from the session file before resuming the session.
  • Test the session resume functionality after applying the workaround to ensure the 400 API error is resolved.
  • Consider reporting this issue to the development team to investigate and implement a permanent fix, as this is a regression from a previous version.

Example

The provided Python script can be used as an example to remove corrupted thinking blocks:

import json
path = '~/.claude/projects/<project>/<session-id>.jsonl'
with open(path, 'r') as f:
    lines = [l for l in f.readlines() if l.strip()]
fixed = []
for line in lines:
    data = json.loads(line)
    msg = data.get('message')
    if msg and isinstance(msg.get('content'), list):
        msg['content'] = [
            b for b in msg['content']
            if not (b.get('type') == 'thinking' and not b.get('thinking'))
        ]
    fixed.append(json.dumps(data))
with open(path, 'w') as f:
    f.write('\n'.join(fixed))

Notes

This workaround may not be applicable to all scenarios, and a permanent fix from the development team is recommended to prevent similar issues in the future.

Recommendation

Apply the workaround to manually patch the session .jsonl file, as this is a regression from a previous version and a permanent fix is not currently available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Session resume fails with 400 error: thinking blocks saved with empty "thinking" field [1 comments, 2 participants]