Fix Codex command not found in PowerShell

Find the real Codex executable, distinguish a missing installation from command lookup, and restore an npm-installed CLI in your current PowerShell session.

For an existing npm-installed Codex CLI on Windows. Tested on Windows 11 with PowerShell 7 and CLI 0.163.0 on November 6, 2026: missing lookup, absolute execution, multiple installations and temporary PATH recovery. Persistent PATH edits, policy-error reproduction, WSL and macOS recovery were not tested.

Start here

If the real executable works by its full path, restore command lookup in the same shell and verify which copy runs before reinstalling.

1. Identify the failing layer

Use the terminal where the error occurred. Command not found, a script-policy block, sign-in failure and a failed model request are different problems. PATH changes address command lookup. This walkthrough assumes an existing npm installation; standalone or desktop-managed executables need their own installation path.

Reference: OpenAI: Codex CLI

2. Inspect every command match

No output means this session cannot resolve the name, not that the files are absent. Several matches may be npm shims or a second installation. Check CommandType and Source: aliases and functions can also hide executables. Do not delete another installation merely because it appears here.

Get-Command codex -All -ErrorAction SilentlyContinue |
  Select-Object CommandType, Source

Reference: Microsoft: PowerShell command precedence

3. Find and run the existing npm shim

Windows npm puts global executable shims directly in its prefix. Ask your installed npm for that directory instead of copying someone else's path. If npm.cmd is unavailable, check Node/npm first. If Test-Path returns False, confirm your installation method; adding a directory cannot restore a missing file.

Continue with the final command only if the shim exists in the npm directory you recognize. A CLI version response demonstrates executable startup. A missing Node runtime or another error needs its own repair. The explicit .cmd extension selects that shim rather than a .ps1 file; this trial did not reproduce a policy block or change execution policy.

$codexBin = (npm.cmd prefix -g).Trim()
$codexCmd = Join-Path $codexBin 'codex.cmd'
Test-Path -LiteralPath $codexCmd

# Continue only when the file exists in your known npm installation:
& $codexCmd --version

Reference: npm: Folders · Microsoft: PowerShell command precedence

4. Restore lookup in this session

When full-path execution works, prepend its containing directory to this process's PATH. Inspect resolution again, then run the named .cmd command. It should use the intended installation and report the same version.

This change lasts for the current PowerShell process and its children. It does not save user or machine environment settings. After a normal installation, a fresh terminal may already have the right environment. Persistent repair is a separate change: use the verified directory and your organization's environment-management process.

In our controlled child-shell trial, removing only npm's directory initially left a second Codex executable available. Removing all discovered Codex directories reproduced missing lookup; the absolute npm shim still worked, and adding its directory back restored the named command. The test restored its environment afterward.

$env:Path = "$codexBin;$env:Path"
Get-Command codex -All -ErrorAction SilentlyContinue |
  Select-Object CommandType, Source
codex.cmd --version

Reference: npm: Folders · Microsoft: PowerShell command precedence

5. Check the result and choose the next step

A version response proves lookup and startup, not sign-in or task completion. Move to the sign-in guide if authentication fails afterward. Diagnose a WSL terminal using its Linux installation and environment separately.

If another copy still wins resolution, keep the all-matches output and both version results. Use the verified full path while reviewing installation ownership. Do not remove files or permanently rewrite PATH as an unexamined cleanup step.

Diagnose command lookup without changing settings

Diagnose why an npm-installed Codex CLI is not found in this Windows PowerShell session. Do not edit files, environment settings, execution policy, accounts, or installations.

Inspect Get-Command codex -All and the installed npm global prefix. Check whether codex.cmd exists there. Only run --version from an existing official installation path I recognize. Compare full-path execution with named resolution. Distinguish missing files, multiple installations, aliases/functions, command lookup, script-policy errors and later authentication errors.

Report the evidence and the smallest next step. Ask before changing PATH or removing any installation. Do not read credentials or claim a successful model task from a version response.

Read the prompt before sending it. Copying does not run it.

Check your result

  • You know the intended installation method and actual executable path.
  • The existing npm shim reports a CLI version by full path.
  • Named codex.cmd works after the temporary same-session change and reports the same version.
  • You understand that process-only recovery neither saves permanent PATH nor proves sign-in.

Sources and scope

The references below distinguish documented behavior from our dated practical checks. Task prompts and completion checks are community guidance; each source states what it supports.

Something changed in your version? Send a correction with the guide URL, platform, and version. Leave out credentials and private project content.

Analytics preferences

Google Analytics measures visits and actions. Microsoft Clarity records page interactions to help us improve navigation. These services can receive device information, page URLs and identifiers, and use cookies. Tool inputs are masked from Clarity.

Reject analytics to stop loading both services. Your choice applies to this browser for 180 days. You can change it here at any time. Read our privacy policy.

Loading your preferences…