Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

thinking-block-repair

Repairs conversation JSONL files where assistant messages with tool calls are missing thinking blocks, which causes API 400 errors during extended thinking session replay.

Problem

When replaying conversation history in extended thinking mode, the Anthropic API requires that assistant messages containing tool_use blocks also include a thinking block. If prior messages had their reasoning_content stripped, the API returns a 400 error.

See: anthropics/claude-code#37485

Usage

# Dry run — report problems without modifying
python thinking_repair.py -n conversation.jsonl

# Repair and write to stdout
python thinking_repair.py conversation.jsonl > repaired.jsonl

# Repair in place
python thinking_repair.py -i conversation.jsonl

# Multiple files
python thinking_repair.py -i session1.jsonl session2.jsonl

How It Works

Scans each JSONL line for assistant messages that have tool_use content blocks but no thinking block. For each match, inserts a minimal placeholder thinking entry at the start of the content array:

{"type": "thinking", "thinking": "(reasoning content was not preserved)"}

Requirements

Python 3.11+