codex fails to launch on macOS due to unsupported env -S shebang
On macOS(Apple Silicon), attempting to run the @openai/codex CLI installed via pnpm results in the following error:
/Users/USERNAME/Library/pnpm/codex: line 16: exec: NODE_OPTIONS=--no-deprecation: not found
📍 Root cause
The top of the shim script contains:
#!/usr/bin/env -S NODE_OPTIONS=--no-deprecation node
The -S flag is a GNU extension to env, and is not supported on macOS, which uses BSD coreutils by default. As a result, this shebang is not portable and fails with a confusing error.
✅ Proposed fix
Update the shebang in the codex launcher script to use a more portable invocation:
#!/bin/bash
NODE_OPTIONS=--no-deprecation exec node /absolute/path/to/dist/cli.js "$@"
Or, if relative resolution is preferred:
#!/bin/bash
NODE_OPTIONS=--no-deprecation exec node "$(dirname "$0")/../global/5/node_modules/@openai/codex/dist/cli.js" "$@"
This resolves the issue across macOS and Linux while keeping the environment flag behavior intact.
🔁 Workaround for users
Until this is fixed in the distributed package, users can create a wrapper script in ~/bin with:
#!/bin/bash
NODE_OPTIONS=--no-deprecation exec node /Users/USERNAME/Library/pnpm/global/5/node_modules/@openai/codex/dist/cli.js "$@"
And ensure ~/bin is at the front of their $PATH.
7 Comments
Thank you for the detailed issue description, proposed fix looks good, please send a PR!
Not sure if the PR is any good, but wanted the workaround out there in the meantime.
FWIW I am on macOS and it runs just fine:
Where do you get that
-Sis "not supported on macOS"? Per the manpage, "The -P, -S and -v options were added in FreeBSD 6.0." — that was released in 2005.Copilot is arguing that the npm package fails when parsed as a shebang in the generated wrapper script, that the "generated global binary (the shim) is interpreted differently than a direct node call or shell script."
The workaround is solid for me, and there are others already reporting similar issues.
I had the same issue, and @dahifi's workaround seems to be working for me so far.
This should be closed now with https://github.com/openai/codex/pull/96, once a new version is released
Note the GNU implementation was modeled after FreeBSD, which implemented the
-Soptions since FreeBSD 5.5 (2008).It looks like your env(1) is trying to execute
NODE_OPTIONS=--no-deprecationrather than taking it as a directive to set that env var. Testing on GNU, macOS 12.7.4, FreeBSD 15, and macOS 15.4 at least show the expected interpretation of an env var setting for any entry containing '='. You can test this withenv -vS'FOO=bar true'It would be interesting to see output from
env -vS'FOO=bar true'on a system that had this issue to see if they also have this operation