Windows: hapi codex fails when npm Codex CLI shim is first on PATH
Summary
On Windows, hapi codex fails when Codex CLI is installed globally via npm and the first codex entries on PATH are npm-generated shims:
<USER_HOME>\AppData\Roaming\npm\codex
<USER_HOME>\AppData\Roaming\npm\codex.cmd
The same setup works if the native Codex binary from the npm package is prepended to PATH.
Environment
- OS: Windows x64
- Shell: PowerShell 7.6.1
- hapi: 0.17.4
- Codex CLI: 0.130.0
- Codex install method:
npm install -g @openai/codex@latest
Reproduction
npm install -g @openai/codex@latest
where.exe codex
codex --version
hapi codex
where.exe codex returns:
<USER_HOME>\AppData\Roaming\npm\codex
<USER_HOME>\AppData\Roaming\npm\codex.cmd
codex --version works:
But hapi codex fails:
The system cannot find the file specified.
[codex-local]: Local Codex process failed: Process exited with code: 1
Failed to execute: "<USER_HOME>\AppData\Roaming\npm\node_modules\@twsxtd\hapi\node_modules\@twsxtd\hapi-win32-x64\bin\hapi.exe" "codex"
Binary exited with status 1.
Workaround
Prepending the native Codex binary directory from the npm package to PATH makes hapi codex start successfully:
$codexExeDir = "$env:APPDATA\npm\node_modules\@openai\codex\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\codex"
$codexPathDir = "$env:APPDATA\npm\node_modules\@openai\codex\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\path"
$env:Path = "$codexExeDir;$codexPathDir;$env:Path"
where.exe codex
hapi codex
Then where.exe codex starts with:
<USER_HOME>\AppData\Roaming\npm\node_modules\@openai\codex\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\codex\codex.exe
Suspected Cause
hapi codex appears to spawn codex by name. On Windows, when npm shims are first on PATH, this can resolve to the extensionless npm shim or codex.cmd rather than the native codex.exe.
This seems to break the local Codex launch path used by hapi, especially because hapi passes complex -c config values for MCP and session hooks.
A possible fix could be to prefer a native codex.exe on Windows when available, or provide an environment variable/config option to override the Codex binary path used by hapi.
Windows:
hapi codexfails when npm Codex CLI shim is first on PATHSummary
On Windows,
hapi codexfails when Codex CLI is installed globally via npm and the firstcodexentries onPATHare npm-generated shims:The same setup works if the native Codex binary from the npm package is prepended to
PATH.Environment
npm install -g @openai/codex@latestReproduction
where.exe codexreturns:codex --versionworks:But
hapi codexfails:Workaround
Prepending the native Codex binary directory from the npm package to
PATHmakeshapi codexstart successfully:Then
where.exe codexstarts with:Suspected Cause
hapi codexappears to spawncodexby name. On Windows, when npm shims are first onPATH, this can resolve to the extensionless npm shim orcodex.cmdrather than the nativecodex.exe.This seems to break the local Codex launch path used by hapi, especially because hapi passes complex
-cconfig values for MCP and session hooks.A possible fix could be to prefer a native
codex.exeon Windows when available, or provide an environment variable/config option to override the Codex binary path used by hapi.