openclaw - 💡(How to fix) Fix Windows: spawn codex ENOENT - codex/* models unusable due to raw spawn() not resolving PATHEXT [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70913Fetched 2026-04-24 10:37:56
View on GitHub
Comments
2
Participants
2
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
commented ×2closed ×1

On Windows, the gateway fails to spawn the codex CLI when using a codex/* model (e.g. codex/gpt-5.5). Every request errors with spawn codex ENOENT and falls back to another model, even though codex is installed globally via npm i -g @openai/codex and is resolvable from the same shell that started PM2.

Root cause appears to be child_process.spawn('codex', …) without shell: true on Windows. Node on Windows only resolves .exe via raw spawn; npm global bins ship as codex (shell script), codex.cmd, and codex.ps1, so raw spawn('codex') can never find an executable and throws ENOENT.

Error Message

[diagnostic] lane task error: lane=main durationMs=14633 error="Error: spawn codex ENOENT" [diagnostic] lane task error: lane=session:agent:main:explicit:<sid> durationMs=14638 error="Error: spawn codex ENOENT" [model-fallback/decision] decision=candidate_failed requested=codex/gpt-5.5 candidate=codex/gpt-5.5 reason=unknown next=github-copilot/gpt-5.4 detail=spawn codex ENOENT

Root Cause

Root cause appears to be child_process.spawn('codex', …) without shell: true on Windows. Node on Windows only resolves .exe via raw spawn; npm global bins ship as codex (shell script), codex.cmd, and codex.ps1, so raw spawn('codex') can never find an executable and throws ENOENT.

Fix Action

Workaround

None that doesn't involve shimming a codex.exe onto PATH or running the gateway under WSL.

Code Example

openclaw agent --session-id t1 --message "reply: hi" --thinking off --json

---

[diagnostic] lane task error: lane=main durationMs=14633 error="Error: spawn codex ENOENT"
[diagnostic] lane task error: lane=session:agent:main:explicit:<sid> durationMs=14638 error="Error: spawn codex ENOENT"
[model-fallback/decision] decision=candidate_failed requested=codex/gpt-5.5 candidate=codex/gpt-5.5 reason=unknown next=github-copilot/gpt-5.4 detail=spawn codex ENOENT

---

[plugins] embedded acpx runtime backend probe failed: embedded ACP runtime probe failed
  (agent=codex; command='C:\Users\<user>\.openclaw\acpx\codex-acp-wrapper.mjs';
   cwd=...; spawn EFTYPE)

---

const bin = process.platform === 'win32'
     ? (which.sync('codex.cmd', { nothrow: true }) || which.sync('codex', { nothrow: true }))
     : 'codex';
   spawn(bin, args);
RAW_BUFFERClick to expand / collapse

Summary

On Windows, the gateway fails to spawn the codex CLI when using a codex/* model (e.g. codex/gpt-5.5). Every request errors with spawn codex ENOENT and falls back to another model, even though codex is installed globally via npm i -g @openai/codex and is resolvable from the same shell that started PM2.

Root cause appears to be child_process.spawn('codex', …) without shell: true on Windows. Node on Windows only resolves .exe via raw spawn; npm global bins ship as codex (shell script), codex.cmd, and codex.ps1, so raw spawn('codex') can never find an executable and throws ENOENT.

Environment

  • OS: Windows 11
  • OpenClaw: 2026.4.22 (00bd2cf)
  • Node: via nvm / system (npm global prefix: C:\Users\<user>\AppData\Roaming\npm)
  • @openai/codex: 0.124.0 (installed globally)
  • where.exe codexcodex, codex.cmd, codex.ps1 present in %APPDATA%\npm (no .exe)
  • codex --version works from PowerShell: codex-cli 0.124.0
  • PM2: launched via pm2 start ecosystem.gateway.json from PowerShell where codex is on PATH

Repro

  1. Windows + PowerShell, npm i -g @openai/codex, confirm Get-Command codex resolves to codex.ps1 / codex.cmd.
  2. openclaw config set agents.defaults.model.primary codex/gpt-5.5
  3. pm2 kill; pm2 start ecosystem.gateway.json (so child inherits fresh PATH).
  4. Gateway boots clean: [gateway] agent model: codex/gpt-5.5.
  5. Send any request:
    openclaw agent --session-id t1 --message "reply: hi" --thinking off --json
  6. Request falls back to github-copilot/gpt-5.4; gateway error log shows:
[diagnostic] lane task error: lane=main durationMs=14633 error="Error: spawn codex ENOENT"
[diagnostic] lane task error: lane=session:agent:main:explicit:<sid> durationMs=14638 error="Error: spawn codex ENOENT"
[model-fallback/decision] decision=candidate_failed requested=codex/gpt-5.5 candidate=codex/gpt-5.5 reason=unknown next=github-copilot/gpt-5.4 detail=spawn codex ENOENT

Related (embedded ACP probe path, same underlying issue):

[plugins] embedded acpx runtime backend probe failed: embedded ACP runtime probe failed
  (agent=codex; command='C:\Users\<user>\.openclaw\acpx\codex-acp-wrapper.mjs';
   cwd=...; spawn EFTYPE)

Expected

On Windows, spawning codex should resolve codex.cmd via PATHEXT (same way where codex does), so codex/* models work out of the box after npm i -g @openai/codex.

Suggested fix

In the Codex harness / acpx wrapper spawn sites, one of:

  1. Pass shell: true to child_process.spawn on Windows (simplest, but has quoting caveats).
  2. Use cross-spawn (respects PATHEXT, no shell, safest for arg escaping).
  3. Manually resolve the binary using PATHEXT before spawning:
    const bin = process.platform === 'win32'
      ? (which.sync('codex.cmd', { nothrow: true }) || which.sync('codex', { nothrow: true }))
      : 'codex';
    spawn(bin, args);

Option 2 (cross-spawn) is the usual answer here and also fixes the spawn EFTYPE seen on the .mjs wrapper path (that one likely needs node <wrapper>.mjs instead of invoking the .mjs directly on Windows).

Workaround

None that doesn't involve shimming a codex.exe onto PATH or running the gateway under WSL.

Impact

All codex/* models (gpt-5.5, gpt-5.4-pro, gpt-5.4, gpt-5.3-codex-spark, gpt-5.2-codex) are unusable as primary or successful-fallback on Windows unless the user manually creates a .exe shim. Requests appear to "work" only because fallback silently routes to github-copilot models.

extent analysis

TL;DR

The most likely fix is to use cross-spawn or pass shell: true to child_process.spawn on Windows to resolve the codex binary correctly.

Guidance

  • The issue is caused by Node on Windows not resolving .exe via raw spawn, and codex being installed as a shell script, codex.cmd, and codex.ps1.
  • To fix this, consider using cross-spawn which respects PATHEXT and handles argument escaping safely.
  • Alternatively, manually resolve the binary using PATHEXT before spawning, as shown in the suggested fix.
  • Verify the fix by checking if codex/* models work as expected after applying the changes.

Example

const spawn = require('cross-spawn');
// or
const { spawn } = require('child_process');
const bin = process.platform === 'win32'
  ? (which.sync('codex.cmd', { nothrow: true }) || which.sync('codex', { nothrow: true }))
  : 'codex';
spawn(bin, args);

Notes

The suggested fix assumes that cross-spawn is available, and the manual resolution approach may have quoting caveats. The issue only affects Windows and codex/* models.

Recommendation

Apply the suggested fix using cross-spawn to ensure safe argument escaping and correct binary resolution on Windows.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING