anthropics / anthropics/claude-code
Windows: synchronous command hooks wait for persistent descendants
- Ngôn ngữ chính
- Python
- Star
- 145k
- Fork
- 23.1k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
## Summary
On Windows, a synchronous command hook can delay its enclosing Claude Code event until a persistent descendant exits, even though the configured hook process has already exited successfully.
This is a bounded delay, not the worktree-transition result-loss symptom reported in #90049.
## Environment
- Claude Code 2.1.263
- Windows 11 Pro 10.0.26100
- Interactive CLI, except where noted
## Minimal reproduction
Create `C:\temp\child.ps1`:
```powershell
Start-Sleep -Seconds 90
```
Create an empty `C:\temp\in.txt`, then create `C:\temp\hook.ps1`:
```powershell
$null = [Console]::In.ReadToEnd()
Start-Process powershell.exe -ArgumentList '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', 'C:\temp\child.ps1' `
-RedirectStandardInput 'C:\temp\in.txt' `
-RedirectStandardOutput 'C:\temp\out.txt' `
-RedirectStandardError 'C:\temp\err.txt'
exit 0
```
Use this project `.claude/settings.json`:
```json
{
"hooks": {
"PostToolUse": [{
"matcher": "PowerShell",
"hooks": [{
"type": "command",
"command": "powershell.exe",
"args": ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "C:\\temp\\hook.ps1"],
"timeout": 120
}]
}]
}
}
```
In a fresh interactive Claude Code session in a Git repository, run a harmless PowerShell tool command such as:
```powershell
Get-Date -Format o
```
## Expected
The tool result is delivered when `hook.ps1` exits.
## Actual
The main tool completes, and `hook.ps1` exits immediately, but Claude Code delays the tool result until `child.ps1` exits about 90 seconds later. In one controlled run:
```text
[Stall] tool_dispatch_end tool=PowerShell toolUseId=call_JDUVNrA2A9kA9qxZ48LWiZz9 outcome=ok durationMs=925
Slow PostToolUse hooks: 91931ms for PowerShell (1 hooks)
```
The child has stdin, stdout, and stderr redirected to files.
## Additional controls
The same parent/child pattern was reproduced across synchronous command hooks:
| Event | Observed continuation point |
| --- | --- |
| `PreToolUse` | The tool dispatch began only after the 30-second child exited. |
| `PostToolUse` | The tool result was delayed until the child exited. |
| `PostToolUseFailure` | The following model request began only after the child exited. |
| `UserPromptSubmit` | The model request began only after the child exited. |
| `SessionStart` | The first model turn began only after the child exited. |
| `Stop` | The turn ended only after the child exited. |
| `SessionEnd` | The hook completed only after the child exited in a print-mode control. |
| `Notification:idle_prompt` | The hook completed only after the child exited. |
In valid controls, the configured hook parent exited with code 0 in roughly 50–100 ms and the descendant lasted 30–90 seconds.
Configuring the hook with `async: true` avoids this synchronous wait in the tested `PostToolUse` control.
## Scope
This does not establish the internal mechanism. In particular, it does not prove explicit process-tree tracking. It establishes that, on Windows, these synchronous command-hook event paths do not complete while a persistent descendant remains alive.
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
No implementation files or tests are named. Start by reproducing the Windows synchronous command-hook behavior with the provided PowerShell parent/child scripts, then trace the hook handling for the listed event paths and compare it with the async control. Done means synchronous hooks continue when the configured parent exits successfully rather than waiting for its persistent descendant.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- powershell
- Lĩnh vực
- cli, devtools, operating-systems
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100