Error Fix · As of 2026-11-26

Fix "'codex' is not recognized" on Windows: PATH, npm Global Prefix, PowerShell and WSL2

If Windows says 'codex' is not recognized as an internal or external command, operable program or batch file after you install Codex CLI, the folder that holds codex is almost always missing from the PATH your terminal sees: the npm global folder was never added, the terminal was opened before the install, or Codex lives in WSL or under a different Node version. Run where.exe codex and, in PowerShell, Get-Command codex -All to find out where it is, then apply the matching fix below. As of 2026-11-26 the latest Codex CLI is 0.172.0 (released 2026-11-24), and on Windows you can install it with npm (@openai/codex) or with OpenAI's standalone PowerShell installer. Once it runs, the last section shows the config.toml that connects Codex to QCode.

QCode is an independent third-party API service and is not affiliated with OpenAI. Install commands and error strings follow OpenAI's documentation, the openai/codex repository and community reports; QCode settings follow docs.qcode.cc.

Updated 2026-11-26

Key facts

  • The error means one thing only: the current terminal can't find an executable named codex on PATH. It says nothing about your API key, network or model.
  • npm puts the codex launchers (codex.cmd, codex.ps1) in the npm global folder, by default %APPDATA%\npm. npm config get prefix prints the real location.
  • The official standalone installer is powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex". It writes its folder to your user PATH, which only new PowerShell windows pick up.
  • In PowerShell, where is an alias for Where-Object. Use where.exe codex, or you'll get no output at all.
  • With nvm-windows, global packages belong to one Node version. Switch versions and codex "disappears", even though PATH is fine.
  • WSL2 and Windows are separate environments. A codex installed inside WSL can't be called from PowerShell and vice versa, and each side has its own ~/.codex config.

Which error are you seeing?

The wording depends on the shell and on your Windows display language. These are the built-in Windows messages:

Shell Language Message
CMD English 'codex' is not recognized as an internal or external command, operable program or batch file.
Windows PowerShell 5.1 English codex : The term 'codex' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PowerShell 7 English codex: The term 'codex' is not recognized as a name of a cmdlet, function, script file, or executable program.
CMD Chinese (Simplified) 'codex' 不是内部或外部命令,也不是可运行的程序或批处理文件。
CMD Japanese 'codex' は、内部コマンドまたは外部コマンド、操作可能なプログラムまたはバッチ ファイルとして認識されていません。
CMD Russian "codex" не является внутренней или внешней командой, исполняемой программой или пакетным файлом.

One message looks similar but has a completely different cause:

codex : File C:\Users\you\AppData\Roaming\npm\codex.ps1 cannot be loaded because running scripts is disabled on this system.

Here codex was found. PowerShell's execution policy is blocking the .ps1 launcher that npm created. See cause 3.

Step 1: find out whether and where Codex is installed

In PowerShell, run these in order (from CMD, only 1 and 3 apply):

# 1. Every file named codex on PATH (note: where.exe, not where)
where.exe codex

# 2. What PowerShell would actually run (.ps1, .cmd or .exe)
Get-Command codex -All

# 3. Where npm installs global packages, and whether Codex is there
npm config get prefix
npm ls -g @openai/codex

# 4. Is there a codex.exe in the standalone installer's default folder?
Test-Path "$env:LOCALAPPDATA\Programs\OpenAI\Codex\bin\codex.exe"

Read the results like this:

Result Meaning Go to
npm ls -g shows @openai/codex@0.17x but where.exe codex finds nothing Installed; npm folder not on PATH Cause 1
A fresh window works The old window never saw the PATH change Cause 2
"running scripts is disabled" Execution policy blocks codex.ps1 Cause 3
npm ls -g is empty and you've switched Node versions Installed under another Node version, or in WSL Cause 4
where.exe codex lists two or more files Competing installs Cause 5
Nothing anywhere It never installed Reinstall

Cause 1: the npm global folder isn't on PATH

With the official Node.js installer, the npm global folder is usually C:\Users\you\AppData\Roaming\npm, and the installer normally adds it to your user PATH. A changed prefix, a portable Node build, or a company policy that resets PATH can leave it out.

Find the folder, then append it to your user PATH without touching the rest (no admin rights needed):

$npmPrefix = (npm config get prefix).Trim()
$userPath  = [Environment]::GetEnvironmentVariable('Path', 'User')
if ($userPath -notlike "*$npmPrefix*") {
  [Environment]::SetEnvironmentVariable('Path', "$userPath;$npmPrefix", 'User')
}

