OpenAI Codex CLI: A Step-by-Step Installation Guide for Windows, macOS, and Linux
OpenAI Codex CLI is a local terminal-based AI coding assistant that streamlines code editing, patch generation, and command execution. This guide covers...
OpenAI Codex CLI is a local, terminal-based AI coding assistant developed by OpenAI to help developers edit code, generate patches, and run commands directly from the command line. As a coding proxy, it offers a suite of tools to enhance workflow efficiency while maintaining control and security.
Key features of Codex CLI include:
- Terminal-based interactive coding assistance for code editing and patch generation.
- Tool-driven architecture with utilities like
apply_patch,shell,update_plan, andmulti_tool_usefor controlled repository changes. - Atomic patch editing via
apply_patchfor easy audit trails and rollbacks. - Sandbox policies (e.g.,
workspace-write,read-only) and approval modes (on-request, on-failure, never) to manage file write and network access. - Plan tracking with
update_planto keep progress clear with only one in-progress step. - Friendly, concise interactions with progress updates before critical operations.
- Strict security constraints to avoid unintended changes, requiring user approval for sensitive actions.
- Parallel tool execution via
multi_tool_use.parallelto boost efficiency.
For Windows users:
- Install WSL2: Run
wsl --installin PowerShell (as administrator if needed) and restart your computer. - Install NVM: Use
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bashto get Node Version Manager. - Install Node.js: Open a new WSL window and run
nvm install 22(check OpenAI’s official site for the latest required version). - Install Codex CLI: Execute
npm i -g @openai/codexto install globally. - Configure: Run
iex (irm 'https://raw.githubusercontent.com/QuantumNous/new-api-docs/refs/heads/main/helper/codex-cli-setup.ps1')to set up the config file. - Launch: Start WSL2, then run
codex(or navigate to your project directory first).
For macOS users:
- Install Homebrew: If not present, run
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)". - Install Node.js: Update Homebrew with
brew update, then install Node.js usingbrew install node. - Install Codex CLI: Run
npm install -g @openai/codex(usesudofor permission issues). - Configure: Execute
curl -fsSL https://raw.githubusercontent.com/QuantumNous/new-api-docs/refs/heads/main/helper/codex-cli-setup.sh | bashto set up the config. - Launch: Run
codexdirectly or navigate to your project directory first.
After installation, set permissions: choose to allow direct file modifications or require manual approval. Use the /model command to select a model. Note that modifying the API endpoint routes all calls to your authorized New API access point—ensure you use a legally approved service or your own deployment.
Security reminder: Avoid untrusted API addresses or keys in production to maintain compliance and data safety.
Sources
- NewAPI Documentation: Codex CLI Installation Guide. https://www.newapi.ai/zh/docs/apps/codex-cli