Skip to content

fix(claude): run the native Windows hook exe for spaced profile paths - #33364

Merged
nwparker merged 2 commits into
mainfrom
nwparker/agint-win-claude-hook-unsafe-path-fallback
Oct 25, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/agint-win-claude-hook-unsafe-path-fallback

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​62
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

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

  • wrapWindowsDirectCmdHookCommand gates on WINDOWS_CMD_SAFE_PATH (/^[A-Za-z0-9_.:\\~-]+$/, windows-hook-command.ts:37). That pattern has no space, so getManagedLifecycleHook dropped the native exe and fell back to powershell.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).
  • Quoting alone (fix(hooks): carry a spaced profile path on the direct Windows hook (#19187) #19255's approach) doesn't fix it. Claude Code runs a hook command through 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 PowerShell and If its command is only quoted strings, PowerShell started no program … put the program in "command" and its arguments in "args". I measured this with real claude.exe 2.1.309 on Windows 11. "C:/Temp/First Last/…/orca-agent-hook.exe" claude works under Git Bash, but under PowerShell it fails with ParserError on every event and the hook never runs.
  • Claude Code 2.1.139 added exec-form hooks (CHANGELOG: "Added hook 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.install gates on the probed version (claudeAcceptsExecFormHooks). getStatus accepts an exec-form entry that's already installed, whatever the current probe says.
  • The managed-command matcher looks at command + args together. 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 claude string 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_DIR pointed there, hook files copied in). Settings were generated by this repo's getManagedLifecycleHook. A local listener captured the hook POSTs while claude -p ran one Bash tool call.

registration hooks delivered (Session/Prompt/Pre/Post/Stop) per-event hook time (claude debug log)
main (spaced → encoded PS) 5/5 656, 640, 634, 622, 633 ms
quoted path, Git Bash 5/5 —
quoted path, shell: powershell (no-Git-Bash host) 0/5, ParserError on every event —
this PR, exec form 5/5, payloads intact 34, 15, 18, 15, 16 ms

Tests: 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

  • Exec form only applies to spaced (non-cmd-safe) exe paths on a known Claude ≥ 2.1.139, so most installs don't change.
  • Older or parallel Orca builds (for example stable and RC side by side) don't recognise the exec-form entry and add their own PowerShell entry. Until the newer build reinstalls, Claude events can post twice.
  • Cursor and Grok import Claude hooks and run the command without args, so the spaced path is unquoted. It fails fast and doesn't block. Claude's hook already skips itself under those hosts.
  • Downgrading Claude below 2.1.139 heals itself on the next Orca restart: install re-probes the version and switches back to the encoded launcher.

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 -NonInteractive part 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

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: c362ed86-69ad-4bd9-8d8b-72f6743db389
Commits

Reviewing files that changed from the base of the PR and between 38dc4e5 and b7eb7bd.

Files selected for processing: 2
  • src/main/claude/hook-settings.ts
  • src/main/claude/windows-native-hook-registration.test.ts
Walkthrough

Claude hook registration now selects exec form for CLI versions at or above 2.1.139 and keeps shell form for older, unknown, or invalid versions. Managed-hook detection checks combined command and string arguments. Windows PowerShell hook launchers now include -NonInteractive, and related tests expect the switch.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 2b47b

An installation could remove an unrelated configured hook when its executable path happens to match the managed-hook pattern. Tighten the match before merging, or accept this bounded risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed The PR implements the coding requirements for both active linked issues. For #19187, Claude versions at or above 2.1.139 use an exec-form hook with the spaced native .exe path in command and `clau…
Out of Scope Changes check Passed The changes stay within the linked issue scope. The matcher changes and Claude version handling support spaced-path exec-form registration. The launcher changes and updated tests support the PowerShel…
Title check Passed The title clearly identifies the primary change: running the native Windows Claude hook executable when profile paths contain spaces.
Description check Passed The description is detailed and relevant. It explains the user impact, root cause, implementation, compatibility behavior, linked issue, testing, performance results, and risks. It omits several templ…
Full details: Linked Issues check

Explanation

The PR implements the coding requirements for both active linked issues. For #19187, Claude versions at or above 2.1.139 use an exec-form hook with the spaced native .exe path in command and claude in args. Older and unknown versions retain the compatible encoded launcher. Installation and status detection recognize the forms, and tests cover spaced profiles, version gating, repeated installation, and managed-command matching. For #17977, WINDOWS_POWERSHELL_HOOK_SWITCHES now includes -NonInteractive, and the affected launcher tests assert the new switch.

Full details: Out of Scope Changes check

Explanation

The changes stay within the linked issue scope. The matcher changes and Claude version handling support spaced-path exec-form registration. The launcher changes and updated tests support the PowerShell stdin fix. No unrelated production behavior or unrelated tests are introduced.

Full details: Description check

Explanation

The description is detailed and relevant. It explains the user impact, root cause, implementation, compatibility behavior, linked issue, testing, performance results, and risks. It omits several template headings and checklist items, but the critical review information is present.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts
  • src/main/agent-hooks/installer-utils.ts
  • src/main/agent-hooks/windows-powershell-hook-launcher.test.ts
  • src/main/agent-hooks/windows-powershell-hook-launcher.ts
  • src/main/claude/claude-hook-event-versions.ts
  • src/main/claude/hook-service.test.ts
  • src/main/claude/hook-service.ts
  • src/main/claude/hook-settings.ts
  • src/main/claude/windows-native-hook-registration.test.ts
  • src/main/cursor/hook-service.test.ts
  • src/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.

Comment thread src/main/agent-hooks/installer-utils.ts Resolved
@nwparker nwparker changed the title fix(claude): run the native Windows hook for spaced profiles; keep PS 5.1 off hook stdin fix(claude): run the native Windows hook exe for spaced profile paths Oct 25, 2026
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>
@nwparker
nwparker force-pushed the nwparker/agint-win-claude-hook-unsafe-path-fallback branch from 04183d1 to 38dc4e5 Compare October 25, 2026 03:10
… 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.
@nwparker

Copy link
Copy Markdown
Contributor Author

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 args element, #13443) recognises and replaces it — stable+RC side by side no longer double-post; only builds older than v1.4.183 would. Two builds may rewrite the entry at each startup (one entry at a time). Verified on real Windows: 5/5 events once each, ~15 ms/hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant