Configuration & Customization

40 min intermediate Lesson 8

Learning Outcomes

  • Create and manage Codex CLI configuration files in TOML format
  • Configure approval policies and sandbox modes to match your workflow
  • Select and switch between models for different task types
  • Set up multiple providers (OpenAI, Bedrock, compatible APIs)
  • Write AGENTS.md files for project-specific AI instructions
NOTE
Tool Version
This lesson covers Codex CLI v0.136+. Configuration format migrated from YAML to TOML in v0.134. Legacy YAML configs are rejected — see the migration section if upgrading.

Lesson Plan

Segment Duration Topic
Intro 3 min Why customize — one size doesn't fit all
Demo 1 8 min Configuration file locations and TOML structure
Demo 2 7 min Approval policies and sandbox settings
Demo 3 7 min Model selection and provider configuration
Explain 5 min AGENTS.md — project instructions
Demo 4 6 min Profiles and team configs
Wrap-up 4 min Recommended configurations for common workflows

Before You Begin

Pre-work:

  • Complete Lesson 7 — Testing with Codex
  • Have experience running at least 10-15 Codex sessions
  • Know your preferred workflow patterns (fast/automatic vs careful/manual)

Shopping List:

  • Codex CLI installed and configured
  • A text editor for editing config files
  • An existing project where you want custom settings
  • Authentication configured (ChatGPT account or API key)

1 Configuration File Locations

Codex CLI uses a layered configuration system in TOML format where project-level settings override user-level settings. Understanding where configs live helps you customize at the right level.

Configuration hierarchy (highest priority first):

Level Location Scope
Command-line flags codex --model gpt-5.4 Current invocation only
Project config .codex/config.toml in project root This project
User config ~/.codex/config.toml All projects
System config /etc/codex/config.toml Machine-wide defaults
Built-in defaults Compiled into Codex CLI Fallback values

User-level config location:

# Create the user config directory if it doesn't exist
mkdir -p ~/.codex

# Create or edit the user config
nano ~/.codex/config.toml

Project-level config location:

# Create a project-level config
mkdir -p .codex
nano .codex/config.toml

User-level config location:

# Create the user config directory
mkdir -p ~/.codex

# Create or edit the user config
notepad ~/.codex/config.toml

Project-level config location:

# Create a project-level config
mkdir -p .codex
notepad .codex/config.toml

Basic config structure:

# ~/.codex/config.toml
model = "gpt-5.5"
approval_policy = "untrusted"
sandbox_mode = "workspace-write"

Project-specific override:

# .codex/config.toml (in your project root)
model = "gpt-5.4"
approval_policy = "on-request"

[context]
include = ["src/", "tests/"]
exclude = ["node_modules/", "dist/", "*.min.js"]
NOTE
How It Works
Codex reads configs on startup, starting with defaults, then layering system → user → project → command-line flags. Later layers override earlier ones for the same key.
TIP
Tip
Put project-level configs in version control (.codex/config.toml). This way, all team members get the same Codex behavior for the project.

2 Approval Policies and Sandbox Settings

Codex CLI separates approval policy (what needs human confirmation) from sandbox mode (what the OS physically allows). Configure both independently.

Approval policies:

# Options: "untrusted", "on-request", "never", "granular"
approval_policy = "untrusted"
Policy File Writes Shell Commands Best For
untrusted Requires approval Requires approval Learning, sensitive code
on-request Automatic Requires approval Trusted edits, faster workflow
never Automatic Automatic CI/CD, automation
granular Per-tool configuration Per-tool configuration Fine-grained control

Granular policy (advanced):

approval_policy = "granular"

[approval_policy_config]
file_write = "auto"      # Options: auto, prompt, approve
shell_command = "prompt"  # Options: auto, prompt, approve
file_delete = "approve"   # Always confirm destructive ops

Sandbox modes:

# Options: "read-only", "workspace-write", "danger-full-access"
sandbox_mode = "workspace-write"
Mode File Access Network Use Case
read-only Read only, no writes Blocked Code exploration, Q&A
workspace-write Read/write in project Blocked Default development
danger-full-access Unrestricted Allowed Installing deps, CI/CD

Command-line overrides:

# Override for a single session
codex --approval-policy on-request --sandbox workspace-write

