AI Model Wiki

    Skip to main content
    10 min read
    Lesson 1 of 5

    Getting Started with Codex CLI

    From the course OpenAI Codex CLI

    OpenAI Codex CLI is an open-source, lightweight terminal agent for AI-assisted coding. It connects to OpenAI's models to provide code generation, editing, and command execution directly from your terminal.

    Installation

    npm install -g @openai/codex
    export OPENAI_API_KEY=your-key-here
    codex
    

    Key Features

    • Open-source — MIT licensed, community-driven development
    • Lightweight — Minimal dependencies, fast startup
    • Sandboxed — Network-disabled, directory-restricted by default
    • Multi-model — Works with GPT-4o, o3, o4-mini, and other OpenAI models
    • Cross-platform — macOS, Linux, and WSL on Windows

    Approval Modes

    ModeFile EditsCommandsBest For
    SuggestRequires approvalRequires approvalLearning, sensitive code
    Auto-editAutomaticRequires approvalRoutine development
    Full-autoAutomaticAutomaticTrusted automation

    Basic Usage

    # Interactive mode
    codex
    
    # One-shot command
    codex "add input validation to the signup form"
    
    # With specific model
    codex --model o3 "refactor this module"
    
    # Quiet mode (less output)
    codex -q "fix the failing test"
    

    Safety Model

    Codex CLI applies sandboxing by default:

    • Network access disabled in sandbox
    • File access restricted to current directory and children
    • Commands run in isolated environment
    • Full-auto mode applies additional restrictions
    • Review all changes before committing

    Codex CLI in a Real CI Pipeline

    One practical pattern: run Codex CLI in GitHub Actions to auto-fix lint errors on every pull request. The workflow installs the CLI, runs your linter, pipes failures to Codex, and commits the fixes back to the branch — all without human intervention for low-risk style violations.

    # .github/workflows/auto-lint-fix.yml (simplified)
    - name: Run linter and auto-fix
      run: |
        npm run lint 2>&1 | codex -q --model o4-mini       "Fix all ESLint errors shown in stdin. Only modify formatting,       do not change logic." --allowedTools edit
    

    Keep the model at o4-mini for this task — it is fast, cheap, and more than capable of formatting fixes. Reserve o3 for architectural decisions.

    Best Practice — Commit Codex Changes Separately

    When Codex makes edits in auto-edit mode, stage and commit them as a discrete "chore: AI-assisted refactor" commit rather than mixing them with your own manual changes. This makes the diff reviewable, keeps blame history clean, and gives you a clear rollback point if the AI introduced a subtle regression.

    Common Pitfall — Running in Full-Auto on Shared Branches

    Full-auto mode executes shell commands without prompting. Never run it on a branch that other people are actively working on — a runaway command could delete build artefacts or overwrite files mid-pipeline. Use full-auto only on isolated feature branches or disposable worktrees.

    Key Takeaways

    • •Codex CLI is open-source (MIT) and lightweight for terminal-based AI coding
    • •Three approval modes: suggest, auto-edit, and full-auto
    • •Sandboxed by default for safety — no network, restricted directory access
    • •Supports multiple OpenAI models including GPT-4o and o3
    0 of 5 lessons marked complete

    Progress is kept in this browser only.