Codex CLI
Install OpenAI's autonomous coding agent and try it out
What is Codex CLI?
Codex CLI is OpenAI’s command-line coding agent. It’s designed for autonomous task execution — you assign it a task, and it plans, implements, tests, and iterates until the job is done.
Key features:
- Autonomous multi-step task execution
- Can create branches, make changes, and iterate
- Sandboxed execution for safety
- Built on OpenAI’s latest models
- Open source
Installation
Step 1: Install Codex CLI
npm install -g @openai/codexVerify:
codex --versionStep 2: Set up your API key
- Go to platform.openai.com
- Create an account or sign in
- Navigate to API Keys
- Create a new secret key
- Set it as an environment variable:
export OPENAI_API_KEY="your-key-here"To make this permanent, add the export line to your shell config:
echo 'export OPENAI_API_KEY="your-key-here"' >> ~/.bashrcsource ~/.bashrc(If your shell is zsh — check with echo $SHELL — use ~/.zshrc instead.)
Never commit your API key to a git repository or share it publicly. Treat it like a password. If you accidentally expose it, revoke it immediately from the OpenAI dashboard and create a new one.
Your first interaction
Step 1: Create a project folder
mkdir hello-codex && cd hello-codexStep 2: Start Codex CLI
codexStep 3: Give it a task
Create a simple to-do list app in a single HTML file. It should:- Let users type a task and press Enter to add it- Show tasks in a list with checkboxes to mark as done- Have a "Clear completed" button- Dark theme, clean design- Save tasks to localStorage so they persist on refreshCodex will:
- Plan the implementation
- Create the file
- Write the code
- Verify it meets requirements
Step 4: Check the result
lscat index.htmlOpen in your browser to test the todo list functionality.
Codex CLI modes
Codex CLI offers different autonomy levels:
| Mode | What it does | Best for |
|---|---|---|
| Suggest | Shows proposed changes, asks for approval | Learning, careful work |
| Auto-edit | Makes file changes automatically, asks before commands | General use |
| Full auto | Executes everything autonomously | When you trust the task |
Start with Suggest mode while learning, then move to Auto-edit as you get comfortable.
Tips
-
Be specific about requirements. Codex excels when you give it a clear, well-defined task. The more specific your instructions, the better the result.
-
Start with small tasks. Build confidence with simple, single-file tasks before trying multi-file projects.
-
Use the sandbox. Codex runs in a sandboxed environment for safety. This means it can’t accidentally harm your system, making it safe to experiment with.
-
Review before accepting. In Suggest mode, Codex shows you what it wants to do before doing it. Use this to learn what good code looks like.