Then close every terminal and editor, including the integrated terminals in VS Code or Cursor, reopen, and run codex --version. Don't edit PATH with setx PATH ...: setx truncates values longer than 1024 characters and can leave you with a shortened PATH.

To prove the program itself works before touching PATH, call it by full path:

& "$env:APPDATA\npm\codex.cmd" --version

Cause 2: the terminal was open before the install

Windows reads environment variables when a process starts. Whether npm or the official script changed PATH, windows that were already open don't see it. The simplest fix is a new window.

If a new window still fails, check whether you ran npm install -g from a different account, for example an administrator account typed into a UAC prompt. The package then lands in that account's %APPDATA%\npm, which your own account can't see. Install global packages from your everyday account without elevation.

Cause 3: execution policy blocks codex.ps1

npm creates both codex.cmd and codex.ps1. PowerShell prefers the .ps1, and the default execution policy may refuse to run scripts. Three ways out:

  1. Allow local scripts for your user only. OpenAI's Windows docs suggest RemoteSigned for the matching npm.ps1 error, after reviewing Microsoft's guidance:

powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

  1. Leave the policy alone and call the CMD launcher: codex.cmd --version.
  2. Switch to the standalone installer, which installs a codex.exe binary rather than a .ps1 launcher.

On a managed machine where IT sets the policy through Group Policy, ask IT instead of working around company security settings.

Cause 4: Codex lives under another Node version or in WSL

  • nvm-windows, fnm or Volta. Under nvm-windows each Node version has its own global packages. Install Codex under Node 22, run nvm use 24, and codex is gone. Switch back, or run npm install -g @openai/codex again under the new version.
  • WSL. npm install -g @openai/codex in an Ubuntu terminal installs the Linux build, which only runs inside WSL. PowerShell not finding it is expected.
  • Node too old. QCode's docs say the npm route needs Node.js 22 LTS or later. Check node -v and upgrade Node before reinstalling.

Cause 5: more than one codex on PATH

When where.exe codex lists several entries, Windows runs the first one on PATH. Typical mixes are an npm copy plus a standalone copy, or a CLI next to the Codex desktop app or VS Code extension. Issue #28278 in openai/codex describes Windows PATH resolving to a mismatched Codex entry point, which made codex exec fail with ShellExecuteExW failed to launch setup helper: 1223.

Keep one CLI install:

# Keeping the standalone build? Remove the npm one
npm uninstall -g @openai/codex

# Keeping npm? Delete the standalone folder and remove it from your user PATH

Reinstall or upgrade

If you decide to reinstall, pick one method:

# Option A: npm (Node.js 22+)
npm install -g @openai/codex@latest

# Option B: OpenAI's standalone installer (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

The standalone installer (option B) installs a codex.exe under your user profile and adds that folder to your user PATH; run where.exe codex in a new window to see the exact location. A public copy of the installer script uses %LOCALAPPDATA%\Programs\OpenAI\Codex\bin by default and documents a CODEX_INSTALL_DIR override, but check the current script before relying on either. The Codex 0.171.0 changelog (2026-11-20) lists fixes for how the installer escapes PATH entries containing shell metacharacters and how the standalone installer detects the Node launcher, so rerunning an older script is worth a try.

Verify in a new window:

codex --version

Output like codex-cli 0.172.0 means PATH is fixed.

Found, but crashes on start

If codex is found but exits immediately and the logs show exit code 3221225781 (0xC0000135), a user on the OpenAI community forum traced it to a missing vcruntime140_1.dll. Installing the latest Microsoft Visual C++ Redistributable (x64 and x86) fixed it; another user also had to reinstall Codex.

The WSL2 route

If you want a Linux toolchain or Linux sandboxing for commands, run Codex inside WSL2:

# In an Ubuntu (WSL2) terminal, pick one
npm install -g @openai/codex
curl -fsSL https://chatgpt.com/codex/install.sh | sh

codex --version

Two rules: WSL doesn't inherit your Windows user variables, so export your key in ~/.bashrc; and WSL's config lives in the Linux home ~/.codex/, separate from %USERPROFILE%\.codex\. OpenAI's docs note you can set CODEX_HOME to the Windows path to share one config, and that WSL1 is unsupported from Codex 0.115.

Once it runs: connect Codex to QCode

Codex CLI speaks the OpenAI Responses protocol. Put this in %USERPROFILE%\.codex\config.toml (create the file if needed):

model_provider = "qcode"
model = "gpt-6.2-sol"

