Skip to content

Speed up Windows Codex/Claude hooks without dropping events - #6402

Merged
OrcaWin merged 1 commit into
mainfrom
brennanb2025/codex-windows-hook-speed
Jun 26, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
brennanb2025/codex-windows-hook-speed

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Problem (regression)

On Windows, managed hooks run through a shell. #6078 wrapped the launcher in powershell -EncodedCommand to survive spaces in profile paths. Combined with the inner PowerShell Invoke-WebRequest post (#2100), every hook spawned two PowerShell processes (~280–410ms startup each, measured) → ~650ms+ per hook, fired up to 6× per turn. Codex 0.140 renders that as lingering Running <event> hook rows.

A prior RC worked around this by deleting SessionStart/UserPromptSubmit/Stop, which loses lifecycle status fidelity. This PR keeps all six events and makes them fast instead.

Fix

Codex (executes hooks as cmd.exe /C <command>):

  • Emit the bare .cmd path for cmd-safe profiles → Codex runs it directly with zero shell startup. Spaced/metachar paths still fall back to the encoded PowerShell launcher (preserves [Bug]: Codex hooks fail on Windows when user path contains spaces #6078 robustness).
  • Replace the inner PowerShell post with curl.exe (Windows 10 1803+), posting the same form fields as the POSIX hook and reading the raw payload from stdin via --data-urlencode payload@- so UTF-8 (e.g. CJK) survives without code-page translation.
  • Common case: 0 PowerShell (~70–150ms) vs ~650ms; spaced-path profiles drop to 1.

Claude (executes hooks through Git Bash):

  • The launcher must stay PowerShell-encoded (a bare path is what breaks Git Bash). But its inner post moves to curl.exe too → 2 PowerShell startups → 1.

Validation

Against the real Codex 0.140 binary (interactive TUI via node-pty + codex exec):

  • All managed hooks fire, render for only 1–2 spinner frames, and clear — no lingering rows; the TUI returns to the idle prompt.
  • A local listener received every hook post in 1–6 ms.
  • Orca's status IPC reports codex state: "installed" (all 6 events present and trust hashes match) in a dev build off this branch.
  • New unit/integration tests: a win32 end-to-end test spawns the generated script through cmd.exe and asserts UTF-8 (CJK) + a worktreeId with spaces and & survive. 65 passed | 3 skipped; typecheck + lint clean.

Notes

  • The bare backslash form (which broke Claude hooks via Git Bash) is not produced by this change; Claude keeps its encoded launcher.
  • Claude is intentionally left at 1 PowerShell rather than 0 — a Git Bash bare path reintroduces the exact breakage class this avoids.

🤖 Generated with Claude Code

Windows runs managed hooks through a shell, and #6078 wrapped the
launcher in `powershell -EncodedCommand` to survive spaces in profile
paths. Combined with the inner PowerShell Invoke-WebRequest post, every
hook spawned two PowerShell processes (~300ms startup each), so a hook
took ~650ms+ and fired up to 6x per turn. Codex 0.140 renders that as
lingering "Running <event> hook" rows. The earlier RC worked around it
by deleting SessionStart/UserPromptSubmit/Stop, which loses lifecycle
status fidelity.

Keep all six Codex events and make them fast instead:

- Codex runs hooks as `cmd.exe /C <command>` and forwards our string
  verbatim when it has no spaces/quotes, so emit the bare .cmd path for
  cmd-safe profiles (zero shell startup) and fall back to the encoded
  PowerShell launcher only for spaced/metachar paths (#6078 robustness).
- Replace the inner PowerShell post with curl.exe (Windows 10 1803+),
  posting the same form fields as the POSIX hook and reading the raw
  payload from stdin via `--data-urlencode payload@-` so UTF-8 (e.g. CJK)
  survives without code-page translation.

Result: the common Codex case is 0 PowerShell (~70-150ms vs ~650ms);
spaced-path profiles drop to 1.

Claude runs hooks through Git Bash, so its launcher must stay
PowerShell-encoded (a bare path is what breaks it), but its inner post
moves to curl.exe too, cutting Claude from two PowerShell startups to
one.

Validated against the real Codex 0.140 binary (interactive TUI + exec):
all managed hooks fire, render briefly, and clear with no lingering
rows; the listener receives every post in 1-6ms.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@OrcaWin
OrcaWin merged commit d0d2571 into main Jun 26, 2026
2 checks passed
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 56f64403-189a-4c7e-a245-ef14e07ad501

📥 Commits

Reviewing files that changed from the base of the PR and between fe53387 and 088a816.

📒 Files selected for processing (6)
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/installer-utils.ts
  • src/main/claude/hook-service.test.ts
  • src/main/claude/hook-service.ts
  • src/main/codex/hook-service.test.ts
  • src/main/codex/hook-service.ts

📝 Walkthrough

Walkthrough

Adds a Windows curl-based hook POST command helper, switches the Windows managed hook scripts for Claude and Codex to use it, and expands Windows tests to cover command generation, direct .cmd execution for cmd-safe paths, and end-to-end payload submission.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

nwparker added a commit that referenced this pull request Aug 20, 2026
…erpreter

The Antigravity drift was invisible to per-agent tests. The shared builder took
only `(source)` and could not add the extra form field Antigravity needs, so it
forked a private copy of the then-correct PowerShell command (#2100); when the
shared builder moved to curl (#6402) every caller was fixed for free and the
copy silently was not.

Assert the violated invariant across all ten batch-script agents at once, and
generate under a mocked win32 platform so the POSIX CI legs guard it too.
Verified to fail on the pre-fix script, naming the offending file.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#6402)

Windows runs managed hooks through a shell, and stablyai#6078 wrapped the
launcher in `powershell -EncodedCommand` to survive spaces in profile
paths. Combined with the inner PowerShell Invoke-WebRequest post, every
hook spawned two PowerShell processes (~300ms startup each), so a hook
took ~650ms+ and fired up to 6x per turn. Codex 0.140 renders that as
lingering "Running <event> hook" rows. The earlier RC worked around it
by deleting SessionStart/UserPromptSubmit/Stop, which loses lifecycle
status fidelity.

Keep all six Codex events and make them fast instead:

- Codex runs hooks as `cmd.exe /C <command>` and forwards our string
  verbatim when it has no spaces/quotes, so emit the bare .cmd path for
  cmd-safe profiles (zero shell startup) and fall back to the encoded
  PowerShell launcher only for spaced/metachar paths (stablyai#6078 robustness).
- Replace the inner PowerShell post with curl.exe (Windows 10 1803+),
  posting the same form fields as the POSIX hook and reading the raw
  payload from stdin via `--data-urlencode payload@-` so UTF-8 (e.g. CJK)
  survives without code-page translation.

Result: the common Codex case is 0 PowerShell (~70-150ms vs ~650ms);
spaced-path profiles drop to 1.

Claude runs hooks through Git Bash, so its launcher must stay
PowerShell-encoded (a bare path is what breaks it), but its inner post
moves to curl.exe too, cutting Claude from two PowerShell startups to
one.

Validated against the real Codex 0.140 binary (interactive TUI + exec):
all managed hooks fire, render briefly, and clear with no lingering
rows; the listener receives every post in 1-6ms.

Co-authored-by: Neil <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants