Windows上安装Codex CLI完整指南
OpenAI的Codex CLI是强大的终端智能体,但Windows安装有差异。
Codex CLI on Windows 2026: Complete Setup Guide (OpenAI's Coding Agent)
OpenAI's Codex CLI brings the coding agent that powers ChatGPT Codex into your terminal. It is open source (Apache-2.0) and sits at 102,900 GitHub stars. Windows setup has a few gotchas - here is the path that works.
Step 1: Prerequisites
- Node.js 20+ (for npm)
- Git for Windows (for repo operations)
- An OpenAI API key (or ChatGPT Plus subscription for some plans)
Step 2: Install
npm install -g @openai/codex
codex --version
Step 3: Authenticate
codex login
This opens a browser window to authorize with your OpenAI account. On Windows, if the browser does not auto-open, copy the printed URL manually.
Step 4: Windows-Specific Setup
Open a terminal (use Git Bash or Windows Terminal - plain cmd works but Git Bash handles paths better):
codex
Then try: "list the files in this directory and summarize the README".
Windows Troubleshooting
| Issue | Fix |
|---|---|
| codex not recognized | Reinstall Node, confirm %APPDATA% |
| pm is in PATH | |
| Login window won't open | Run codex login --headless and paste the URL |
| Path errors on repos | Use Git Bash instead of cmd |
| Firewall blocks | Allow Node.js in Windows Defender Firewall |
| Slow first run | Codex downloads models/schema on first launch |
What Codex CLI Does Well
- Executes multi-step coding tasks with plan-then-act behavior
- Sandboxed command execution (approval prompts)
- Reads your whole repo for context
- Works with GPT-5-class models via API
FAQ
Is Codex CLI free? The CLI is open source. API usage is billed at OpenAI rates; Plus subscribers get limited monthly usage.
Codex CLI vs Claude Code? Both are terminal agents; Codex is OpenAI-tied, Claude Code is Anthropic-tied. Choose by which model you prefer.
Can it run local models? No - Codex CLI is designed for OpenAI models.
