You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] API Error 400: "tool_use ids must be unique" when using -p flag with tool-requiring prompts #20508
I have searched existing issues and this hasn't been reported yet
This is a single bug report (please file separate reports for different bugs)
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
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")
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 #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:
Delete ~/.claude.json to reset state
Run claude and complete login
Run a prompt: claude -p "check what tasks you have" - works
Run the same or any other prompt again: claude -p "check what tasks you have" - fails
2.1.19 fails on the first tool call in -p (no multi-turn required).
2.1.17 works end-to-end: ./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 doctor hangs at "Checking installation status..." here.
This suggests a race condition or runaway loop in the tool initialization code that's generating duplicate IDs.
Reproduction
# Fails - any tool useecho"Read test.txt"| claude --print --no-session-persistence
# Works - no tool useecho"Say hello"| claude --print --no-session-persistence
Flags that DON'T help- --no-session-persistence- --dangerously-skip-permissions- Different models (--model claude-sonnet-4-...)- Clean directories without .claude settings- Fresh reinstall of CLIWorkaroundln -sf ~/.local/share/claude/versions/2.1.17 ~/.local/bin/claudeThis 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.
I'm experiencing this same issue on Claude Code on Android and web.
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.7.content.3: tool_use ids must be unique"},"request_id":"<id>"}
Reacted by Aleksander Smywiński-Pohl, Anthony Sosso, Hayate Ishida, Ben Poulson, Corey Farwell, Mark Risher, Samir Giripunje, James McClean, Hamza Nouali, Leonardo Pinheiro and 19 more
Activity
github-actions commentedon Jan 24, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
siliconcat commentedon Jan 24, 2026
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.
kenfdev commentedon Jan 24, 2026
I posted a similar issue #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:
matchpoint-ai-bot commentedon Jan 24, 2026
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.matchpoint-ai-bot commentedon Jan 24, 2026
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.EdgarHApollo commentedon Jan 26, 2026
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
miohtama commentedon Jan 26, 2026
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.
matthew-bram commentedon Feb 5, 2026
Has anyone seen any movement on this?
starkey-01 commentedon Feb 24, 2026
I'm experiencing this same issue on Claude Code on Android and web.
BenjaminCes commentedon Mar 2, 2026
same error here!
zernie commentedon Mar 6, 2026
The worst thing is that you can't avoid this one in Claude code web
malachany commentedon Mar 7, 2026
I have this error in Claude Code Cloud while on mobile
WynnD commentedon Mar 12, 2026
I am also consistently hitting this wall
acehox commentedon Mar 12, 2026
Same issue here, also on mobile
zernie commentedon Mar 13, 2026
I'm getting this more and more often. No idea what's causing it. Even compaction doesn't help