Skip to content

fix(codex): hooks launch on Windows, whichever shell Codex uses - #308

Merged
blitzcrieg1 merged 5 commits into
masterfrom
fix/codex-windows-hook-command
Oct 22, 2026
Merged

blitzcrieg1 merged 5 commits into
masterfrom
fix/codex-windows-hook-command

Conversation

@blitzcrieg1

@blitzcrieg1 blitzcrieg1 commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Fixes #307. Refs #300, #302.

What was wrong

The Codex installer wrote "<python.exe>" "<agentmetry_ingest.py>" codex hook <Event>. On Windows, Codex reported every hook run as started and completed, but nothing reached ingest: no event, no 401, no spool. Run as written, the command exits 1 under cmd /c (the leading quoted token breaks cmd's quote stripping) and under powershell -Command (a command that starts with a quoted string is a string, not a call). The installer already guards against the PowerShell case for VS Code. The dogfood machine's last Codex event was in July.

What changed

  • windows_hook_command(command): removes the quotes; a path containing a space is replaced by its 8.3 short name (GetShortPathNameW); a path with no short name keeps its quotes, so the result is never worse than before.
  • merge_codex_hooks(..., windows=None): on Windows each Agentmetry handler's command is the unquoted form. It does not use Codex's commandWindows override (see below). The command still contains codex hook, so idempotent reinstalls recognise our groups, and a reinstall drops a commandWindows left by the first commit.
  • docs/agent-coverage.md: the Codex row notes the unquoted command, why commandWindows is avoided, and that /hooks approval applies to conversations started afterwards.

Tests (tests/test_codex_windows_command.py, 11)

  • The rewrite for the script, frozen and console forms; short-name substitution; the no-short-name fallback.
  • On Windows the installer writes an unquoted command for every Codex event and never commandWindows; elsewhere the command keeps its quotes; reinstalling does not duplicate and drops an old override.
  • On Windows, the generated command is launched through cmd and PowerShell, with a plain path and with a path containing a space, and must write a marker with the right arguments. With the old quoted form both shell tests fail.

Checks

Frozen files untouched; fingerprint 15846a0915769d4a. Ruff clean. Full suite: the three known local-only failures. README count 1870 to 1881.

On the dogfood machine

Verified end to end on the dogfood machine. A Codex CLI run and a ChatGPT desktop conversation both delivered session, approval, tool-call and stop events, the first Codex tool events since July.

Why not commandWindows (second commit)

The first commit wrote Codex's commandWindows override, and Codex then ran no hook at all. Codex's review dialog hashes a hook without commandWindows and its runtime hashes it with it, so every approval is stored against a hash the runtime never computes: hooks/list reports the hooks as modified, and they are skipped silently. Measured on Codex 0.163 with a throwaway CODEX_HOME: the same stored approvals read trusted once the override is removed.

🤖 Generated with Claude Code

The Codex installer wrote `"<python.exe>" "<agentmetry_ingest.py>" codex hook
<Event>`. Codex reported every hook run as completed and nothing reached
ingest: under cmd /c the leading quoted token breaks cmd's quote stripping,
under PowerShell a command starting with a quoted string is a string, and
both exit 1 before Python starts. The dogfood machine's last Codex event was
in July. (#307)

Codex accepts a `commandWindows` override but does not say which shell it
uses, so the installer now writes one that runs under cmd, PowerShell and
direct execution: quotes removed, a path with a space replaced by its 8.3
short name, a path with no short name left quoted rather than broken. Tests
launch the generated command through cmd and PowerShell, including a path
with a space, and fail with the old form.

docs/agent-coverage.md and the changelog also record that Codex applies hook
approval to new conversations only (#300). README count 1870 -> 1881.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dows`

The first commit on this branch put the unquoted Windows form in Codex's
`commandWindows` override. On the dogfood machine Codex then ran no hook at
all, approved or not, and said nothing. Its review dialog hashes a hook without
`commandWindows`; its runtime hashes it with it. Every approval was stored
against a hash the runtime never computes, so `hooks/list` reported all five
hooks as `modified` and Codex skipped them.

Measured on Codex 0.163 (the ChatGPT desktop app's engine) with a throwaway
CODEX_HOME: the same stored approvals read `trusted` once the override is
removed. With the unquoted form in `command` and one approval, a Codex CLI run
and a ChatGPT desktop conversation both delivered session, approval, tool-call
and stop events, the first Codex tool events since July.

The installer now writes the unquoted form into `command` on Windows and never
writes `commandWindows`; a reinstall drops one left by the earlier version.
Three of the four new tests fail against the previous behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
blitzcrieg1 and others added 3 commits October 22, 2026 21:29
Merging master into this branch left two "### Fixed" headings in the same
release. The entries are unchanged; the second heading is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ook-command

# Conflicts:
#	CHANGELOG.md
#	README.md
@blitzcrieg1
blitzcrieg1 merged commit b171c55 into master Oct 22, 2026
11 checks passed
@blitzcrieg1
blitzcrieg1 deleted the fix/codex-windows-hook-command branch October 22, 2026 19:07
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex hooks never launch on Windows: the quoted command fails under cmd and PowerShell

1 participant