Skip to content

Bug: tool_use IDs are not unique in claude-agent-sdk 0.1.22 #522

@viniciussantos45

Description

@viniciussantos45

Description

When using claude-agent-sdk version 0.1.22, the SDK generates duplicate tool_use.id values during agent execution, causing the Claude API to return the following error:

400 invalid_request_error:
messages.X.content.Y: `tool_use` ids must be unique

This happens even when the user does not manually define any tool_use blocks, indicating that the issue is caused by the SDK’s internal tool invocation logic.

Downgrading to claude-agent-sdk 0.1.20 resolves the issue.


Environment

  • OS: macOS
  • Python: 3.13.8
  • SDK: claude-agent-sdk 0.1.22 (bug)
  • SDK: claude-agent-sdk 0.1.20 (working)

Steps to Reproduce

Using claude-agent-sdk 0.1.22:

import asyncio

from claude_agent_sdk import (
    AssistantMessage,
    ClaudeAgentOptions,
    TextBlock,
    query,
)

async def main():
    options = ClaudeAgentOptions(
        allowed_tools=["Read"],
        system_prompt="You are a helpful coding assistant.",
        cwd=".",
    )

    async for message in query(
        prompt="What is this repository about?",
        options=options,
    ):
        if isinstance(message, AssistantMessage):
            for block in message.content:
                if isinstance(block, TextBlock):
                    print(block.text)

asyncio.run(main())

Expected Behavior

The agent should successfully execute tool calls and return a response describing the repository.


Actual Behavior

The request fails with:

400 invalid_request_error:
messages.X.content.Y: `tool_use` ids must be unique

This suggests that the SDK is reusing the same tool_use.id across multiple internal tool invocations.


Workaround

Downgrading the SDK fixes the issue:

pip install claude-agent-sdk==0.1.20

Additional Notes

This issue appears when the agent performs multiple internal tool calls (e.g. repeated Read operations).
The user code does not define or reuse tool_use IDs manually — the duplication is fully internal to the SDK.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions