AsterFlowAsterFlow
User GuideAPI ReferenceAI ApplicationsHelp & SupportBusiness Cooperation

OpenAI Codex CLI

OpenAI Codex CLI Installation Tutorial — Install a terminal AI coding assistant on Windows, macOS, Linux, connecting to AsterFlow. Supports sandbox policies and atomic patch editing.

Project Introduction

Codex CLI is a coding agent from OpenAI that runs locally on your computer.

Demo

introduce-01.webp

Features

| Category | Feature
title: OpenAI Codex CLI description: OpenAI Codex CLI Installation Tutorial — Install a terminal AI coding assistant on Windows, macOS, Linux, connecting to AsterFlow. Supports sandbox policies and atomic patch editing.

Project Introduction

Codex CLI is a coding agent from OpenAI that runs locally on your computer.

Demo

introduce-01.webp

Features

| Category | Feature
| Terminal-based Coding Assistant | Codex CLI is a terminal-based interactive coding assistant for editing code, generating patches, and running commands in the command line. | | Tool-Driven Architecture | Provides tools such as apply_patch, shell, update_plan, and multi_tool_use for controlled modification of repository files and operations. | | Atomic Patch Editing | Uses a specialized patch format to atomically add/update/delete files via apply_patch, facilitating auditing and rollback. | | Sandbox and Approval | Supports sandbox policies (e.g., workspace-write, read-only) and approval modes (on-request, on-failure, never) to control write and network access permissions. | | Plan Tracking | update_plan is used to list steps and track status, requiring only one in_progress step at all times to maintain clear progress. | | Interaction Protocol | Sends brief introductory explanations before important operations, maintaining a friendly, concise tone and providing progress updates. | | Security Constraints | Adheres to strict rules (no arbitrary changes to unrelated files, no adding copyright headers, no executing destructive commands), requiring user approval for sensitive operations. | | Testing and Formatting | Recommends running relevant tests and formatting tools after modifications, but is not responsible for fixing issues unrelated to the current task. | | Output and Style | Final output adheres to CLI rendering specifications (e.g., ** for headings, backticks for paths/commands), maintaining a scannable and concise structure. | | Parallel Execution | Supports running multiple tools in parallel via multi_tool_use.parallel to improve efficiency. |

AI Model Configuration Method

Windows Graphical Guide

1. Open Terminal

windows_open_terminal

2. Install WSL

For optimal performance on Windows, please install and use Windows Subsystem for Linux (WSL2).

Install WSL2, Restart Windows Computer

wsl --install

Restart your Windows computer after installation.

Windows Notes

  • It is recommended to use PowerShell instead of CMD.
  • If you encounter permission issues, try running as administrator.
  • Some antivirus software may report false positives; you need to add an exception.

windows-img-03.webp

Download Node Version Manager (NVM)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

windows-img-04.webp

NVM Installs Node.js 22

Open a new PowerShell window in the tab bar and open WSL:

wsl

Install Node.js (version numbers are time-sensitive; please install the corresponding version according to the OpenAI official website requirements):

nvm install 22

windows-img-05.webp

3. Install Codex CLI

Install Codex CLI

npm i -g @openai/codex

This command will download and install the latest version of Codex CLI from the official npm repository.

windows-img-06.webp

4. Modify Configuration File

One-Click Modification of Codex CLI Configuration File

Run this in the WSL terminal:

curl -fsSL https://docs.asterflow.ai/helper/codex-cli-setup.sh | bash

The setup flow is as follows:

  1. Enter the API key: The script prompts for the API key first, then fetches the current model list in real time from the AsterFlow endpoint https://asterflow.ai/v1.
  2. Choose models: Use the arrow keys to move, press Space to toggle a model ([√] marks selected items), and press Enter after selecting at least one model.
  3. Finish setup: The first selected model in the list becomes Codex's default model, and all selected models are saved to asterflow-selected-models.txt under CODEX_HOME.

Rerun the script whenever AsterFlow adds or changes models. The generated configuration keeps the reasoning effort at medium; restart Codex after setup to load the new configuration. If Invalid token persists, confirm that the key has not been deleted or expired.

5. Start Using Codex CLI

Now you can start using Codex CLI!

Launch Codex CLI

Launch WSL2:

wsl

Launch Codex CLI directly:

codex

Use in a specific project:

cd mnt/c/path/to/your/project
codex

Press Enter to launch Codex CLI.

windows-img-09.webp

windows-img-10.webp

Set Codex CLI permissions: 1. Allow Codex to modify files directly; 2. Codex requires manual authorization to modify files.

Select Model

/model

windows-img-11.webp

windows-img-12.webp

windows-img-13.webp

windows-img-14.webp

Note: After modifying the API address, all models (including officially preset models) will call your configured, legally authorized self-owned or organizational access point. Please use your own deployed AsterFlow, or confirm that the service provider has a AsterFlow service with legal upstream authorization and compliance obligations. Do not connect API addresses or keys from unknown sources to a production environment.

macOS Graphical Guide

1. Install Homebrew (Skip if already installed)

Homebrew is the missing package manager for macOS.

Official Website: https://brew.sh

macos-img-01.webp

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

macos-img-02.webp

macos-img-03.webp

macos-img-04.webp

2. Install Node.js Environment

Node.js Environment Installation Steps

Update Homebrew:

brew update

Install Node.js:

brew install node

macOS Notes

  • If you encounter permission issues, you might need to use sudo.
  • The first run may require permission in System Preferences.
  • It is recommended to use Terminal or iTerm2.

macos-img-05.webp

