[BUG] API Error 400: "tool_use ids must be unique" when using -p flag with tool-requiring prompts
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 using claude -p (print mode) with prompts that require tool use (like checking if a file exists or running shell commands), the CLI fails with an API error about duplicate tool_use IDs.
Environment
- Claude Code version: 2.1.19
- OS: macOS Darwin 25.2.0
- Shell: zsh
What Should Happen?
Claude should check if the file exists and return the result.
Error Messages/Logs
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1: `tool_use` ids must be unique"},"request_id":"req_011CXRMKYvALAsgksCjT7HoC"}
Steps to Reproduce
## Steps to Reproduce
``bash ``
claude -p "check package.json exists"
## Pattern Observed
- FAILS: Prompts requiring tool use (
"check package.json exists","echo hello") - WORKS: Pure text responses (
"2+2","say hello","how many r in strawberry")
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.18
Claude Code Version
2.1.19
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
IntelliJ IDEA terminal
Additional Information
_No response_
15 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
while it seems to be the same as #16340 that one has been marked as completed without a solution. Downgrading to 2.1.18 solves the problem, but 2.1.19 fails.
I posted a similar issue https://github.com/anthropics/claude-code/issues/20573 but probably it was a duplicate of this issue.
I'll add a little more context.
After a fresh login (deleting ~/.claude.json), the first prompt to claude -p works correctly, but any subsequent prompt fails with an API error about duplicate tool_use IDs. Simple prompts like claude -p "hello" work.
The following steps always reproduces the problem:
Environment
Behavior
Repro
claude --dangerously-skip-permissions -p "Use Read tool to read ./README.md" --output-format stream-json --verboseWorkaround
Extra
claude doctorhangs at "Checking installation status..." here.Follow-up (Ubuntu 22.04.5, node v22.22.0):
./ralph.py --max 1 --marker RALPH_217_OK "Use exactly one tool call to run 'touch /tmp/ralph_217_tool_ok', then output RALPH_217_OK."created the file and returned the marker.claude doctorhangs at "Checking installation status..." here.## Additional Debug Findings
I can confirm this issue on v2.1.19. Rolling back to v2.1.17 resolves the problem.
### Environment
### Debug Log Analysis
Examining
~/.claude/debug/logs reveals anomalous behavior when tool use is triggered:~350 log entries at the exact same millisecond timestamp:
2026-01-26T16:57:17.756Z [DEBUG] [API:request] Creating client...
2026-01-26T16:57:17.756Z [DEBUG] [API:request] Creating client...
2026-01-26T16:57:17.756Z [DEBUG] [API:request] Creating client...
... repeated 100+ times
Breakdown:
[API:request] Creating clientcalls[API:auth] OAuth token checkcalls (start + complete)This suggests a race condition or runaway loop in the tool initialization code that's generating duplicate IDs.
### Reproduction
```bash
# Fails - any tool use
echo "Read test.txt" | claude --print --no-session-persistence
# Works - no tool use
echo "Say hello" | claude --print --no-session-persistence
Flags that DON'T help
Workaround
ln -sf ~/.local/share/claude/versions/2.1.17 ~/.local/bin/claude
This completely resolves the issue. v2.1.17 handles tool use correctly.
I can confirm the downgrade to v2.1.17 solved the issue for me.
For Visual Studio Code, you can use _Extensions: Install Specific Version of Extension..._ in the command palette to pin down Claude Code to a working version.
Has anyone seen any movement on this?
I'm experiencing this same issue on Claude Code on Android and web.
same error here!
The worst thing is that you can't avoid this one in Claude code web
I have this error in Claude Code Cloud while on mobile
I am also consistently hitting this wall
Same issue here, also on mobile
I'm getting this more and more often. No idea what's causing it. Even compaction doesn't help