[model_providers.qcode]
name = "qcode"
base_url = "https://api.qcode.cc/openai"
wire_api = "responses"
env_key = "QCODE_API_KEY"

Store the key as a user variable, then open a new window:

[Environment]::SetEnvironmentVariable('QCODE_API_KEY', 'cr_your_key', 'User')

QCode's docs also describe requires_openai_auth = true with %USERPROFILE%\.codex\auth.json containing {"OPENAI_API_KEY": "cr_your_key"}. Use one method, not both. Three traps:

  1. base_url must be exactly https://api.qcode.cc/openai, with no /v1 and no trailing slash, or you'll get not_found.
  2. Notepad may save the file as config.toml.txt. Choose "All Files" and type config.toml.
  3. Through QCode, Codex uses GPT models. Per QCode's endpoint docs, Claude is served only on the Anthropic protocol and the Chinese models don't support the Responses API, so don't put either kind of model ID in Codex.

To skip manual setup, QCode's Windows one-click script (run in PowerShell) is irm https://qcode.cc/install/codex.ps1 | iex. It tests endpoint latency, writes the config and installs Codex and Node.js if needed.

Error lookup

Symptom Cause Fix
'codex' is not recognized as an internal or external command Codex folder not on PATH Check npm config get prefix, add it to user PATH, reopen terminals
The term 'codex' is not recognized as the name of a cmdlet Same, PowerShell wording Same; confirm with Get-Command codex -All
running scripts is disabled on this system Policy blocks codex.ps1 RemoteSigned -Scope CurrentUser, or use codex.cmd
where codex prints nothing in PowerShell where = Where-Object Use where.exe codex
Gone after switching Node versions Global packages are per version Switch back or reinstall under the new version
Works in WSL, not in PowerShell Installed in WSL only Use it in WSL, or install on Windows too
Exit code 3221225781 Missing VC++ runtime (community report) Install the latest Visual C++ Redistributable
401 / You didn't provide an API key Key not found Check QCODE_API_KEY or auth.json
not_found base_url has /v1 or a trailing slash Set it to https://api.qcode.cc/openai

FAQ

What's the fastest fix for "'codex' is not recognized" right after installing?

Close the terminal and open a new one. If that fails, run npm config get prefix, add that folder to your user PATH, and restart every terminal and editor.

Why does where codex print nothing in PowerShell?

In PowerShell where is an alias for Where-Object, not the program-finder. Type where.exe codex or use Get-Command codex -All.

How do I fix "codex.ps1 cannot be loaded because running scripts is disabled"?

Execution policy is blocking npm's .ps1 launcher. Run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser, call codex.cmd, or install codex.exe with the standalone installer.

Should I install Codex on Windows with npm or the official installer?

The standalone installer doesn't need Node.js, installs a binary and avoids the .ps1 launcher, so it has fewer PATH problems. npm is fine if you already manage tools with it; just keep only one install.

Can I run a Codex installed in WSL2 from a Windows terminal?

Not directly. WSL2 and Windows each need their own install, config folder and environment variables. To share config, point CODEX_HOME in WSL at the Windows .codex folder, as OpenAI's docs describe.

Codex starts now but returns 401. Is that still PATH?

No. A 401 means Codex ran and sent a request without a valid key. Check that QCODE_API_KEY is visible in a new window, or that auth.json holds the full cr_ key under OPENAI_API_KEY.

Can I use Claude or Chinese models in Codex through QCode?

No. Codex only uses the Responses protocol; on QCode, Claude is served on the Anthropic protocol only, and GLM, Kimi, DeepSeek and Qwen are served on Anthropic and OpenAI Chat but not Responses. Use GPT models such as gpt-6.2-sol in Codex.

Test the whole setup on the trial plan

Once Codex runs, the simplest way to validate everything is QCode's Trial plan: from $9 for 30 days with $5 of usage per day. The same key calls GPT in Codex (OpenAI protocol) and Claude in Claude Code (Anthropic protocol); Anthropic and OpenAI models are billed at official API price ×1.0. For occasional use, a pay-as-you-go pack (valid 7 days) also works. See /pricing for all plans and current prices.

Test the whole setup on the trial plan

One key for both the Anthropic Messages API and OpenAI-compatible APIs. Claude and GPT are billed at the official price ×1.0; live rates are on /models.

Not sure where to start?

Try it for a week

Small Pack: $4 for $30 of quota, valid 7 days

Use it every day

Starter: $9.00/month with $5 of quota every day — just $0.060 per $1 of quota, vs about $0.113 for the Medium Pack