macos-img-06.webp

Verify Successful Installation

After installation, open the terminal and enter the following commands:

node --version
npm --version

If version numbers are displayed, the installation was successful.

3. Install Codex CLI

Install Codex CLI

Open the terminal and run the following command:

# Install Codex CLI globally
npm install -g @openai/codex

If you encounter permission issues, you can use sudo:

sudo npm install -g @openai/codex

macos-img-07.webp

Verify Codex CLI Installation

After installation, enter the following command to check if the installation was successful:

codex --version

If a version number is displayed, congratulations! Codex CLI has been successfully installed.

4. Modify Configuration File

One-Click Modification of Codex CLI Configuration File

curl -fsSL https://docs.asterflow.ai/helper/codex-cli-setup.sh | bash

The setup flow is as follows:

  1. Enter the API key: The script prompts for the API key first, then fetches the current model list in real time from the AsterFlow endpoint https://asterflow.ai/v1.
  2. Choose models: Use the arrow keys to move, press Space to toggle a model ([√] marks selected items), and press Enter after selecting at least one model.
  3. Finish setup: The first selected model in the list becomes Codex's default model, and all selected models are saved to asterflow-selected-models.txt under CODEX_HOME.

Rerun the script whenever AsterFlow adds or changes models. The generated configuration keeps the reasoning effort at medium; restart Codex after setup to load the new configuration. If Invalid token persists, confirm that the key has not been deleted or expired.

5. Start Using Codex CLI

Now you can start using Codex CLI!

Launch Codex CLI

Launch Codex CLI directly:

codex

Use in a specific project:

cd /path/to/your/project
codex

Press Enter to launch Codex CLI.

macos-img-09.webp

macos-img-10.webp

Set Codex CLI permissions: 1. Allow Codex to modify files directly; 2. Codex requires manual authorization to modify files.

macos-img-11.webp

macos-img-12.webp

macos-img-13.webp

macos-img-14.webp

Note: After modifying the API address, all models (including officially preset models) will call your configured, legally authorized self-owned or organizational access point.

6. macOS Common Issues and Solutions

Permission Error During Installation

Try the following solutions:

  • Install with sudo: sudo npm install -g @openai/codex
  • Or configure npm to use the user directory: npm config set prefix ~/.npm-global

macOS Security Settings Prevent Running

If the system prevents Codex CLI from running:

  • Open "System Preferences" → "Security & Privacy"
  • Click "Open Anyway" or "Allow"
  • Or run in Terminal: sudo spctl --master-disable

Linux Graphical Guide

1. Install Node.js Environment

Codex CLI requires a Node.js environment to run.

Node.js Environment Installation Steps

Add NodeSource repository:

sudo curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

Install Node.js:

sudo apt-get install -y nodejs

Linux Notes

  • Some distributions may require additional dependencies.
  • If you encounter permission issues, use sudo.
  • Ensure your user has write permissions in npm's global directory.

linux-img-01.webp

linux-img-02.webp

Verify Successful Installation

After installation, open the terminal and enter the following commands:

node --version
npm --version

If version numbers are displayed, the installation was successful.

2. Install Codex CLI

Install Codex CLI

Open the terminal and run the following command:

# Install Codex CLI globally
npm install -g @openai/codex

If you encounter permission issues, you can use sudo:

sudo npm install -g @openai/codex

linux-img-03.webp

Verify Codex CLI Installation

After installation, enter the following command to check if the installation was successful:

codex --version

If a version number is displayed, congratulations! Codex CLI has been successfully installed.

3. Modify Configuration File

One-Click Modification of Codex CLI Configuration File

curl -fsSL https://docs.asterflow.ai/helper/codex-cli-setup.sh | bash

The setup flow is as follows:

  1. Enter the API key: The script prompts for the API key first, then fetches the current model list in real time from the AsterFlow endpoint https://asterflow.ai/v1.
  2. Choose models: Use the arrow keys to move, press Space to toggle a model ([√] marks selected items), and press Enter after selecting at least one model.
  3. Finish setup: The first selected model in the list becomes Codex's default model, and all selected models are saved to asterflow-selected-models.txt under CODEX_HOME.

Rerun the script whenever AsterFlow adds or changes models. The generated configuration keeps the reasoning effort at medium; restart Codex after setup to load the new configuration. If Invalid token persists, confirm that the key has not been deleted or expired.

4. Start Using Codex CLI

Now you can start using Codex CLI!

Launch Codex CLI

Launch Codex CLI directly:

codex

Use in a specific project:

# Enter your project directory
cd /path/to/your/project

# Launch Codex CLI
codex

Press Enter to launch Codex CLI.

linux-img-05.webp

linux-img-06.webp

Set Codex CLI permissions: 1. Allow Codex to modify files directly; 2. Codex requires manual authorization to modify files.

linux-img-07.webp

linux-img-08.webp

linux-img-09.webp

linux-img-10.webp

Note: After modifying the API address, all models (including officially preset models) will call your configured, legally authorized self-owned or organizational access point.

5. Linux Common Issues and Solutions

Permission Error During Installation

Try the following solutions:

  • Install with sudo: sudo npm install -g @openai/codex
  • Or configure npm to use the user directory: npm config set prefix ~/.npm-global
  • Then add to PATH: export PATH=~/.npm-global/bin:$PATH

Missing Dependency Libraries

Some Linux distributions require additional dependencies:

# Ubuntu/Debian
sudo apt install build-essential
# CentOS/RHEL
sudo dnf groupinstall "Development Tools"
OpenAI Codex CLI | AsterFlow Docs