fix(cli): Fix Codex CLI execution issue in PowerShell with Hapi Codex#763
Merged
Merged
Conversation
…ly when using hapi codex in powershell
There was a problem hiding this comment.
Findings
- [Major] 直接启动原生
codex.exe会绕过 Codex launcher 的运行环境设置,证据cli/src/codex/utils/codexExecutable.ts:73。当前 resolver 对 npm shim 优先返回 native exe,但@openai/codex/bin/codex.jslauncher 会在启动 native binary 前补充 bundledvendor/.../codex-path到PATH,并设置CODEX_MANAGED_PACKAGE_ROOT/包管理器标记;绕过它后,Windows 用户可能能启动 Codex,但在依赖 bundledrg.exe或资源路径时出现回归。
Suggested fix:function resolveWindowsCandidate(candidate: string): CodexCommand | null { if (!existsSync(candidate)) { return null; } if (windowsPath.extname(candidate).toLowerCase() === '.exe') { return { command: candidate, args: [] }; } const script = resolveShimScript(candidate); if (script) { return { command: 'node', args: [script] }; } return null; }
Summary
- Review mode: initial
- 发现 1 个 Major 问题:Windows shim 路径绕过 Codex 官方 JS launcher,丢失其运行环境设置。建议对 shim 使用
node codex.js ...args,仍可避免.cmd/PowerShell 参数转义问题,同时保留 Codex 自己的 PATH/resource 初始化。
Testing
- Not run (automation; 当前 runner 中
bun不可用:bun: command not found)
HAPI Bot
|
|
||
| const nativeExecutable = resolveNativePackageExecutable(candidate); | ||
| if (nativeExecutable) { | ||
| return { command: nativeExecutable, args: [] }; |
There was a problem hiding this comment.
[Major] 这里把 npm shim 解析成原生 codex.exe 后,codexLocal 会直接用当前 process.env 启动它。这样绕过了 @openai/codex/bin/codex.js launcher;该 launcher 会把 bundled vendor/.../codex-path 加进 PATH,并设置 CODEX_MANAGED_PACKAGE_ROOT/包管理器标记。缺少这层环境后,Windows 用户可能能启动 Codex,但在依赖 bundled rg.exe 或资源路径时出现回归。
Suggested fix:
function resolveWindowsCandidate(candidate: string): CodexCommand | null {
if (!existsSync(candidate)) {
return null;
}
if (windowsPath.extname(candidate).toLowerCase() === '.exe') {
return { command: candidate, args: [] };
}
const script = resolveShimScript(candidate);
if (script) {
return { command: 'node', args: [script] };
}
return null;
}There was a problem hiding this comment.
Findings
- None.
Summary
- Review mode: follow-up after new commits
- No blocking issues found in the updated diff. The prior launcher-bypass finding was addressed by resolving Windows npm shims to
node codex.js, and the same resolved command is now used for the version check and local launch path. - Residual risk: Windows behavior was reviewed from source/tests only; this runner cannot execute the targeted Bun/Vitest suite.
Testing
- Not run (automation;
bunis not installed in this runner:/bin/bash: bun: command not found)
HAPI Bot
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.
关联Issue: #762
本次提交代码使用 codex cli + gpt5.5 xhigh(plan)与high(implement)生成
改动摘要:
本地运行结果:

启动日志:
[11:38:28.890] Starting hapi CLI with args: ["bun","B:/~BUN/root/hapi.exe","codex"]
[11:38:29.444] [AUTO-START] Starting hub automatically...
[11:38:29.446] [SPAWN HAPI CLI] Spawning: hapi hub in D:*\hapi
[11:38:29.455] [AUTO-START] Hub process spawned with PID 35696
[11:38:30.296] [AUTO-START] Server ready after 840ms
[11:38:30.304] [codex] Starting with options: startedBy=terminal
[11:38:30.306] Using machineId: 2e446020----6fcfcb971c79
[11:38:30.449] [WORKTREE] Git probe miss in 123ms
[11:38:30.461] [START] Reporting session 08b621fa---***a8fcfd0561d1 to runner
[11:38:30.465] [CONTROL CLIENT] Runner is not running, file is stale
[11:38:30.466] [START] Failed to report to runner (may not be running): Runner is not running, file is stale
[11:38:30.467] [MessageQueue2] Initialized
[11:38:30.470] [Codex] Synced session config for keepalive: permissionMode=default, model=auto, modelReasoningEffort=default, collaborationMode=default
[11:38:30.471] [codex-loop] Iteration with mode: local
[11:38:30.487] Socket connected successfully
[11:38:30.508] [codex-local]: Started hapi MCP bridge server at http://127.0.0.1:59083/
[11:38:30.539] [hookServer] Started on port 59084
[11:38:30.540] [codex-local]: Started Codex SessionStart hook server on port 59084
[11:38:30.542] [codex-local]: launch
[11:38:30.544] [CodexLocal] Spawning codex with args: ["-c","mcp_servers.hapi.command="D:\\work\\code\\nodeJs\\hapi\\cli\\dist-exe\\bun-windows-x64\\hapi.exe"","-c","mcp_servers.hapi.args=['mcp','--url','http://127.0.0.1:59083/']","-c","hooks.SessionStart=[{ hooks = [{ type = "command", command = "\"D:\\\\work\\\\code\\\\nodeJs\\\\hapi\\\\cli\\\\dist-exe\\\\bun-windows-x64\\\\hapi.exe\" hook-forwarder --port 59084 --token 08d957975f31a374" }] }]","-c","hooks.state={"C:\\\\config.toml:session_start:0:0"={trusted_hash="sha256:f4255c02"}}","-c","developer_instructions="ALWAYS when you start a new chat, call the title tool to set a concise task title.\nPrefer calling functions.hapi__change_title.\nIf that exact tool name is unavailable, call an equivalent alias such as hapi__change_title, mcp__hapi__change_title, or hapi_change_title.\nIf the task focus changes significantly later, call the title tool again with a better title.\nWhen you create or find a local image file that the user should see, call functions.hapi__display_image with the image path. If that exact tool name is unavailable, use an equivalent alias such as hapi__display_image, mcp__hapi__display_image, or hapi_display_image.""]
可以成功运行codex cli