📖 Introduction

Codex CLI is OpenAI's coding agent that you can run in your local terminal. It can read, modify, and run code in your selected directory. It's open-source and built in Rust for speed and efficiency.

ChatGPT Plus, Pro, Business, Edu, and Enterprise plans all include Codex access. You can authenticate using your ChatGPT account or an API key.

⚙️ System Requirements

Component Requirement Notes
Operating System macOS / Linux / Windows (WSL2) Windows support is experimental
Node.js v18.0 or higher Required for npm installation
Account ChatGPT Plus/Pro/Enterprise or API Key Requires valid access

🖥️ Choose Your Platform

Install via npm

Terminal
# Install Codex CLI globally npm install -g @openai/codex # Verify installation codex --version

Install via Homebrew

Terminal
brew install openai-codex # Verify installation codex --version

Configure API Key

On first run, Codex will prompt you to log in. You can use your ChatGPT account or an API key for authentication. When using BeeHears service:

Terminal - Configure environment variables
# Set API Base URL (using BeeHears service) export OPENAI_BASE_URL="https://api.beehears.com/v1" # Set API key export OPENAI_API_KEY="your-api-key-here" # Run Codex codex
💡 Benefits of Using BeeHears

Through BeeHears integration, you can access the latest models like GPT-6 Astra, GPT-6 Sol, and enjoy unified billing and multi-model switching capabilities.

⚠️ Notice for Windows Users

Windows support is currently experimental. We recommend using Codex in a WSL2 workspace for the best experience.

Install WSL2

PowerShell (Administrator)
# Install WSL wsl --install # After restart, open WSL terminal to continue

Install Node.js in WSL

WSL Terminal
# Install Node.js curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs # Verify node --version

Install Codex CLI

WSL Terminal
# Install globally npm install -g @openai/codex # Run codex

Configure API Key

WSL Terminal
export OPENAI_BASE_URL="https://api.beehears.com/v1" export OPENAI_API_KEY="your-api-key-here" codex

Install via npm

Terminal
# Install Node.js (if not installed) curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs # Install Codex CLI npm install -g @openai/codex # Verify installation codex --version

Configure API Key

Terminal
# Set environment variables export OPENAI_BASE_URL="https://api.beehears.com/v1" export OPENAI_API_KEY="your-api-key-here" # Run codex
💡 Permanent Configuration

Add environment variables to ~/.bashrc or ~/.zshrc for permanent configuration.

🚀 Basic Usage

Start an Interactive Session

Terminal
cd /path/to/project codex

Common Commands

  • codex - Start an interactive TUI session
  • codex "your prompt" - Send a prompt directly
  • /model - Switch models (GPT-6 Astra, GPT-6 Sol, etc.)
  • /help - View help information

Key Features

  • Code Review - Get code reviews before committing or pushing
  • Image Input - Attach screenshots or design specifications
  • Web Search - Get latest information from the web
  • Sub-agents - Handle complex tasks in parallel
  • MCP Support - Integrate third-party tools via Model Context Protocol

Approval Modes

Codex offers multiple approval modes to control its behavior before editing files or running commands:

  • suggest - Only suggest changes (default)
  • auto-edit - Automatically edit files
  • full-auto - Fully automatic mode

🔄 Upgrade

Terminal
# Upgrade to the latest version npm install -g @openai/codex@latest