Building Module 6 · CLI Tools Setup

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

Terminal window
npm install -g @openai/codex

Verify:

Terminal window
codex --version

Step 2: Set up your API key

  1. Go to platform.openai.com
  2. Create an account or sign in
  3. Navigate to API Keys
  4. Create a new secret key
  5. Set it as an environment variable:
Terminal window
export OPENAI_API_KEY="your-key-here"

To make this permanent, add the export line to your shell config:

Terminal window
echo 'export OPENAI_API_KEY="your-key-here"' >> ~/.bashrc
source ~/.bashrc

(If your shell is zsh — check with echo $SHELL — use ~/.zshrc instead.)

Keep your API key safe

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

Terminal window
mkdir hello-codex && cd hello-codex

Step 2: Start Codex CLI

Terminal window
codex

Step 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 refresh

Codex will:

  1. Plan the implementation
  2. Create the file
  3. Write the code
  4. Verify it meets requirements

Step 4: Check the result

Terminal window
ls
cat index.html

Open in your browser to test the todo list functionality.

Codex CLI modes

Codex CLI offers different autonomy levels:

ModeWhat it doesBest for
SuggestShows proposed changes, asks for approvalLearning, careful work
Auto-editMakes file changes automatically, asks before commandsGeneral use
Full autoExecutes everything autonomouslyWhen you trust the task

Start with Suggest mode while learning, then move to Auto-edit as you get comfortable.

Tips

  1. Be specific about requirements. Codex excels when you give it a clear, well-defined task. The more specific your instructions, the better the result.

  2. Start with small tasks. Build confidence with simple, single-file tasks before trying multi-file projects.

  3. 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.

  4. 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.