API Error 400: tool_use ids must be unique in --print mode (v2.1.19)
Resolved 💬 5 comments Opened Jan 25, 2026 by waihaiwai Closed Mar 7, 2026
Description
When using --print mode with --output-format stream-json in Claude Code CLI v2.1.19, an API error occurs after tool execution (e.g., WebSearch).
Error Message
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1: `tool_use` ids must be unique"},"request_id":"req_..."}
Steps to Reproduce
- Install Claude Code CLI v2.1.19
- Run a command that uses tools (e.g., WebSearch):
``bash``
echo "/lookup-term CORS" | claude --print --output-format stream-json --verbose --allowedTools "WebSearch,WebFetch" --permission-mode bypassPermissions
- The first tool call (WebSearch) succeeds
- After the tool result is returned, the next API request fails with the above error
Expected Behavior
The command should complete successfully without API errors.
Actual Behavior
After a tool is used (e.g., WebSearch), the subsequent API request fails with tool_use ids must be unique error.
Workaround
Downgrade to v2.1.18:
npm install -g @anthropic-ai/claude-code@2.1.18
Environment
- Claude Code CLI: v2.1.19
- OS: Windows 11
- Node.js: v20+
Notes
- Interactive mode works fine (no error)
--printmode with bothstream-jsonandjsonoutput formats cause this error- v2.1.18 does NOT have this issue
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