API Error 400: tool_use ids must be unique - occurs consistently
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 13 comments · opened Jan 27, 2026 · closed Apr 10, 2026
Description
When using Claude Code CLI with --print --output-format json, the API consistently returns a 400 error indicating duplicate tool_use IDs are being sent in the request.
Environment
- Platform: macOS (Darwin 25.2.0)
- Model: claude-opus-4-5-20251101
Error
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1: `tool_use` ids must be unique"},"request_id":"req_011CXYMdu1vaiqC69uftUr9D"}
Observed Behavior
- The CLI exits with code 0 (success)
- JSON response has
is_error: truebutsubtype: "success" - The error occurs consistently, not just occasionally
num_turns: 2suggests it fails early in the conversation
Expected Behavior
- Tool use IDs should be unique in all API requests
- CLI should exit with non-zero code when API returns an error
subtypeshould reflect the error state
Additional Context
The error messages.1.content.1: tool_use ids must be unique suggests tool_use blocks are being duplicated with the same ID somewhere in conversation serialization.
13 Comments
Claude Code version: 2.1.20
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
II don't think its either of those reports - might have the same root cause, but in my case im not using multi-turn and im not using stream-json -- my use case is a simple --print with --output-format=json (or even in interactive mode with no --print or --output-format at all)
one more thing I might add - the tool use actually goes though - the action in the tool use is performed and then the 400 happens
<img width="617" height="251" alt="Image" src="https://github.com/user-attachments/assets/d2ec1815-6e2a-49a6-ac65-b68af18c4efe" /> - this literally happened when I was reporting this very but and the comment was indeed posted ;)
FYI - it's not related to the VSCode extension - this happens both in CLI and in the VSCode plugin ( I saw some issues regarding the VSCode extension )
Having the same Issue 2 weeks ago in my code sessions in web, app, and desktop, i cant find a solution, even claude say it is a bug when asked. I reduced the size of files like claude.md and PRD files, but this is consistent.
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.13.content.3: tool_use ids must be unique"},"request_id":"req_011CYLadytJmjDoyKkbJh8rD"}
I have the same issue in claude code online. Did anyone find a way to recover from this error?
Still experiencing this on v2.1.50 in interactive desktop mode on Windows 11.
Error
The error repeats on every retry (6+ times observed), creating an infinite loop since the corrupted message history is resent each time.
Trigger
C:\roottool_useIDsNote on the v2.1.21 fix
The fix described as "Fixed API errors when resuming sessions that were interrupted during tool execution" appears to have only resolved the
--printmode variant (confirmed by @waihaiwai in #20751). The interactive/desktop mode variant with parallel tool call failures is still present through v2.1.50.Workaround
/clearor start a new session. The corrupted conversation history is what causes the retry loop — once cleared, the error stops. Setting the working directory to the actual project folder (notC:\) reduces the likelihood of triggering it.running /clear on Claude Web/Android doesn't work, endless loop.
As soon as I installed/started using claude desktop on windows, I started getting these random "API Error 400: tool_use ids must be unique" errors via remote-control to a claude-code tui install that never generates those errors
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.