Skip to content

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

Open

Description

@siliconcat

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

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

Activity

  1. github-actions commented on Jan 24, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] --print mode generates duplicate tool_use IDs causing API error 400 #16340
    2. [BUG] API Error 400 "tool use concurrency issues" occurs only in print mode (-p), not in interactive mode #18131
    3. [BUG] Claude keeps crashing when I ask it to stop and or clarify what it is doing #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

  2. siliconcat commented on Jan 24, 2026

    @siliconcat
    Author

    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.

  3. kenfdev commented on Jan 24, 2026

    @kenfdev

    I posted a similar issue #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
  4. matchpoint-ai-bot commented on Jan 24, 2026

    @matchpoint-ai-bot

    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.
  5. matchpoint-ai-bot commented on Jan 24, 2026

    @matchpoint-ai-bot

    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.
  6. EdgarHApollo commented on Jan 26, 2026

    @EdgarHApollo

    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

    # 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.
  7. miohtama commented on Jan 26, 2026

    @miohtama

    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.

  8. matthew-bram commented on Feb 5, 2026

    @matthew-bram

    Has anyone seen any movement on this?

  9. starkey-01 commented on Feb 24, 2026

    @starkey-01

    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>"}
    
  10. BenjaminCes commented on Mar 2, 2026

    @BenjaminCes

    same error here!

  11. zernie commented on Mar 6, 2026

    @zernie

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

  12. malachany commented on Mar 7, 2026

    @malachany

    I have this error in Claude Code Cloud while on mobile

  13. WynnD commented on Mar 12, 2026

    @WynnD

    I am also consistently hitting this wall

  14. acehox commented on Mar 12, 2026

    @acehox

    Same issue here, also on mobile

  15. zernie commented on Mar 13, 2026

    @zernie

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiarea:toolsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions