anthropics / anthropics/claude-agent-sdk-python

Hook denial causes "API Error: 400 due to tool use concurrency issues" instead of graceful handling

未關閉
#265 0 則留言 2 個 reaction 已指派 1 人 已被 @dhollman 認領 在 GitHub 檢視
bug
主要語言
Python
星號
8.1k
分支
1.3k
平均合併
2 天 31 分鐘
30 天內合併 PR
1

描述

## Issue Description
When using PreToolUse hooks to deny tool access, Claude responds with a synthetic error message about "tool use concurrency issues" instead of gracefully handling the hook denial. This appears to be a regression as the same code worked correctly previously.

## Expected Behavior
When a hook denies tool access, Claude should either:

Gracefully acknowledge the denial and inform the user it cannot access the resource
Ask for clarification or suggest alternatives
Continue the conversation without generating an API error

## Actual Behavior
Claude generates a synthetic error message:
API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation.
This error message is misleading as there are no actual concurrency issues - the tool was simply denied by the hook.

## Reproduction:
Just run the example at [hooks](https://github.com/anthropics/claude-agent-sdk-python?tab=readme-ov-file#example)

## Output:
```
SystemMessage(subtype='init', data={'type': 'system', 'subtype': 'init', 'cwd': '/Users/shashank/Downloads/tests', 'session_id': '04733b4c-3f8d-473b-bc98-13d8bf791f68', 'tools': ['Task', 'Bash', 'Glob', 'Grep', 'ExitPlanMode', 'Read', 'Edit', 'Write', 'NotebookEdit', 'WebFetch', 'TodoWrite', 'WebSearch', 'BashOutput', 'KillShell', 'Skill', 'SlashCommand'], 'mcp_servers': [], 'model': 'claude-sonnet-4-5-20250929', 'permissionMode': 'default', 'slash_commands': ['compact', 'context', 'cost', 'init', 'output-style:new', 'pr-comments', 'release-notes', 'todos', 'review', 'security-review'], 'apiKeySource': 'ANTHROPIC_API_KEY', 'claude_code_version': '2.0.20', 'output_style': 'default', 'agents': ['general-purpose', 'statusline-setup', 'output-style-setup', 'Explore'], 'uuid': '528e006a-6260-44e6-8af5-fc085de21a3d'})
AssistantMessage(content=[TextBlock(text="I'll run the bash command to display the help information for the foo.sh script.")], model='claude-sonnet-4-5-20250929', parent_tool_use_id=None)
AssistantMessage(content=[ToolUseBlock(id='toolu_01KtERtZPLP1jJHD8Q6R5Urr', name='Bash', input={'command': './foo.sh --help', 'description': 'Run foo.sh script with --help flag'})], model='claude-sonnet-4-5-20250929', parent_tool_use_id=None)
UserMessage(content=[ToolResultBlock(tool_use_id='toolu_01KtERtZPLP1jJHD8Q6R5Urr', content='Hook requested permission behavior: deny', is_error=True)], parent_tool_use_id=None)
AssistantMessage(content=[TextBlock(text='API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation.')], model='', parent_tool_use_id=None)
ResultMessage(subtype='success', duration_ms=6004, duration_api_ms=8428, is_error=True, num_turns=4, session_id='04733b4c-3f8d-473b-bc98-13d8bf791f68', total_cost_usd=0.016683999999999997, usage={'input_tokens': 3, 'cache_creation_input_tokens': 2604, 'cache_read_input_tokens': 12040, 'output_tokens': 101, 'server_tool_use': {'web_search_requests': 0}, 'service_tier': 'standard', 'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 2604}}, result='API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation.')

==================================================

SystemMessage(subtype='init', data={'type': 'system', 'subtype': 'init', 'cwd': '/Users/shashank/Downloads/tests', 'session_id': '04733b4c-3f8d-473b-bc98-13d8bf791f68', 'tools': ['Task', 'Bash', 'Glob', 'Grep', 'ExitPlanMode', 'Read', 'Edit', 'Write', 'NotebookEdit', 'WebFetch', 'TodoWrite', 'WebSearch', 'BashOutput', 'KillShell', 'Skill', 'SlashCommand'], 'mcp_servers': [], 'model': 'claude-sonnet-4-5-20250929', 'permissionMode': 'default', 'slash_commands': ['compact', 'context', 'cost', 'init', 'output-style:new', 'pr-comments', 'release-notes', 'todos', 'review', 'security-review'], 'apiKeySource': 'ANTHROPIC_API_KEY', 'claude_code_version': '2.0.20', 'output_style': 'default', 'agents': ['general-purpose', 'statusline-setup', 'output-style-setup', 'Explore'], 'uuid': '52d621cc-abbb-4c45-8245-b72b17b0172e'})
AssistantMessage(content=[TextBlock(text="I'll run the bash command to echo the message.")], model='claude-sonnet-4-5-20250929', parent_tool_use_id=None)
AssistantMessage(content=[ToolUseBlock(id='toolu_01GSdQauBw8vtEroSiVYdYXj', name='Bash', input={'command': "echo 'Hello from hooks example!'", 'description': 'Echo a greeting message'})], model='claude-sonnet-4-5-20250929', parent_tool_use_id=None)
UserMessage(content=[ToolResultBlock(tool_use_id='toolu_01GSdQauBw8vtEroSiVYdYXj', content='Hello from hooks example\\!', is_error=False)], parent_tool_use_id=None)
AssistantMessage(content=[TextBlock(text='The command executed successfully and printed: `Hello from hooks example!`')], model='claude-sonnet-4-5-20250929', parent_tool_use_id=None)
ResultMessage(subtype='success', duration_ms=7572, duration_api_ms=16764, is_error=False, num_turns=9, session_id='04733b4c-3f8d-473b-bc98-13d8bf791f68', total_cost_usd=0.028661349999999995, usage={'input_tokens': 8, 'cache_creation_input_tokens': 275, 'cache_read_input_tokens': 29457, 'output_tokens': 108, 'server_tool_use': {'web_search_requests': 0}, 'service_tier': 'standard', 'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 275}}, result='The command executed successfully and printed: `Hello from hooks example!`')
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。