# Common shortcut for full autonomy (deprecated but still works with warning)
codex --full-auto "Generate boilerplate"
WARNING
Watch Out
The `--full-auto` flag is a deprecated compatibility path that prints a warning. Use `--approval-policy never --sandbox danger-full-access` for the same effect with explicit intent.
TIP
Tip
A good default: set user-level config to 'untrusted' + 'workspace-write' and override per-project only for repos where you've verified it's safe.

3 Model Selection and Providers

Different models offer different trade-offs between capability, speed, and cost. Codex CLI supports multiple providers beyond OpenAI.

Available OpenAI models:

Model Strengths Best For
gpt-5.5 Newest frontier model, strongest reasoning Complex architecture, multi-file analysis
gpt-5.4 Flagship model, excellent all-rounder General development, debugging
gpt-5.4-mini Fast, affordable Quick edits, boilerplate, explanations
gpt-5.3-codex Coding-optimized Code generation, refactoring

Setting the default model:

# In config.toml
model = "gpt-5.5"

Switching models per session:

# Launch with a specific model
codex --model gpt-5.4 "Architect a microservices pattern"

# In interactive mode
codex --model gpt-5.4-mini

Switching mid-session:

> /model gpt-5.4
Model switched to: gpt-5.4

Configuring additional providers:

Codex CLI works with any provider supporting the Chat Completions or Responses API:

# ~/.codex/config.toml

# Default provider (OpenAI via ChatGPT auth)
model = "gpt-5.5"

# Additional providers
[[providers]]
name = "bedrock"
base_url = "https://bedrock-runtime.us-east-1.amazonaws.com"
env_key = "AWS_ACCESS_KEY_ID"

[[providers]]
name = "custom"
base_url = "http://localhost:8080/v1"
env_key = "LOCAL_API_KEY"

Using an alternate provider:

codex --provider bedrock --model anthropic.claude-sonnet "Explain this code"

Model selection strategy:

Task Type Recommended Model
Simple file edits, typo fixes gpt-5.4-mini
Code generation, boilerplate gpt-5.4-mini
Complex debugging, multi-file analysis gpt-5.5
Architecture and design decisions gpt-5.5
Test generation gpt-5.4-mini
Refactoring with reasoning required gpt-5.4
NOTE
How It Works
Model selection only affects the AI reasoning — the sandbox, file access, and approval policies work identically regardless of model. A more capable model produces better suggestions, but the safety layers remain the same.
TIP
Tip
Start tasks with gpt-5.4-mini. If the results aren't good enough (wrong approach, missing nuance), switch to gpt-5.5 and re-ask. This keeps costs low while ensuring quality when it matters.

4 AGENTS.md — Project Instructions

The AGENTS.md file is the primary way to give Codex project-specific context and rules. It lives at your project root and is automatically read at the start of every session.

Basic AGENTS.md:

# Project: PaymentService

This is a Node.js + TypeScript payment processing service.

## Conventions
- Use TypeScript strict mode
- Follow camelCase for variables, PascalCase for types
- Test files go next to source files with .test.ts extension
- Never modify files in src/generated/ — they are auto-generated

## Architecture
- src/api/ — HTTP handlers
- src/services/ — Business logic
- src/models/ — Database models
- src/generated/ — Auto-generated types (DO NOT EDIT)

## Commands
- `npm run lint` — Run after editing TypeScript files
- `npm test` — Run tests
- `npm run build` — Build for production

Discovery hierarchy:

Codex reads AGENTS.md files from the root down, with closer files taking priority:

  1. AGENTS.override.md (highest priority — for local overrides, gitignored)
  2. AGENTS.md (standard — committed to repo)
  3. Subdirectory AGENTS.md files (scoped to that directory)

Size limit: AGENTS.md content is capped at 32 KiB by default. Keep it concise.

Personal overrides without polluting the repo:

# Create a personal override (add to .gitignore)
echo "AGENTS.override.md" >> .gitignore
<!-- AGENTS.override.md -->
# Personal preferences
- I prefer verbose explanations
- Always suggest tests alongside new code
- Use my preferred import style: named imports only

When AGENTS.md is most valuable:

  • Large projects where conventions aren't obvious from the code
  • Teams with specific style guides
  • Projects with auto-generated code that shouldn't be touched
  • Repos with non-standard build/test commands
