Repository navigation
[Bug]: Claude Code hooks spawn powershell.exe on every tool call (~360 ms overhead per call, even outside Orca panes) - #7131
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between c1a82aba07aa6119db963ef5bba426459f6781c1 and d96b010. 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis change replaces a single Windows hook command wrapper with two platform-tailored wrappers: Changes
Sequence Diagram(s)Not applicable; changes are localized wrapper selection and test refactors without a multi-component interaction flow. Estimated code review effort: 3/5 Related PRs: None specified. Suggested labels: windows, hooks, tests Suggested reviewers: None specified. 🐰 A rabbit hopped through cmd and bash, 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/claude/hook-settings.ts (1)
77-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShare the Windows cmd-safe path check with Codex
This repeats the Codex cmd-safe allow-list insrc/main/codex/hook-service.ts. Extract the regex/decision helper so both agents stay in sync if the accepted characters or fallback behavior changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f93132c1-9164-458f-9e1a-93c27f8d47d5
📒 Files selected for processing (2)
src/main/claude/hook-service.test.tssrc/main/claude/hook-settings.ts
|
Addressed the CodeRabbit nitpick: extracted the shared \WINDOWS_CMD_SAFE_PATH\ regex and \wrapHookCommand\ into \src/main/agent-hooks/installer-utils.ts. Both Claude (\hook-settings.ts) and Codex (\hook-service.ts) now delegate to the shared \wrapHookCommand. Also updated Droid, Gemini, Command Code, Cursor, and Grok — they all had the same \wrapWindowsHookCommand\ / \wrapPosixHookCommand\ pattern and benefit from the cmd-safe fast path. All 67 affected tests pass. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/command-code/hook-service.test.ts (1)
56-61: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTest can no longer detect if the fast path silently stops firing.
Accepting either the PowerShell-launcher pattern or the bare script filename means these tests pass regardless of which path is taken. Since the entire point of this PR is to skip the PowerShell wrapper for safe paths, consider adding one assertion (with a known-safe mock path) that specifically expects the bare script path — otherwise a regression that always falls back to the launcher (defeating the ~180ms savings) would go unnoticed.
Also applies to: 88-91
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8e2fa22f-bb03-471d-9dbc-4c68acb16aa3
📥 Commits
Reviewing files that changed from the base of the PR and between 568ab31 and c1a82aba07aa6119db963ef5bba426459f6781c1.
📒 Files selected for processing (13)
src/main/agent-hooks/installer-utils.tssrc/main/claude/hook-settings.tssrc/main/codex/hook-service.tssrc/main/command-code/hook-service.test.tssrc/main/command-code/hook-service.tssrc/main/cursor/hook-service.test.tssrc/main/cursor/hook-service.tssrc/main/droid/hook-service.test.tssrc/main/droid/hook-service.tssrc/main/gemini/hook-service.test.tssrc/main/gemini/hook-service.tssrc/main/grok/hook-service.test.tssrc/main/grok/hook-service.ts
| const command = config.hooks.PreToolUse[0].hooks[0].command | ||
| expect( | ||
| process.platform === 'win32' | ||
| ? WINDOWS_POWERSHELL_LAUNCHER.test(command) || command.includes(DROID_SCRIPT_FILE_NAME) | ||
| : /droid-hook/.test(command) | ||
| ).toBe(true) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Relaxed assertions can no longer catch a fallback regression on unsafe (spaced) paths.
Per the line-range change details, lines 108-110 sit in "the Windows-spaces regression test loop" — the test that verifies a path containing spaces still uses the PowerShell fallback rather than a bare invocation. OR-ing in command.includes(DROID_SCRIPT_FILE_NAME) means this assertion now also passes if the implementation incorrectly treats a spaced path as "cmd-safe" and emits the bare path directly — exactly the regression this test exists to catch, since an unescaped bare path with spaces would be mis-parsed by cmd.exe/MSYS. The same weakening at 77-82 similarly means the "happy path" test can no longer detect a regression where the new bare-path optimization silently never engages (i.e., code always falls back to PowerShell).
Suggest keeping the strict launcher-only assertion for the spaces-loop case (108-110), and asserting the bare path explicitly for the safe-path case (77-82), while still allowing platform variance.
🧪 Suggested tightening
- expect(
- WINDOWS_POWERSHELL_LAUNCHER.test(command) || command.includes(DROID_SCRIPT_FILE_NAME)
- ).toBe(true)
+ // Spaced paths must always fall back to the PowerShell wrapper.
+ expect(WINDOWS_POWERSHELL_LAUNCHER.test(command)).toBe(true)Also worth noting: this appears to conflict with the PR summary's claim that "the space-in-path fallback test remains unchanged."
Also applies to: 108-110
…er (stablyai#7116) Claude Code hooks on Windows were wrapped in powershell.exe -EncodedCommand, adding ~180ms per PowerShell spawn. With PreToolUse + PostToolUse both firing on every tool call, each call paid ~360ms overhead. Use the bare forward-slash .cmd path directly when the path contains no spaces or cmd metacharacters (the common case). Git Bash/MSYS executes .cmd files natively, dropping each hook invocation to ~60ms. Fall back to the PowerShell encoded launcher only for paths with spaces/special chars. Follows the same approach Codex already uses (WINDOWS_CMD_SAFE_PATH).
Move the WINDOWS_CMD_SAFE_PATH regex and safe-path fallback logic from Codex's getManagedCommand into a shared wrapHookCommand utility in installer-utils.ts. Update Claude, Codex, Droid, Gemini, Command Code, Cursor, and Grok agents to delegate to the shared function, giving every agent the ~180ms PowerShell startup skip when the hook script path is cmd.exe-safe.
c1a82ab to
d96b010
Compare
|
looking into it |
Description
Fixes #7116
Claude Code hooks on Windows were wrapped in \powershell.exe -EncodedCommand, adding ~180ms per PowerShell spawn. With \PreToolUse\ + \PostToolUse\ both firing on every tool call (via \matcher: '*' ), each call paid ~360ms overhead — adding minutes of dead time over an agentic session.
Change
Follows the same approach Codex already uses (\WINDOWS_CMD_SAFE_PATH\ in \src/main/codex/hook-service.ts):
Git Bash/MSYS executes .cmd\ files natively, so the PowerShell wrapper was unnecessary overhead for the common case.
Files changed
Verification
Cross-platform notes