anthropics / anthropics/claude-agent-sdk-python

PreToolUse hook updatedInput has no effect on AskUserQuestion tool

Đang mở
#767 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
8.1k
Fork
1.3k
Merge trung bình
2 ngày 31 phút
Pull request đã merge (30 ngày)
1

Mô tả

## Description

When a PreToolUse Python hook callback returns `updatedInput` for AskUserQuestion, the updated input is not reflected in the tool result that Claude sees. Claude continues as if no answer was provided.

## Steps to Reproduce

```python
async def ask_hook(hook_input, tool_use_id, hook_context):
return {
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "allow",
"updatedInput": {"answer": "Jeremy"}, # This is ignored
}
}

options = ClaudeAgentOptions(
permission_mode="bypassPermissions",
cli_path="/home/tester/.local/bin/claude",
hooks={
"PreToolUse": [HookMatcher(matcher="AskUserQuestion", hooks=[ask_hook])],
},
)

async for msg in query(prompt="Ask my name with AskUserQuestion, then greet me", options=options):
if isinstance(msg, ResultMessage):
print(msg.result)
# Output: "It seems your answer didn't come through clearly!"
# Expected: "Hello, Jeremy!"
```

## Expected Behavior

`updatedInput: {"answer": "Jeremy"}` should replace the AskUserQuestion tool input, and Claude should see the answer in the tool result.

## Workaround

Use `permissionDecision: "deny"` with the answer in `permissionDecisionReason`:
```python
return {
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": "The user has already provided their answer: Jeremy",
}
}
```
Claude reads the denial reason and uses the answer correctly.

## Environment

- claude-agent-sdk: 0.1.51
- Claude CLI: 2.1.86
- Python: 3.12
- OS: Linux (Docker)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.