When Codex fails in Windows PowerShell, the root cause is often not Codex itself. It may be Node.js, npm, PATH, execution policy, quoting, environment variables, proxy settings, or PowerShell argument passing.
This guide walks through the most common errors and the order to debug them.
Quick Checklist
Start here:
|
|
If codex --version works, Codex is available. Then look at login, project path, permissions, or network issues. If it fails, check Node, npm global paths, and the installed Codex CLI first.
Error 1: codex Is Not Recognized
Common message:
|
|
Check:
|
|
If Node.js or npm is missing, install the Node.js LTS version, then open a new PowerShell window. If npm exists but codex does not, reinstall:
|
|
Then:
|
|
If the command is still missing, the npm global bin directory is probably not in PATH.
Error 2: npm install -g Fails
Common causes:
- old Node.js version;
- npm global directory permission issue;
- company proxy or certificate interception.
Check:
|
|
Do not disable SSL verification casually. On managed company devices, follow the internal development environment guide.
Error 3: ExecutionPolicy Blocks Scripts
If PowerShell says scripts are disabled:
|
|
For trusted scripts, you can set the current user policy:
|
|
Or run a trusted script once:
|
|
Do not add -ExecutionPolicy Bypass everywhere. It is only for trusted scripts you understand.
Error 4: Paths With Spaces or Chinese Characters
Avoid building one long command string.
Instead of:
|
|
Use:
|
|
When calling an executable path:
|
|
Each argument should be its own array item.
Error 5: Copying Bash Commands Into PowerShell
Bash examples such as:
|
|
are not PowerShell commands.
PowerShell environment variable syntax:
|
|
To persist it for the user:
|
|
Open a new terminal afterward.
Error 6: Quotes, Backslashes, or JSON Arguments Break
Do not hand-escape complex JSON in a one-line command:
|
|
Prefer files or structured objects:
|
|
For native commands, use arrays:
|
|
Error 7: Chinese Text Looks Garbled or Files Are Corrupted
PowerShell console mojibake does not always mean the file is broken. Verify with UTF-8 reads:
|
|
When Codex or scripts modify Chinese Markdown, ask them to write UTF-8 explicitly and verify after writing. Do not treat terminal display alone as proof of corruption.
Error 8: Codex Login or API Key Does Not Work
First identify the intended auth mode:
- Codex app or CLI login;
- API key;
- plugin using local Codex;
- another tool calling Codex.
Check whether the current session sees the variable:
|
|
If you just changed system environment variables, open a new PowerShell window.
Error 9: Proxy, Certificates, or Firewall
If Codex starts but requests fail, test the network:
|
|
If DNS or port 443 fails, fix network access first. If the browser works but PowerShell fails, check terminal proxy settings and company certificate policy.
Error 10: Success and Failure Are Judged Incorrectly
Native programs use $LASTEXITCODE:
|
|
PowerShell cmdlets use terminating errors:
|
|
Do not use $LASTEXITCODE to check Copy-Item, Move-Item, or Remove-Item.
Prefer PowerShell 7
powershell.exe is usually Windows PowerShell 5.1. PowerShell 7 is:
|
|
Check:
|
|
Installing PowerShell 7 does not replace powershell.exe. Check your Windows Terminal, VS Code, and task settings.
A Safer Codex Startup Template
|
|
With arguments:
|
|
Suggested Debug Order
- Check
node -vandnpm -v. - Check
where.exe codex. - Run
codex --version. - Confirm PowerShell 5.1 or 7.
- Check paths with spaces or non-ASCII characters.
- Check whether you copied Bash syntax.
- Check execution policy.
- Check login or API key in the current session.
- Check proxy and certificate settings.
- Separate native program exit codes from PowerShell cmdlet errors.
Summary
Most Windows PowerShell Codex errors fall into four buckets: installation, shell syntax, paths/encoding, and network/authentication. Debug them in order before reinstalling everything. Use argument arrays, -LiteralPath, UTF-8 verification, and explicit error handling to make Codex on Windows much more stable.