Skip to content

bug(codex): 在 powershell 中使用 hapi codex 无法成功运行 codex cli #762

@xuansheep

Description

@xuansheep

What version of HAPI is running?

hapi version: 0.18.4

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64

What issue are you seeing?

powershell 启动错误截图:
Image

Starting HAPI hub in background... HAPI hub started The system cannot find the file specified. [codex-local]: Local Codex process failed: Process exited with code: 1 Failed to execute: "D:\\software\\nvm\\v22.22.2\\node_modules\\@twsxtd\\hapi\\node_modules\\@twsxtd\\hapi-win32-x64\\bin\\hapi.exe" "codex" Binary exited with status 1. Command failed: D:\software\nvm\v22.22.2\node_modules\@twsxtd\hapi\node_modules\@twsxtd\hapi-win32-x64\bin\hapi.exe codex

.hapi/logs 详细日志:
[10:52:24.595] Starting hapi CLI with args: ["bun","B:/~BUN/root/hapi.exe","codex"] [10:52:25.100] [AUTO-START] Starting hub automatically... [10:52:25.102] [SPAWN HAPI CLI] Spawning: hapi hub in D:\****\hapi [10:52:25.110] [AUTO-START] Hub process spawned with PID 14316 [10:52:25.759] [AUTO-START] Server ready after 647ms [10:52:25.764] [codex] Starting with options: startedBy=terminal [10:52:25.766] Using machineId: 2e446020-****-****-baf2-6fcfcb971c79 [10:52:25.876] [WORKTREE] Git probe miss in 93ms [10:52:25.887] [START] Reporting session 5eb9a260-3575-444c-867b-12618f777c14 to runner [10:52:25.890] [CONTROL CLIENT] Runner is not running, file is stale [10:52:25.891] [START] Failed to report to runner (may not be running): Runner is not running, file is stale [10:52:25.893] [MessageQueue2] Initialized [10:52:25.894] [Codex] Synced session config for keepalive: permissionMode=default, model=auto, modelReasoningEffort=default, collaborationMode=default [10:52:25.895] [codex-loop] Iteration with mode: local [10:52:25.911] Socket connected successfully [10:52:25.913] [codex-local]: Started hapi MCP bridge server at http://127.0.0.1:64734/ [10:52:25.922] [hookServer] Started on port 64735 [10:52:25.923] [codex-local]: Started Codex SessionStart hook server on port 64735 [10:52:25.925] [codex-local]: launch [10:52:25.927] [CodexLocal] Spawning codex with args: ["-c","mcp_servers.hapi.command=\"D:\\\\software\\\\nvm\\\\v22.22.2\\\\node_modules\\\\@twsxtd\\\\hapi\\\\node_modules\\\\@twsxtd\\\\hapi-win32-x64\\\\bin\\\\hapi.exe\"","-c","mcp_servers.hapi.args=['mcp','--url','http://127.0.0.1:64734/']","-c","hooks.SessionStart=[{ hooks = [{ type = \"command\", command = \"\\\"D:\\\\\\\\software\\\\\\\\nvm\\\\\\\\v22.22.2\\\\\\\\node_modules\\\\\\\\@twsxtd\\\\\\\\hapi\\\\\\\\node_modules\\\\\\\\@twsxtd\\\\\\\\hapi-win32-x64\\\\\\\\bin\\\\\\\\hapi.exe\\\" hook-forwarder --port 64735 --token 802ce**********2d2373\" }] }]","-c","hooks.state={\"C:\\\\<session-flags>\\\\config.toml:session_start:0:0\"={trusted_hash=\"sha256:3515************\"}}","-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.\""] [10:52:25.964] [CodexLocal] Child exited (code=1, signal=null, aborted=false) [10:52:25.966] [codex-local]: launch error {} [10:52:25.968] [WARN] [codex-local]: Local Codex process failed: Process exited with code: 1 [10:52:25.970] [hookServer] Stopped [10:52:25.971] [hapiMCP] Stopping server [10:52:25.972] [codex-local]: SessionStart hook did not provide transcript path before shutdown [10:52:25.973] [codex-local]: Stopped hapi MCP bridge server [10:52:25.974] [codex] Cleanup start [10:52:25.985] [API] Socket disconnected: io client disconnect [10:52:25.986] [codex] Cleanup complete

What steps can reproduce the bug?

hapi codex 在 Windows 上通过 PATH 启动 codex,实际命中的是 npm 生成的 codex.cmd。该 shim 使用 %* 转发参数,会破坏包含空格和 --port 的 -c hooks.SessionStart=... 参数,导致 Codex 把 hook command 里的 --port 当成自身顶层参
数并退出 code 1

相关代码:
codexLocal.ts
await spawnWithTerminalGuard({ command: 'codex', args, cwd: opts.path, env: process.env, signal: opts.abort, logLabel: 'CodexLocal', spawnName: 'codex', installHint: 'Codex CLI', includeCause: true, logExit: true });

What is the expected behavior?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions