[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_
This issue has 15 comments on GitHub. Read the full discussion on GitHub ↗