[BUG] Session resume fails with 400 error: thinking blocks saved with empty "thinking" field
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 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
- Start a session with extended thinking enabled
- Have a long conversation (200+ messages) that generates multiple thinking blocks
- Exit the session
- Resume the session: claude --resume <session-id>
- Send any message
- 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