stream-json mode: duplicate tool_use IDs error on multi-turn
Resolved 💬 4 comments Opened Jan 24, 2026 by joelreymont Closed Feb 28, 2026
Bug Description
When using -p --input-format stream-json --output-format stream-json mode, sending a second prompt after a tool use results in:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1: `tool_use` ids must be unique"}}
Reproduction
(echo '{"type":"user","message":{"role":"user","content":"run: echo hello"}}' && sleep 8 && echo '{"type":"user","message":{"role":"user","content":"keep going"}}') | claude -p --input-format stream-json --output-format stream-json --verbose --permission-mode bypassPermissions
Expected Behavior
Second prompt should work - conversation should continue normally.
Actual Behavior
First turn works (tool executes), second prompt fails with duplicate tool_use ID error.
Environment
- claude --version: 2.1.19
- macOS
Analysis
The error messages.1.content.1: tool_use ids must be unique indicates Claude CLI is building the messages array incorrectly when making the second API call. The tool_use ID from the first turn is being duplicated.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