Repository navigation
fix(claude): run the native Windows hook exe for spaced profile paths - #33364
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 5 minutes. View limit details
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6e2bd26f-371d-49f4-8b4c-7f61e799296b
Commits-
Reviewing files that changed from the base of the PR and between 0fa161b and 2b47b5281f4b9080f7aa712b0bec41ae9a31089a.
Files selected for processing: 11-
src/main/agent-hooks/installer-utils.test.tssrc/main/agent-hooks/installer-utils.tssrc/main/agent-hooks/windows-powershell-hook-launcher.test.tssrc/main/agent-hooks/windows-powershell-hook-launcher.tssrc/main/claude/claude-hook-event-versions.tssrc/main/claude/hook-service.test.tssrc/main/claude/hook-service.tssrc/main/claude/hook-settings.tssrc/main/claude/windows-native-hook-registration.test.tssrc/main/cursor/hook-service.test.tssrc/main/grok/hook-service.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
A profile path with a space (C:\Users\First Last) failed the cmd-safe gate, so the native orca-agent-hook.exe was skipped and every Claude hook event started powershell.exe -EncodedCommand instead (~640 ms vs ~16 ms per event measured on Windows 11 with claude 2.1.309). Quoting the path is not enough: Git Bash needs the quotes, but Claude's no-Git-Bash PowerShell host treats `"path" claude` as a parse error. Claude 2.1.139+ accepts exec-form hooks (`command` + `args`) that spawn without a shell, so a spaced exe path is registered that way when the probed CLI version supports it; older or unknown versions keep the encoded launcher. Fixes #19187 Co-authored-by: marcdhansen <7607160+marcdhansen@users.noreply.github.com>
04183d1 to
38dc4e5
Compare
… entry Builds since v1.4.183 match managed hooks by any args element, so carrying the script path as argv[2] (ignored by orca-agent-hook.exe) makes a stable/RC build replace the entry instead of adding a duplicate PowerShell hook. The existing args matcher then covers reinstall, so the command+args join is dropped.
|
Review note (supersedes the Risk bullets in the description): the exec-form entry now carries the script path as a 2nd arg, so every Orca build since v1.4.183 (whose matcher checks each |
ELI5
On Windows, if your user folder has a space in it (
C:\Users\First Last), Orca didn't use its fast native Claude hook (orca-agent-hook.exe). Every Claude hook event started a whole PowerShell process instead. That cost about 640 ms per event, and it's the launcher behind the orphaned-conhost reports. With this change, Claude runs the exe directly and doesn't go through a shell, so spaces don't matter.Root cause
wrapWindowsDirectCmdHookCommandgates onWINDOWS_CMD_SAFE_PATH(/^[A-Za-z0-9_.:\\~-]+$/,windows-hook-command.ts:37). That pattern has no space, sogetManagedLifecycleHookdropped the native exe and fell back topowershell.exe -NoProfile -EncodedCommand …(Windows: the #18875 direct-hook fix is inert for any profile with a space (C:\Users\First Last), keeping the encoded launcher and its conhost orphan leak #19187).commandthrough Git Bash when Git Bash is installed and through PowerShell when it isn't. Claude 2.1.310's bundle says so:Git Bash wasn't found, so a ${e} hook ran in PowerShellandIf its command is only quoted strings, PowerShell started no program … put the program in "command" and its arguments in "args". I measured this with realclaude.exe2.1.309 on Windows 11."C:/Temp/First Last/…/orca-agent-hook.exe" claudeworks under Git Bash, but under PowerShell it fails withParserErroron every event and the hook never runs.args: string[]field (exec form) that spawns the command directly without a shell, so path placeholders never need quoting"). Exec form doesn't depend on which host shell Claude picks.What changed
getManagedLifecycleHook: if the native exe path can't be written as a bare cmd-safe path and the probed Claude version is ≥ 2.1.139, register{ command: <exe path>, args: ['claude'] }. Older versions, or an unknown version, keep the existing encoded launcher.ClaudeHookService.installgates on the probed version (claudeAcceptsExecFormHooks).getStatusaccepts an exec-form entry that's already installed, whatever the current probe says.command + argstogether. Reinstalling therefore replaces an exec-form entry instead of adding a duplicate, and other agents (openclaude, …) still don't claim it.Unspaced profiles keep the same bare
C:/…/orca-agent-hook.exe claudestring as before, so their settings don't churn. The PowerShell launcher switches are unchanged.How verified (real Windows host,
awin-lan, Win11 26100, PS 5.1, claude.exe 2.1.309)I used a sandbox profile at
C:\Temp\First Last(USERPROFILE/CLAUDE_CONFIG_DIRpointed there, hook files copied in). Settings were generated by this repo'sgetManagedLifecycleHook. A local listener captured the hook POSTs whileclaude -pran one Bash tool call.shell: powershell(no-Git-Bash host)ParserErroron every eventTests:
pnpm tc,check:code-quality:changed, the agent-hooks/claude suites on macOS, plus the new Windows-only spaced-temp-home install test on awin-lan.Risk
commandwithoutargs, so the spaced path is unquoted. It fails fast and doesn't block. Claude's hook already skips itself under those hosts.Credit
Co-authored with marcdhansen, who diagnosed #19187 and opened #19255. This supersedes #19255, whose quoted form breaks under Claude's no-Git-Bash PowerShell host (table above) and conflicts with current main. The PowerShell
-NonInteractivepart of the original cluster (#17977) is left for a separate Win10 / PS 5.1 repro. It broke the AllSigned process-policy hook path on Windows CI, and it did not reproduce on Win11.Fixes #19187
Refs #20913