[BUG] API Error 400: "tool_use ids must be unique" when using -p flag with tool-requiring prompts

Status Open
Reported on v2.1.19
Maintainer reply None cached
Activity 15 comments · opened Jan 24, 2026

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_

View original on GitHub ↗

15 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/16340
  2. https://github.com/anthropics/claude-code/issues/18131
  3. https://github.com/anthropics/claude-code/issues/13124

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

siliconcat · 7 months ago

while it seems to be the same as #16340 that one has been marked as completed without a solution. Downgrading to 2.1.18 solves the problem, but 2.1.19 fails.

kenfdev · 7 months ago

I posted a similar issue https://github.com/anthropics/claude-code/issues/20573 but probably it was a duplicate of this issue.

I'll add a little more context.

After a fresh login (deleting ~/.claude.json), the first prompt to claude -p works correctly, but any subsequent prompt fails with an API error about duplicate tool_use IDs. Simple prompts like claude -p "hello" work.

The following steps always reproduces the problem:

  1. Delete ~/.claude.json to reset state
  2. Run claude and complete login
  3. Run a prompt: claude -p "check what tasks you have" - works
  4. Run the same or any other prompt again: claude -p "check what tasks you have" - fails
matchpoint-ai-bot · 7 months ago

Environment

  • Claude Code: 2.1.19 (regression)
  • OS: Ubuntu 22.04.5 LTS (GNU/Linux 6.8.0-90-generic x86_64)
  • Node: v22.22.0

Behavior

  • Print mode (-p) tool use fails with: API 400 "tool_use ids must be unique"

Repro
claude --dangerously-skip-permissions -p "Use Read tool to read ./README.md" --output-format stream-json --verbose

Workaround

  • Downgraded to 2.1.17: print-mode tool use works again

Extra

  • Non-interactive claude doctor hangs at "Checking installation status..." here.
matchpoint-ai-bot · 7 months ago

Follow-up (Ubuntu 22.04.5, node v22.22.0):

  • 2.1.19 fails on the first tool call in -p (no multi-turn required).
  • 2.1.17 works end-to-end: ./ralph.py --max 1 --marker RALPH_217_OK "Use exactly one tool call to run 'touch /tmp/ralph_217_tool_ok', then output RALPH_217_OK." created the file and returned the marker.
  • claude doctor hangs at "Checking installation status..." here.
EdgarHApollo · 7 months ago

## Additional Debug Findings

I can confirm this issue on v2.1.19. Rolling back to v2.1.17 resolves the problem.

### Environment

  • Claude Code: 2.1.19 (broken) → 2.1.17 (working)
  • OS: macOS Darwin 22.6.0 (arm64)
  • Auth: OAuth (Max subscription)

### Debug Log Analysis

Examining ~/.claude/debug/ logs reveals anomalous behavior when tool use is triggered:

~350 log entries at the exact same millisecond timestamp:
2026-01-26T16:57:17.756Z [DEBUG] [API:request] Creating client...
2026-01-26T16:57:17.756Z [DEBUG] [API:request] Creating client...
2026-01-26T16:57:17.756Z [DEBUG] [API:request] Creating client...
... repeated 100+ times

Breakdown:

  • 106 [API:request] Creating client calls
  • 212 [API:auth] OAuth token check calls (start + complete)

This suggests a race condition or runaway loop in the tool initialization code that's generating duplicate IDs.

### Reproduction

```bash
# Fails - any tool use
echo "Read test.txt" | claude --print --no-session-persistence

# Works - no tool use
echo "Say hello" | claude --print --no-session-persistence

Flags that DON'T help

  • --no-session-persistence
  • --dangerously-skip-permissions
  • Different models (--model claude-sonnet-4-...)
  • Clean directories without .claude settings
  • Fresh reinstall of CLI

Workaround

ln -sf ~/.local/share/claude/versions/2.1.17 ~/.local/bin/claude

This completely resolves the issue. v2.1.17 handles tool use correctly.

miohtama · 7 months ago

I can confirm the downgrade to v2.1.17 solved the issue for me.

For Visual Studio Code, you can use _Extensions: Install Specific Version of Extension..._ in the command palette to pin down Claude Code to a working version.

matthew-bram · 6 months ago

Has anyone seen any movement on this?

starkey-01 · 6 months ago

I'm experiencing this same issue on Claude Code on Android and web.

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.7.content.3: tool_use ids must be unique"},"request_id":"<id>"}
BenjaminCes · 6 months ago

same error here!

zernie · 5 months ago

The worst thing is that you can't avoid this one in Claude code web

malachany · 5 months ago

I have this error in Claude Code Cloud while on mobile

WynnD · 5 months ago

I am also consistently hitting this wall

Vedinsoh · 5 months ago

Same issue here, also on mobile

zernie · 5 months ago

I'm getting this more and more often. No idea what's causing it. Even compaction doesn't help