Skip to content

Unable to locate Codex CLI binaries. Ensure @openai/codex is installed with optional dependencies. #16408

Closed as not planned

Description

@zy445566

What version of Codex CLI is running?

codex-cli 0.118.0

What subscription do you have?

enterprise

Which model were you using?

gpt-5.4

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64

What terminal emulator and version are you using (if applicable)?

VSCode

What issue are you seeing?

Unable to locate Codex CLI binaries. Ensure @openai/codex is installed with optional dependencies.

What steps can reproduce the bug?

the project which I use npx create-next-app@latest --all --yes to create

What is the expected behavior?

I debug the node_modules@openai\codex-sdk\dist\index.js

try {
    const codexPackageJsonPath = moduleRequire.resolve(`${CODEX_NPM_NAME}/package.json`);
    const codexRequire = createRequire(codexPackageJsonPath);
    const platformPackageJsonPath = codexRequire.resolve(`${platformPackage}/package.json`);
    vendorRoot = path2.join(path2.dirname(platformPackageJsonPath), "vendor");
  } catch(error) {
    console.log(error)
    throw new Error(
      `Unable to locate Codex CLI binaries. Ensure ${CODEX_NPM_NAME} is installed with optional dependencies.`
    );
  }

the real error shows

TypeError: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '[project]/Documents/mynextproject/node_modules/@openai/codex/package.json.[json].cjs [app-route] (ecmascript)'

Additional information

My temporary solution:

let codex;
if(platform==='win32') {
codex = new Codex({
    codexPathOverride: path.resolve(process.cwd(), "node_modules/@openai/codex-win32-x64/vendor/x86_64-pc-windows-msvc/codex/codex.exe)
  });
} else {
codex = new Codex({
    codexPathOverride: path.resolve(process.cwd(), "node_modules/@openai/codex/bin/codex.js")
  });
}

Activity

  1. added
    bug
    on Apr 1, 2026
  2. added
    CLI
    windows-os
    on Apr 1, 2026
  3. github-actions commented on Apr 1, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. etraut-openai commented on Apr 2, 2026

    @etraut-openai
    Contributor

    This doesn't look like a Codex bug, but rather a bug in your code that attempts to launch codex. If I'm misunderstanding the problem, let me know.

  5. zy445566 commented on Apr 3, 2026

    @zy445566
    Author

    This doesn't look like a Codex bug, but rather a bug in your code that attempts to launch codex. If I'm misunderstanding the problem, let me know.
    @etraut-openai

    the case happened when I use the npm package "@openai/codex-sdk" in the next.js project

    import { Codex } from "@openai/codex-sdk";
    
    const codex = new Codex();
    const thread = codex.startThread();
    const turn = await thread.run("Diagnose the test failure and propose a fix");
    
    console.log(turn.finalResponse);
    console.log(turn.items);
  6. Jian-Mengs commented on May 21, 2026

    @Jian-Mengs

    mine is this Image

  7. aideskdevservice commented on Jun 12, 2026

    @aideskdevservice

    mine is this Image

    same here, any solution to fix this?

  8. offcharken commented on Jun 12, 2026

    @offcharken

    Fixed: I set the Windows user variable:
    CODEX_CLI_PATH=C:\Users\offcharken.codex\packages\standalone\current\bin\codex.exe

  9. black-yt commented on Jun 13, 2026

    @black-yt

    更新 Codex App 后出现:

    Unable to locate the Codex CLI binary
    

    如果之前在 Codex App 里把 Agent Environment 设置成了 WSL,那么实际上系统里可能同时存在 3 个 Codex:

    1. Windows npm 安装的 Codex
    C:\Users\<user>\AppData\Roaming\npm\codex
    C:\Users\<user>\AppData\Roaming\npm\codex.cmd
    

    这是在 Windows 终端里执行 codex 用的。

    1. WSL 里自己安装的 Codex

    例如:

    /home/xwh/.nvm/versions/node/v22.22.2/bin/codex
    

    这是你在 Ubuntu/WSL 终端里执行 codex 用的。

    1. Codex App 自动生成的 WSL Wrapper(真正被 App 调用的)

    例如:

    C:\Users\<user>\.codex\bin\wsl\48731301ce01af57\codex
    

    这是 Codex App 为了桥接 Windows 和 WSL 自动生成的启动器。

    问题的根源在于:

    • 更新前,Codex App 被设置为使用 WSL 环境。
    • 很多人以为它直接调用第 2 个(WSL 里的 codex)。
    • 实际上它调用的是第 3 个(自己生成的 WSL Wrapper)。
    • 更新后 App 丢失了这个 Wrapper 的定位信息。
    • 因此启动时报:
    Unable to locate the Codex CLI binary
    

    很多人会误把环境变量设置到:

    AppData\Roaming\npm\codex
    

    或者:

    /home/.../codex
    

    结果会出现各种奇怪错误(.cmd 语法错误、node not found 等)。

    正确修复方法:

    先找到 App 自动生成的 WSL Wrapper,找到类似:

    C:\Users\<user>\.codex\bin\wsl\48731301ce01af57\codex
    

    然后设置:

    setx CODEX_CLI_PATH "C:\Users\<user>\.codex\bin\wsl\48731301ce01af57\codex"

    验证:

    echo %CODEX_CLI_PATH%

    重启 Codex App 即可恢复。

  10. onlinecco commented on Aug 26, 2026

    @onlinecco

    For me, I had to do
    setx CODEX_CLI_PATH "C:\Users\<user>\.codex\.sandbox-bin\codex.exe"

  11. xkingda24-bot commented on Aug 26, 2026

    @xkingda24-bot

    Fixed: I set the Windows user variable:
    CODEX_CLI_PATH=C:\Program Files\WindowsApps\OpenAI.Codex_26.820.7780.0_x64__2p2nqsd0c76g0\app\resources\codex.exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions