feat(windows): native Codex hook transport (queue + out-of-sandbox dispatcher)#305
Open
So-Mu3 wants to merge 1 commit into
Open
feat(windows): native Codex hook transport (queue + out-of-sandbox dispatcher)#305So-Mu3 wants to merge 1 commit into
So-Mu3 wants to merge 1 commit into
Conversation
Route Codex SessionStart and SessionEnd hooks through a native PowerShell queue so sandboxed sessions do not launch Git Bash directly. Inside the Codex Windows sandbox, msys/cygwin binaries die at startup (CreateFileMapping Win32 error 5), so the legacy windows_wrap() commandWindows always fails with "hook exited with code 1". The hook now runs scripts/windows/hook-enqueue.ps1 (pure PowerShell, fail-open, always exit 0), which atomically writes a request file to run/hook-queue (or the project's .agmsg/hook-queue fallback). An out-of-sandbox dispatcher (hook-dispatcher.ps1, single instance, registered as a logon task via install-hook-dispatcher.ps1 -Register) replays the request through Git Bash where it works. Selection is manifest-driven (hook_windows_transport=queue, codex only); types without the key keep the legacy Git Bash wrapper. Stop/turn hooks are unchanged (they need synchronous stdout). Verified end-to-end on Windows 11 with Codex 0.142.5: SessionStart Completed, request consumed, session-start.sh exit 0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Inside the Codex Windows sandbox, msys/cygwin binaries die at startup with
fatal error - CreateFileMapping ... Win32 error 5. ThecommandWindowsgenerated bywindows_wrap()launches Git Bash inside that sandbox, so the codex SessionStart/SessionEnd hooks always fail withhook exited with code 1— regardless of bash path or wrapper tweaks, since any msys child stays inside the sandbox boundary.Design
Generalizes the existing
AGMSG_CODEX_BRIDGE_LAUNCHERrequest-file pattern (#41) to the whole hook transport:scripts/windows/hook-enqueue.ps1— pure PowerShell, no external processes, always exits 0 (fail-open; a broken delivery must never fail the session). Atomically writes one request file (header + hook stdin JSON) torun/hook-queue/, falling back to the project's.agmsg/hook-queue/.scripts/windows/hook-dispatcher.ps1— single instance (pidfile), polls the queue dirs (1s), replays each request through Git Bash (session-start.sh/session-end.sh, stored stdin piped through), logs torun/hook-dispatcher.log(1MB truncate).install-hook-dispatcher.ps1 -Register|-Unregister|-Statusmanages a logon scheduled task.hook_windows_transport=queue(codex only). Types without the key keep the legacywindows_wrap()behavior — claude-code is untouched. Stop/turn hooks are out of scope (they need synchronous stdout, which a queue cannot provide).run/hook-projects.list(on_enable/on_disable) so the dispatcher knows which projects' fallback queues to watch.Verification
bats tests/test_delivery.bats: 125/125 pass (3 new tests: queue commandWindows generation, legacy fallback regression, project-list add/remove/dedup).codex execshowshook: SessionStart Completed, request enqueued in-sandbox and consumed by the dispatcher,session-start.shexit 0. Before the change the same environment reproducibly failed.Notes
[ScriptBlock]::Createsyntax checks; dispatcher registration requires the user to runinstall-hook-dispatcher.ps1 -Registeronce (documented indocs/codex-monitor-beta.md).🤖 Generated with Claude Code