Codex CLI on Windows (native install)
Prereqs
- Windows 10/11 + PowerShell
- Node.js + npm installed
- Note: Codex on Windows runs with an experimental sandbox in agent mode to restrict writes outside the working folder and block network access unless approved. (OpenAI Developers)
Install
npm i -g @openai/codex
Codex CLI is OpenAI’s local coding agent. (OpenAI Developers)
Find where npm installed the codex command
npm bin -g may not exist on newer npm versions, so use prefix instead. (npm Docs)
$prefix = (npm prefix -g).Trim()
$prefix
dir "$prefix\codex*"
You should see codex.cmd (and often codex.ps1) in that folder.
Run it (PowerShell gotcha)
If you run a quoted path with arguments, use PowerShell’s call operator &. (SS64)
& "$prefix\codex.cmd" --version
& "$prefix\codex.cmd"
Fix “codex is not recognized” (PATH)
For the current PowerShell window only:
$env:Path += ";$prefix"
codex --version
Permanent fix (User PATH) + restart terminal:
$userPath = [Environment]::GetEnvironmentVariable("Path","User")
if ($userPath -notlike "*$prefix*") {
[Environment]::SetEnvironmentVariable("Path", ($userPath.TrimEnd(';') + ";" + $prefix), "User")
}
Then close PowerShell and open a new one, and run:
codex --version
codex
Login (if browser auth is blocked)
Use device-code login:
codex login --device-auth
Quick troubleshoot
where.exe codex
npm list -g --depth=0
Alternative (often smoother)
OpenAI also provides a WSL2 path if you’d rather run Codex in a Linux environment on Windows. (OpenAI Developers)