anthropics / anthropics/claude-code
[DOCS] Remove obsolete Python can_use_tool dummy-hook workaround
- Ngôn ngữ chính
- Python
- Star
- 145k
- Fork
- 23.1k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Current Python SDK releases keep stdin open for `can_use_tool` without a dummy hook, but the user-input guide still tells users the workaround is required.
### Documentation Type
Incorrect/outdated documentation
### Documentation Location
https://code.claude.com/docs/en/agent-sdk/user-input
### Section/Topic
Python `can_use_tool` example and the streaming-mode note
### Current Documentation
The Python example still defines a no-op hook under this comment:
```python
# Required workaround: dummy hook keeps the stream open for can_use_tool
```
It also passes that hook through `ClaudeAgentOptions.hooks`. The note below the example says a finite prompt stream closes before the callback unless a hook or SDK MCP server keeps stdin open.
### What's Wrong or Missing?
https://github.com/anthropics/claude-agent-sdk-python/pull/1204 changed the Python SDK to keep stdin open when `can_use_tool` is configured. It also added support for `can_use_tool` with string prompts. The workaround and warning now describe behavior that current SDK releases no longer have.
The stale example makes users register an unrelated hook and suggests that the supported callback path still needs a transport workaround.
### Suggested Improvement
Remove `dummy_hook`, the `hooks={...}` option, and the note that says a hook or SDK MCP server is required. Use the string-prompt form in the Python example, matching the TypeScript example on the same page:
```python
async for message in query(
prompt="Create a test file and then delete it",
options=ClaudeAgentOptions(can_use_tool=can_use_tool),
):
...
```
The page can still state that `can_use_tool` uses streaming mode internally and that `ClaudeSDKClient` remains the better fit for long-lived interactive sessions.
### Impact
Medium - Makes feature difficult to understand
### Verification
The current SDK contract tests pass without any hook:
```console
$ python -m pytest -q tests/test_query.py -k 'can_use_tool_waits_for_result or string_prompt_with_can_use_tool_is_supported'
3 passed, 56 deselected in 0.91s
```
### Additional Context
Earlier reports such as https://github.com/anthropics/claude-code/issues/19694 described the real SDK bug before it was fixed. This report is about removing the workaround after the fix shipped.
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
Hướng nghiên cứu
Open the user-input guide at code.claude.com/docs/en/agent-sdk/user-input and review the Python can_use_tool example and streaming-mode note. Remove the dummy hook, hooks option, and obsolete workaround warning, then use the string-prompt form shown in the issue. Verify the related SDK contract tests with `python -m pytest -q tests/test_query.py -k 'can_use_tool_waits_for_result or string_prompt_with_can_use_tool_is_supported'`.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 92/100