Quickstart
This guide will help you get Codex CLI running and execute your first commands. You’ll go from installation to your first AI-powered task in just a few minutes.Before you begin
Make sure you have:- Codex CLI installed (see Installation)
- A ChatGPT account (Plus, Pro, Team, Edu, or Enterprise) or an OpenAI API key
- A terminal running macOS 12+, Linux (Ubuntu/Debian), or Windows 11 with WSL2
Get started with Codex
Sign in with ChatGPT
Run When you run this command, Codex will:On a remote or headless machine? Use device code authentication instead:Alternatively, you can use an API key (see Authentication for details).
codex and select Sign in with ChatGPT. This is the recommended method for using Codex with your ChatGPT plan.- Start a local login server on
http://localhost(random port) - Open your browser to authenticate
- Complete authentication and return to the terminal
We recommend signing into your ChatGPT account to use Codex as part of your Plus, Pro, Team, Edu, or Enterprise plan. Learn more about what’s included in your ChatGPT plan.
Run your first command
Once authenticated, run Codex interactively:Or provide a prompt directly:Codex will analyze your project and provide an explanation.
Understanding approval modes
Codex operates in three approval modes that control how much autonomy the agent has:Suggest
Default modeCodex reads files and suggests changes. You approve all file writes and shell commands.
Auto Edit
Codex reads and writes files automatically. You approve shell commands.Use:
codex --approval-mode auto-editFull Auto
Codex reads, writes files, and executes commands autonomously. Everything runs in a sandbox.Use:
codex --approval-mode full-autoExample workflows
Here are some common tasks you can ask Codex to perform:Refactor code
Refactor code
- Read the component file
- Rewrite it using React Hooks
- Run tests to verify the changes
- Show you a diff of the changes
Generate tests
Generate tests
- Analyze the
date.tsfile - Generate comprehensive unit tests
- Execute the tests
- Iterate until they pass
Create a full application
Create a full application
- Scaffold the project structure
- Install dependencies
- Write the application code
- Run it in the sandbox
- Show you the live result
Fix errors
Fix errors
- Run the TypeScript compiler
- Identify all type errors
- Fix them one by one
- Verify the fixes compile
Interactive vs non-interactive mode
Interactive mode (default) Runcodex to start an interactive REPL session:
Passing images
Codex is multimodal and can understand images. Pass screenshots or diagrams:Next steps
Learn about authentication
Explore all authentication methods and configuration options
Core concepts
Understand approval modes, sandboxing, and security model
Configuration
Customize Codex with config files and environment variables
CLI reference
Explore all available commands and options