You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Codex plugin: Windows hooks fail when the session shell is PowerShell (commandWindows uses cmd syntax) #4239
On Windows, Codex CLI (0.156.x) runs a hook's commandWindows through the session shell rather
than cmd.exe: codex-rs/core/src/session/mod.rs hands the turn environment's shell to the hook
runtime, and codex-rs/hooks/src/engine/command_runner.rs (build_command) then runs pwsh -NoProfile -Command "<commandWindows>". %COMSPEC% /C is only the fallback when no session
shell is known, and PowerShell is the usual session shell on Windows.
The hooks in plugins/worktrunk/.codex-plugin/plugin.json (current main, after #4008) look like
"${PLUGIN_ROOT}\hooks\wt.cmd" config state marker set 💬 || exit /b 0
which PowerShell cannot parse (a quoted string followed by bare arguments; exit /b is cmd-only).
So every UserPromptSubmit / PermissionRequest / Stop / SessionEnd hook fails before wt.cmd starts: codex exec prints hook: UserPromptSubmit Failed / hook: Stop Failed, and the activity markers
never change.
Repro (same in PowerShell 7 and Windows PowerShell 5.1):
pwsh -NoProfile -Command '"C:\Users\<user>\.codex\plugins\cache\worktrunk\worktrunk\local\hooks\wt.cmd" config state marker set 💬 || exit /b 0'
# ParserError: Unexpected token 'config' in expression or statement.
The same line works under cmd /C. Since Codex can use either shell, commandWindows has to parse
in both. For example, an unquoted ${PLUGIN_ROOT}\hooks\wt.cmd --version runs (exit 0) under both pwsh -NoProfile -Command and cmd /C when the path has no spaces; the || exit /b 0 fallback
would need a shell-neutral replacement.
Seen with worktrunk v0.77.0 and Codex CLI 0.156.0 on Windows 11. Related: #4007 / #4008.
Fixed in #4241, which is green on CI and now needs maintainer review before it lands.
Your reading of the Codex source holds up — I traced the same path: build_hooks_config fills HooksConfig::shell_program/shell_args from the turn environment's shell, Shell::derive_exec_args yields -NoProfile -Command for ShellType::PowerShell, and build_command only takes the %COMSPEC% /C shape when no session shell is known. The report saved a lot of digging.
Each commandWindows now leads with cmd /d /c call and carries no cmd-only control flow:
cmd /d /c call "${PLUGIN_ROOT}\hooks\wt.cmd" config state marker set 🤖
A leading bareword puts PowerShell in command mode, so the quoted path is an argument rather than the expression it was choking on. call does a second job: cmd's own /C quote-stripping fires only when the command line starts with a quote, so leading with call keeps the quotes on a path with a space in it. That is why the unquoted ${PLUGIN_ROOT}\hooks\wt.cmd you floated isn't the route taken — $CODEX_HOME sits under the user profile, so C:\Users\First Last\.codex\... is the ordinary case, not the exception. The || exit /b 0 best-effort tail moves into hooks/wt.cmd, which now always exits 0; no spelling of || true parses in both shells, and a parse error loses the whole line including the marker.
The regression test runs the shipped commands the way build_command spawns them, under cmd.exe, powershell.exe, and pwsh, from a plugin root with a space in it, checking each event lands its marker and exits 0. The two PowerShell legs fail at the parse before the change.
If you have a Codex 0.156 session handy, confirmation from a real one would be worth having: the PR is verified by CI and by source reading, not by an installed Codex on Windows.
Activity
worktrunk-bot commentedon Sep 23, 2026
Fixed in #4241, which is green on CI and now needs maintainer review before it lands.
Your reading of the Codex source holds up — I traced the same path:
build_hooks_configfillsHooksConfig::shell_program/shell_argsfrom the turn environment's shell,Shell::derive_exec_argsyields-NoProfile -CommandforShellType::PowerShell, andbuild_commandonly takes the%COMSPEC% /Cshape when no session shell is known. The report saved a lot of digging.Each
commandWindowsnow leads withcmd /d /c calland carries no cmd-only control flow:A leading bareword puts PowerShell in command mode, so the quoted path is an argument rather than the expression it was choking on.
calldoes a second job: cmd's own/Cquote-stripping fires only when the command line starts with a quote, so leading withcallkeeps the quotes on a path with a space in it. That is why the unquoted${PLUGIN_ROOT}\hooks\wt.cmdyou floated isn't the route taken —$CODEX_HOMEsits under the user profile, soC:\Users\First Last\.codex\...is the ordinary case, not the exception. The|| exit /b 0best-effort tail moves intohooks/wt.cmd, which now always exits 0; no spelling of|| trueparses in both shells, and a parse error loses the whole line including the marker.The regression test runs the shipped commands the way
build_commandspawns them, undercmd.exe,powershell.exe, andpwsh, from a plugin root with a space in it, checking each event lands its marker and exits 0. The two PowerShell legs fail at the parse before the change.If you have a Codex 0.156 session handy, confirmation from a real one would be worth having: the PR is verified by CI and by source reading, not by an installed Codex on Windows.
fix(plugin): make the Codex Windows hook commands parse in PowerShell (…