Repairs conversation JSONL files where assistant messages with tool calls are missing thinking blocks, which causes API 400 errors during extended thinking session replay.
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
# 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.jsonlScans 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)"}Python 3.11+