@akz-tools/claude-fix
v1.0.2
Published
Fix: API Error 400 due to tool use concurrency issues — repairs broken Claude Code conversations
Maintainers
Readme
claude-fix
Community fix scripts for Claude Code bugs.
npx @akz-tools/claude-fix <fix-name> <session-id>Available Fixes
orphaned-toolcalls — Fix "400 tool use concurrency" error
API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation.
If you're seeing this error in Claude Code and /rewind doesn't help — this tool fixes it.
The most reported unfixed bug in Claude Code (15+ GitHub issues, countless Reddit posts). Makes conversations permanently unresumable. /rewind doesn't help. /compact can make it worse.
Usage
# Step 1: Find your broken session ID
npx @akz-tools/claude-fix orphaned-toolcalls --list
# Step 2: Fix it
npx @akz-tools/claude-fix orphaned-toolcalls <session-id>
# Step 3: Resume
claude --resume <new-session-id>You can also dry-run to see what's wrong without fixing:
npx @akz-tools/claude-fix orphaned-toolcalls --dry-run <session-id>How to find your session ID
- In Claude Code, run:
/conversations - Or:
ls -lt ~/.claude/projects/*/*.jsonl | head -20 - Or:
npx @akz-tools/claude-fix orphaned-toolcalls --list
What it does
Creates a fixed clone of your broken conversation. The original is never touched.
Root cause
Claude Code stores conversations as a tree (each message links to its parent via parentUuid). When it runs tools concurrently (e.g., two Read calls in parallel), it creates branches:
assistant: "Let me read both files"
├── tool_use: Read(file_A) ← branch 1
│ └── tool_result: <contents of A>
└── tool_use: Read(file_B) ← branch 2
└── tool_result: <contents of B>
└── ... conversation continues on this branchWhen Claude Code flattens this tree for the Anthropic API, it follows one branch — losing the tool_result on the sibling branch. The API sees a tool_use without a matching tool_result and returns 400.
User interruptions (pressing Escape) can also create consecutive same-role messages, which violate the API's alternating message requirement.
The fix:
- Walks the
parentUuidchain to find the linearized path - Detects missing
tool_resultblocks and consecutive same-role messages - Grafts missing results from sibling branches (they exist in the JSONL, just on the wrong branch)
- Inserts synthetic error results for truly lost tool calls
- Merges consecutive user messages from interruptions
- Rebuilds with a clean linear
parentUuidchain
Requirements
- Node.js 18+
- macOS or Linux
Contributing
Found another Claude Code bug that needs a fix script? PRs welcome. Each fix goes in its own directory:
claude-fixes/
├── cli.mjs # Router — npx @akz-tools/claude-fix <name>
├── fix-conversation/ # Fix: orphaned-toolcalls
│ └── index.mjs
├── fix-next-bug/ # Fix: next bug someone finds
│ └── index.mjs
└── ...License
MIT
