API Error 400: tool_use ids must be unique - occurs consistently

Resolved 💬 13 comments Opened Jan 27, 2026 by sash Closed Apr 10, 2026

Description

When using Claude Code CLI with --print --output-format json, the API consistently returns a 400 error indicating duplicate tool_use IDs are being sent in the request.

Environment

  • Platform: macOS (Darwin 25.2.0)
  • Model: claude-opus-4-5-20251101

Error

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.1: `tool_use` ids must be unique"},"request_id":"req_011CXYMdu1vaiqC69uftUr9D"}

Observed Behavior

  • The CLI exits with code 0 (success)
  • JSON response has is_error: true but subtype: "success"
  • The error occurs consistently, not just occasionally
  • num_turns: 2 suggests it fails early in the conversation

Expected Behavior

  1. Tool use IDs should be unique in all API requests
  2. CLI should exit with non-zero code when API returns an error
  3. subtype should reflect the error state

Additional Context

The error messages.1.content.1: tool_use ids must be unique suggests tool_use blocks are being duplicated with the same ID somewhere in conversation serialization.

View original on GitHub ↗

This issue has 13 comments on GitHub. Read the full discussion on GitHub ↗