Skip to content

[bug]: Codex provider fails when npm global codex.cmd is under Program Files #1927

@habitssss

Description

@habitssss

Bug Description

On Windows, the Codex provider fails to start when the npm global codex.cmd shim is installed under %ProgramFiles%\nodejs.

The same Codex CLI works from the terminal, so this appears related to how Emdash launches Windows .cmd shims through its PTY layer.

Steps to Reproduce

  1. Install Node.js on Windows so npm global shims are under %ProgramFiles%\nodejs.
  2. Install Codex with npm install -g @openai/codex.
  3. Confirm codex --version works in a terminal.
  4. Open Emdash and start a Codex conversation.
  5. Observe that Codex fails to start.

Actual vs Expected Behavior

Actual: Emdash fails to launch Codex and the terminal shows:

'"C:\Program Files\nodejs\codex.CMD"' is not recognized as an internal or external command,
operable program or batch file.

On a Chinese Windows locale, this appears as:

'"C:\Program Files\nodejs\codex.CMD"' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

Expected: Emdash should start the Codex provider successfully when codex.cmd is installed in the normal Node.js global install location on Windows.

emdash Version

1.1.10

Operating System

Windows

Additional Context

Environment:

  • Emdash install path: %LOCALAPPDATA%\Programs\Emdash
  • Node/npm global prefix: %ProgramFiles%\nodejs
  • Codex CLI path:
    • %ProgramFiles%\nodejs\codex
    • %ProgramFiles%\nodejs\codex.cmd
    • %ProgramFiles%\nodejs\codex.ps1
  • Codex version: codex-cli 0.129.0

These commands work successfully from the terminal:

where.exe codex

Output:

C:\Program Files\nodejs\codex
C:\Program Files\nodejs\codex.cmd
cmd.exe /d /s /c '"C:\Program Files\nodejs\codex.CMD" --version'

Output:

codex-cli 0.129.0

Directly starting the .cmd shim through node-pty also works:

const pty = require("node-pty");

const p = pty.spawn(
  "C:\\Program Files\\nodejs\\codex.cmd",
  ["--version"],
  {
    cwd: process.cwd(),
    cols: 80,
    rows: 24,
    env: process.env,
  }
);

p.onData((d) => process.stdout.write(d));
p.onExit((e) => console.log("EXIT", e));

Output:

codex-cli 0.129.0
EXIT { exitCode: 0 }

However, launching via cmd.exe through node-pty fails:

const pty = require("node-pty");

const p = pty.spawn(
  "C:\\Windows\\System32\\cmd.exe",
  ["/d", "/s", "/c", "\"C:\\Program Files\\nodejs\\codex.CMD\" --version"],
  {
    cwd: process.cwd(),
    cols: 80,
    rows: 24,
    env: process.env,
  }
);

p.onData((d) => process.stdout.write(d));
p.onExit((e) => console.log("EXIT", e));

Observed output:

The syntax of the command is incorrect.
EXIT { exitCode: 1 }

The issue may be in the Windows .cmd / .bat handling path around:

src/main/core/pty/pty-spawn-platform.ts

Current behavior appears to resolve extensionless codex to a .CMD file and then wrap it with:

cmd.exe /d /s /c "<resolved codex.CMD>" ...

This seems fragile when the resolved command path is under Program Files.

Possible fix directions:

  • Avoid wrapping Windows .cmd / .bat shims through cmd.exe /s /c when node-pty can launch the .cmd file directly.
  • Or change the wrapper form to something like cmd.exe /d /c call "C:\Program Files\nodejs\codex.CMD" ....
  • Add a regression test for a provider command resolved to C:\Program Files\nodejs\codex.CMD.

Workaround:

"C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\@openai\codex\bin\codex.js"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions