fix: resolve ENOENT for .cmd shims on Windows#13
Merged
dkundel-openai merged 1 commit intoopenai:mainfrom Mar 31, 2026
Merged
Conversation
On Windows, Node.js `spawnSync` without `shell: true` uses
`CreateProcess`, which only resolves `.exe` files. npm installs global
tools (like `codex`) as `.cmd` shims, so `spawnSync("codex", ...)`
returns ENOENT even when codex is correctly installed and on PATH.
Adding `shell: process.platform === "win32"` routes through `cmd.exe`
on Windows, which properly resolves `.cmd`, `.bat`, and PATHEXT entries.
No behavior change on macOS/Linux since the condition evaluates to false.
Collaborator
|
@codex review |
dkundel-openai
approved these changes
Mar 31, 2026
This was referenced Mar 31, 2026
0xZOne
added a commit
to 0xZOne/codex-plugin-cc
that referenced
this pull request
Mar 31, 2026
…lity On Windows, `codex` is installed as an npm `.cmd` shim. Node's `child_process.spawn()` cannot resolve `.cmd` files without `shell: true`, causing `ENOENT` when `SpawnedCodexAppServerClient` tries to start `codex app-server`. This is the same class of bug fixed in openai#13 for `spawnSync` in `process.mjs`, but the async `spawn()` call in `app-server.mjs` was missed.
This was referenced Mar 31, 2026
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.
Summary
shell: process.platform === "win32"tospawnSyncinrunCommand(), fixing binary detection (codex,npm, etc.) on WindowsProblem
On Windows, npm installs global CLI tools as
.cmdshims (e.g.,codex.cmd). Node.jsspawnSync()withoutshell: truecallsCreateProcess, which only resolves.exefiles — it cannot find.cmdor.batfiles, even when they are onPATH.This causes
binaryAvailable("codex", ...)to return{ available: false, detail: "not found" }on Windows, even with a correctly installed and PATH-accessible Codex CLI. The same applies tonpmdetection.Before (on Windows)
After
Root cause
spawnSync("codex", ["--version"])→ WindowsCreateProcess→ searches forcodex.exeonly → ENOENT.Adding
shell: trueroutes throughcmd.exe, which resolves commands usingPATHEXT(.CMD,.BAT, etc.), matching how the Windows shell resolves commands.Why this is safe
process.platform === "win32"evaluates tofalseon macOS/Linux — zero behavior change on non-Windows platformsshell: trueis the standard Node.js pattern for cross-platform command resolution (used bycross-spawn,execa, and npm itself)terminateProcessTreealready works on Windows becausetaskkillis a native.exe, not a.cmdshim — so it is unaffected by this changeTest plan
/codex:setupreports all components as available after the fixfalse, no code path change)