Skip to content

[codex] Fix Codex Windows hook fallback#1555

Merged
peyton-alt merged 4 commits into
mainfrom
fix/codex-windows-hook-fallback
Jun 30, 2026
Merged

[codex] Fix Codex Windows hook fallback#1555
peyton-alt merged 4 commits into
mainfrom
fix/codex-windows-hook-fallback

Conversation

@peyton-alt

@peyton-alt peyton-alt commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

https://entire.io/gh/entireio/cli/trails/684

Summary

  • Add Windows-native guarded production hook wrappers that avoid sh -c while preserving the missing-entire PATH guard.
  • Switch Codex Windows fallback installs to those guarded cmd.exe wrappers when the existing shell wrapper probe fails.
  • Replace stale managed Codex hook commands during command-form migration instead of appending duplicate hooks.
  • Clean up branch artifacts: remove stale .gitignore conflict markers and delete stray t1.txt.

Why

A Windows user had Codex hooks fail with exit code 1 when hooks were enabled and entire was installed, because the long sh -c production hook wrapper was not usable in that environment. The targeted fallback keeps the normal wrapper behavior for unaffected installs, but uses a Windows-compatible guarded wrapper when the probe detects the shell wrapper path is broken.

Validation

  • mise run check
  • mise run lint
  • go test ./cmd/entire/cli/agent/... -count=1
  • git diff --check origin/main
  • entire review --profile codex-temp --base origin/main --agent codex returned approve - no actionable defects found.

Note

Medium Risk
Changes how production hook commands are written and recognized on Windows; mis-detection could break Codex hooks or leave duplicate/stale entries, though scope is limited to Codex install paths and shared wrapper helpers with tests.

Overview
Fixes Codex production hook installs on Windows where long sh -c wrappers fail in native shells, while keeping the existing Unix-style wrappers when a runtime probe shows sh -c still works.

Adds cmd.exe / where.exe production wrappers in the shared agent hook helpers (silent exit and JSON/plain missing-entire warnings with CMD escaping), and extends IsManagedHookCommand so uninstall/managed-hook detection recognizes those Windows wrapper forms.

Codex InstallHooks picks Windows vs shell wrappers on Windows production installs based on the probe, and syncHookCommand replaces stale Entire hook entries when the desired command string changes instead of leaving duplicates.

Reviewed by Cursor Bugbot for commit c713d66. Configure here.

Copilot AI review requested due to automatic review settings June 29, 2026 12:36
@peyton-alt peyton-alt marked this pull request as ready for review June 29, 2026 12:38
@peyton-alt peyton-alt requested a review from a team as a code owner June 29, 2026 12:38

Copilot AI 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.

Pull request overview

This PR fixes Codex hook installation on Windows by introducing Windows-native production hook wrappers (avoiding sh -c), switching Codex to those wrappers when a compatibility probe indicates the shell wrapper path is broken, and ensuring hook installs replace stale managed commands instead of accumulating duplicates.

Changes:

  • Added cmd.exe/where.exe-guarded production hook wrappers (silent + JSON/plain warning) and extended managed-hook detection to recognize them.
  • Updated Codex hook installation to choose Windows wrappers on Windows when the compatibility probe fails, and to replace stale managed hook commands rather than appending duplicates.
  • Added/expanded tests around the new Windows wrappers, managed-hook detection, and Codex install migration behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
cmd/entire/cli/agent/hook_command.go Adds Windows-native production hook wrappers + managed-hook detection updates + CMD escaping helper.
cmd/entire/cli/agent/hook_command_test.go Adds unit tests for Windows wrappers and managed-hook detection.
cmd/entire/cli/agent/codex/hooks.go Adds Windows wrapper compatibility probing and hook-command sync (replace vs append) for Codex installs.
cmd/entire/cli/agent/codex/hooks_test.go Adds tests for Windows probe success/failure paths and migration behavior.

Comment thread cmd/entire/cli/agent/codex/hooks.go Outdated
Comment thread cmd/entire/cli/agent/hook_command.go
@peyton-alt peyton-alt force-pushed the fix/codex-windows-hook-fallback branch 2 times, most recently from 3a6e411 to 7bea261 Compare June 29, 2026 12:57
Entire-Checkpoint: 5ac1e71750f3
@peyton-alt peyton-alt force-pushed the fix/codex-windows-hook-fallback branch from ea96703 to a4d1ec9 Compare June 29, 2026 15:29
Entire-Checkpoint: 36599a4bbda6
@peyton-alt peyton-alt force-pushed the fix/codex-windows-hook-fallback branch from 0d4399b to db20ff4 Compare June 29, 2026 22:01
peyton-alt and others added 2 commits June 30, 2026 11:57
Addresses the trail #684 review findings on the Windows hook fallback.

- Restructure the cmd.exe wrappers from `where … || exit /b 0 & command`
  to `where … & if errorlevel 1 (…) else (command)`. The wrapped command
  now lives inside the else branch, so there is no unconditional trailing
  command and correctness no longer depends on `exit /b` aborting the whole
  `cmd /c` line from inside a parenthesized block. Present -> command runs
  and its exit code propagates; absent -> silent/warning branch, exit 0.
- Add an execution-level test that runs each wrapper through cmd.exe and
  asserts present-runs / present-propagates-exit / absent-skips-exit-0 /
  JSON-valid behavior (skips off-Windows).
- Lift the probe + OS gate + wrapper selection out of the codex package
  into the shared agent layer (UseWindowsProductionHooks,
  WrapProduction{Silent,JSONWarning}HookCommandForOS,
  SetWindowsHookProbeForTesting) so the other sh-based agents can adopt the
  Windows fallback without re-implementing it. codex/hooks.go is now a thin
  caller. Document why the probe is intentionally not memoized (re-probing
  is what drives self-correcting hook migration).
- Stop caret-escaping `%` in escapeWindowsCMD: these are cmd /c command
  lines, not batch scripts, so `^%` is wrong and a lone `%` is already
  literal. Document the distinction and update the test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@peyton-alt peyton-alt merged commit 495a38c into main Jun 30, 2026
9 checks passed
@peyton-alt peyton-alt deleted the fix/codex-windows-hook-fallback branch June 30, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants