OpenAI Codex CLI Not Working on Windows: How to Fix

Share
A Windows laptop sits on a desk with a terminal window open on the screen.

If OpenAI Codex CLI is failing on Windows, the usual cause is not the CLI itself. The problem is often a Node.js install, PATH, the shell you launched it from, or Windows handling of environment variables and authentication differently from WSL2. The fastest safe fix is to check your version, install method, PATH, Node.js, and API key setup first, then compare behavior in PowerShell, Command Prompt, and WSL2 before reinstalling anything.

What’s actually failing when Codex CLI won’t run on Windows

Start by matching the fix to the symptom. A command that is not found points to install or PATH trouble. A crash right after launch points to the shell, Node.js, or a Windows-specific runtime problem. A prompt that opens but refuses to sign in or make requests usually means credentials, environment variables, or network access are the real issue.

If you need a quick way to classify the problem, look for this kind of message:

The exact message varies.
Error

That kind of error usually appears right when you run the command, during startup, or after you try to sign in.

It helps to separate the cases before you change anything:

  • Install problem: codex is not recognized, or the command never appears.
  • Launch problem: the command exists, but it closes, hangs, or throws an error as soon as it starts.
  • Auth problem: the CLI opens, but login fails or requests are rejected.

On Windows, those failures can look similar from the outside, but the fix is different. A PATH issue means Windows cannot find the executable. An auth issue means the CLI cannot read the right environment variable in the shell you are using. A shell-specific issue often disappears if you run the same command in PowerShell, Command Prompt, Git Bash, and WSL2 and compare the result.

Will this work on your setup, or do you need WSL2

On Windows, WSL2 is often the least painful place to run Codex CLI if the tool expects Linux-style behavior or if native PowerShell keeps tripping over quoting, path handling, or environment-variable differences. Native Windows can still work, but it is more likely to expose shell differences. Git Bash can be a middle ground, but it is not the same as a full Linux environment.

Use this quick rule of thumb:

  • If the install docs mention Linux-style commands, WSL2 is usually the safer choice.
  • If the CLI starts in PowerShell but fails in Git Bash, the issue is probably shell-specific.
  • If it works in WSL2 but not in PowerShell, the Windows environment is the problem, not the CLI package.

You do not need admin rights just to compare shells. You may need Administrator rights later if you have to change system-wide PATH entries or install software for all users. Keep one terminal window open for each shell so you can compare behavior without mixing settings.

If you are already in WSL2 and the CLI works there, that is a valid fix. You do not need to force native Windows to behave the same way if your work does not require it.

Check the basics first: Node.js, PATH, and how you installed it

Before changing anything else, confirm that Node.js is installed, that the version is compatible with the CLI, and that the command you are running is the one Windows can actually find. Most Windows failures start here.

  1. Check Node and npm from the shell where Codex CLI fails.
node -v
npm -v
PowerShell

You should see version numbers. If node is not recognized, Windows cannot find Node.js in PATH. If npm is missing too, the Node install is incomplete or broken.

  1. Check where Windows is finding Node.
where node
where npm
PowerShell

If these return nothing, or point to an unexpected location, PATH is the issue. If they return multiple paths, you may have more than one Node install, and the wrong one may be winning.

  1. Check how Codex CLI was installed.

If you installed it with npm, the executable is usually tied to the npm global bin directory. If you installed it another way, make sure that install method matches the shell you are using. A tool installed inside WSL2 will not automatically appear in native PowerShell.

If node -v works but the CLI still does not, the next likely problem is that the global npm bin folder is missing from PATH or the install landed in a different shell environment than the one you opened.

Fix the most common Windows launch errors

The most common launch failures on Windows are command not found, script-loading errors, and permission or terminal issues. Work through them in that order so you do the least disruptive fix first.

Command not found

If PowerShell says the command is not recognized, first check whether the package was installed globally and whether npm’s global bin folder is on PATH.

  1. Check the global npm location.
npm prefix -g
npm bin -g
PowerShell

If npm bin -g returns a directory, that directory needs to be reachable from the shell where you run Codex CLI. If it is not on PATH, add it for your user account through Windows Environment Variables, then open a new terminal.

  1. Open a fresh terminal and try the command again.

If it works after a new terminal opens, PATH was the problem. If it still does not work, the CLI may have been installed in a different environment, such as WSL2, or the install itself may be incomplete.

Do not reinstall repeatedly before checking PATH. A missing PATH entry can make a correct install look broken.

Script cannot be loaded

If PowerShell refuses to run the command because script execution is blocked, the issue is the execution policy or how the launcher was installed.

  1. Check the execution policy in the shell where the failure happens.
Get-ExecutionPolicy -List
PowerShell

If the policy blocks local scripts, you may need a more permissive user-level policy or a different shell. The safest test is to open a new PowerShell session and try again, then compare that result with Command Prompt. If the CLI works in Command Prompt but not PowerShell, the install is probably fine and PowerShell is the blocker.

Permission issues

If you see access denied errors, check whether you installed the package under one user account and are running the shell under another, or whether the install directory needs elevation. Installing globally into a protected location can cause this.

Run the terminal you are using as the same user that installed the tool. Only use Administrator mode if the install path or PATH edit truly requires it.

Terminal-specific failures

Windows Terminal can hide the difference between shells because each profile can load different startup scripts. Try the same command in plain PowerShell and plain Command Prompt.

  1. Compare Node in Command Prompt.
node -v
where node
Command Prompt

If the command works in one terminal but not another, the issue is in that terminal profile or shell startup file, not in Codex CLI itself. Check your PowerShell profile, startup scripts, and any custom environment variables loaded by Windows Terminal.

If it opens but won’t authenticate, check your API key and environment variables

If the CLI launches but login fails or requests are rejected, focus on credentials and environment variables. On Windows, a key can be set correctly in one shell and still be invisible in another.

  1. Check whether the variable is set in the shell you are using.
$env:OPENAI_API_KEY
PowerShell

If nothing prints, the variable is not set in that session. If it prints a value, do not paste it elsewhere. You only need to know that it exists.

  1. Set it for the current PowerShell session if needed.
$env:OPENAI_API_KEY="your_api_key_here"
PowerShell

That only lasts for the current window. If you need it to persist, set it through the Windows Environment Variables UI for your user account.

  1. If you are using Command Prompt, set it there with the matching syntax.
set OPENAI_API_KEY=your_api_key_here
Command Prompt

If login still fails, check for these common Windows gotchas:

  • The key was set in WSL2, but you are running native PowerShell.
  • The key was set in one terminal window, then you opened another one.
  • The shell profile overwrote the variable on startup.
  • A proxy, VPN, or firewall is blocking the request.

If the CLI reports an auth error even though the variable is set, try the same command in a plain shell with no profile scripts loaded. That tells you whether the issue is the CLI or something your shell is injecting at startup.

How to confirm it’s working after the fix

After you change one thing, verify one thing. Do not stack multiple fixes at once or you will not know which one worked.

  1. Open a fresh terminal in the same shell where you expect the CLI to work.
  2. Check Node again.
node -v
PowerShell

You should see a version number. If you do not, the shell still cannot see Node.js.

  1. Check that the CLI command is found.
where codex
PowerShell

If the command is found, Windows can see the executable. If it is not, PATH or the install method is still wrong.

  1. Run the smallest safe Codex CLI command you normally use, or start it in its default mode if that is how your setup works.

You are looking for one of two signs: the command is found, or the CLI moves past startup and into its own prompt or help output. If you still get the same PATH, script-loading, or auth error, the fix did not hit the real cause yet. Go back one layer and compare the same command in another shell.

A Windows laptop displays a terminal window while someone checks settings at the keyboard.

How to avoid breaking it again on Windows

The easiest way to avoid repeat failures is to keep the setup simple and consistent. Use one shell for the tool unless you have a reason to switch. If you need both PowerShell and WSL2, treat them as separate environments with separate installs and separate environment variables.

A few habits help a lot:

  • Keep only one Node.js install active if you can.
  • Reopen the terminal after changing PATH or environment variables.
  • Avoid setting the API key in a shell profile until you know the CLI works.
  • Do not mix a WSL2 install with a native Windows install and expect one to see the other.
  • If one terminal profile works and another does not, check the startup scripts before changing the CLI.

If you switch shells often, document where the CLI is installed and where the API key lives. That saves time the next time the command stops working after a Windows update or a shell refresh.

When the problem is bigger than Codex CLI

If Node itself is broken, reinstalling the CLI will not help. If PATH is wrong, the package can be correct and still look missing. If PowerShell keeps blocking the command, switching shells may be faster than forcing a native fix.

A broader fix makes sense when:

  • node -v fails in every shell.
  • where node shows an unexpected install or multiple conflicting installs.
  • The command works in WSL2 but fails in native Windows no matter what you change.
  • Your API key works in one shell but not another, which points to profile or environment-variable issues.

If that is where you land, update Node.js first, then do a clean reinstall of the CLI in the shell you actually plan to use. If Windows still fights you after that, move the setup to WSL2 and keep your daily work there.

Conclusion

If the CLI still fails after the checks above, keep the shell that already works and use that environment instead of fighting Windows further. The next step is to compare the failing shell with the working one and fix the mismatch there.

Frequently Asked Questions

Should I use PowerShell, Command Prompt, Git Bash, or WSL2 for Codex CLI on Windows?

Use the shell that gives you the fewest surprises. If PowerShell keeps failing on startup or auth, WSL2 is often the cleanest option. If the command works in one shell but not another, the shell is part of the problem.

Why does `node -v` work but `codex` says command not found?

That usually means Node.js is installed, but the CLI executable is not on PATH or was installed in a different environment. Check the npm global bin directory and make sure you are running the same shell where you installed it.

Can I set the API key in Windows Environment Variables instead of typing it every time?

Yes. That is usually the better choice once you know the CLI works. Just remember that a variable set in one environment, such as WSL2, will not automatically appear in native PowerShell.

Read more