TIP
Tip
The AGENTS.md file is essentially a system prompt for your project. Invest time in writing a good one — it pays off in every Codex session by reducing repeated instructions.
WARNING
Watch Out
Don't put secrets in AGENTS.md — its content is sent to the API with every request. Keep sensitive information in environment variables or files excluded from context.

5 Profiles and Team Configuration

For teams and users working across multiple contexts, Codex supports configuration profiles.

Named profiles:

# ~/.codex/work.config.toml — work profile
model = "gpt-5.5"
approval_policy = "untrusted"
sandbox_mode = "workspace-write"
# ~/.codex/personal.config.toml — personal projects
model = "gpt-5.4-mini"
approval_policy = "on-request"
sandbox_mode = "workspace-write"

Using profiles:

# Launch with a specific profile
codex --config ~/.codex/work.config.toml

Recommended team configuration:

# .codex/config.toml — committed to repo
approval_policy = "untrusted"
sandbox_mode = "workspace-write"

[context]
exclude = [
  "node_modules/",
  "dist/",
  "coverage/",
  "src/generated/",
  "*.lock",
  ".env*"
]

Multiple project configs:

project-api/
  .codex/config.toml      → on-request, gpt-5.4-mini, Node.js
  AGENTS.md               → API conventions

project-ml/
  .codex/config.toml      → untrusted, gpt-5.5, Python
  AGENTS.md               → ML conventions

sandbox/
  .codex/config.toml      → never + danger-full-access
  AGENTS.md               → "This is a sandbox, go wild"

Verifying your configuration:

> /model
Current model: gpt-5.5

> What configuration are you currently running with?

Migrating from legacy YAML config:

If you're upgrading from an older Codex version with config.yaml:

# The old format
# model: o4-mini
# approval_mode: suggest

# Convert to new format (config.toml)
model = "gpt-5.5"
approval_policy = "untrusted"
sandbox_mode = "workspace-write"

Key renames:

  • approval_mode: suggest → approval_policy = "untrusted"
  • approval_mode: auto-edit → approval_policy = "on-request"
  • approval_mode: full-auto → approval_policy = "never" + sandbox_mode = "danger-full-access"
  • model: o4-mini → model = "gpt-5.4-mini" (or your preferred model)
  • model: o3 → model = "gpt-5.5" (or equivalent tier)
NOTE
How It Works
Codex v0.134+ explicitly rejects legacy YAML configs with a migration guide. If you see a config format error on startup, convert your config.yaml to config.toml using the mapping above.
TIP
Tip
Add .codex/config.toml to your repo's README: 'This project uses Codex CLI — see .codex/config.toml for AI settings and AGENTS.md for project instructions.' This helps onboard new team members.

Questions & Answers

Q: Can I have different configs for different branches?
Since .codex/config.toml is a regular file in your repo, it follows git branches. You could have a different config on a feature branch vs main — though this is rarely needed. A more common pattern is using AGENTS.override.md for personal preferences that don't get committed.
Q: Does AGENTS.md count against the model's context window?
Yes — AGENTS.md content (up to 32 KiB) is included in every API call. Keep it concise and focused on rules rather than verbose explanations. A good target is a page or two of clear, actionable rules and project structure.
Q: How do I reset to default settings?
Remove or rename your config files. Codex falls back to built-in defaults when no config file is found. You can also override any setting with command-line flags for a single session.
Q: Can team members use different models while sharing other settings?
Yes. The project config (shared via git) can set approval policy, sandbox mode, and context rules while leaving the model unspecified. Each developer sets their preferred model in their personal user config (~/.codex/config.toml). User-level model setting is overridden only if the project config explicitly sets a model.

Key Takeaways

  1. TOML configuration: Codex uses config.toml (not YAML) — layered from system → user → project → CLI flags
  2. Two control axes: Approval policies (untrusted/on-request/never/granular) and sandbox modes (read-only/workspace-write/danger-full-access)
  3. AGENTS.md is your project prompt: Write clear conventions and architecture notes that persist across sessions
  4. Multi-provider support: Configure OpenAI, Bedrock, or any compatible API endpoint
  5. Model per task: Use gpt-5.4-mini for quick work and gpt-5.5 for complex reasoning
  6. Profiles for context-switching: Named config files let you switch between work/personal/experimental setups

Next Steps: In Lesson 9 — Integration Workflows, you'll learn how to combine Codex CLI with git, CI/CD systems, and IDE workflows.