[BUG] Multi-turn tool use in -p mode fails with "tool_use ids must be unique" (regression in 2.1.19)
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 Code in non-interactive print mode (-p) with tools enabled and --max-turns > 1, the second API call after a tool execution fails with:
echo "Read the file package.json" | ~/.local/share/claude/versions/2.1.19 -p --max-turns 2 --allowedTools "Read"
Fails with:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1: `tool_use` ids must be unique"},"request_id":"req_011CXWiczWyfqE6xJjdJ3ktn"}
This is a regression introduced in version 2.1.19. Versions 2.1.17 and 2.1.18 work correctly.
What Should Happen?
Claude reads the file and returns a summary.
Error Messages/Logs
Steps to Reproduce
echo "Read the file package.json" | ~/.local/share/claude/versions/2.1.19 -p --max-turns 2 --allowedTools "Read"
Claude Model
Not sure / Multiple models
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
iTerm2
Additional Information
From ~/.claude/debug/*.txt when the error occurs:
2026-01-26T20:29:51.437Z [DEBUG] Stream started - received first chunk
2026-01-26T20:29:52.958Z [DEBUG] executePreToolHooks called for tool: Read
2026-01-26T20:29:53.016Z [DEBUG] Getting matching hook commands for PostToolUse with query: Read
2026-01-26T20:29:53.080Z [DEBUG] [API:request] Creating client, ANTHROPIC_CUSTOM_HEADERS present: false, has Authorization header: false
2026-01-26T20:29:53.080Z [DEBUG] [API:auth] OAuth token check starting
2026-01-26T20:29:53.080Z [DEBUG] [API:auth] OAuth token check complete
2026-01-26T20:29:53.221Z [ERROR] Error in non-streaming fallback: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1: tool_use ids must be
unique"},"request_id":"req_011CXWd4ekrvcjusemBs62DQ"}
The error messages.1.content.1 indicates that in the second message (index 1), the second content block (index 1) contains a duplicate tool_use id. This suggests the CLI is incorrectly constructing the
conversation history when making the follow-up API call after tool execution.
The error occurs consistently with any tool (Read, Glob, Grep, Bash) and any model (opus, sonnet, haiku).
With --output-format stream-json --verbose, we can see the tool executes successfully:
```json
{"type":"assistant","message":{"content":[{"type":"tool_use","id":"toolu_01LnYAiD1gBt2qQWUUGZNaWM","name":"Glob","input":{"pattern":"**/*.ts"}}]}}
{"type":"user","message":{"content":[{"tool_use_id":"toolu_01LnYAiD1gBt2qQWUUGZNaWM","type":"tool_result","content":"..."}]}}
But then the next API call fails with the duplicate ID error.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