Step 1: Install with npm
Run npm install -g @openai/codex in your terminal. Requires Node.js 22 or newer.
Step 2: Set your API key
Export your OpenAI API key as an environment variable: OPENAI_API_KEY
Step 3: Choose autonomy mode
Select suggest (safest), auto-edit (balanced), or full-auto (most autonomous) based on your comfort level
Step 4: Start coding
Run codex in your project directory for interactive use, or pass a prompt directly for one-shot tasks
| Feature | Codex in ChatGPT | Codex CLI | |
|---|---|---|---|
| Runs where | Runs where | Cloud sandbox | Your local machine |
| Setup required | Setup required | None (browser based) | npm install + API key |
| Accesses local files | Accesses local files | No (cloud only) | |
| Accesses local tools | Accesses local tools | ||
| Internet during execution | Internet during execution | No (sandboxed) | |
| AI providers | AI providers | OpenAI only | Multiple (OpenAI, local models, etc.) |
| Delivers results as | Delivers results as | GitHub pull request | Direct file changes |
| Cost | Cost | ChatGPT subscription | API usage (pay per token) |
| Open source | Open source |
When to use CLI vs. ChatGPT
Use Codex CLI when you need local file access, want to work with multiple AI providers, or prefer a terminal workflow. Use Codex in ChatGPT when you want zero setup, cloud isolation, and automatic PR creation. Many developers use both: ChatGPT Codex for larger tasks that benefit from sandboxing, and the CLI for quick local tasks where speed matters.