Configuration & Customization
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
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)
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"]
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"
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 |
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:
AGENTS.override.md(highest priority — for local overrides, gitignored)AGENTS.md(standard — committed to repo)- Subdirectory
AGENTS.mdfiles (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
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)
Questions & Answers
Key Takeaways
- TOML configuration: Codex uses config.toml (not YAML) — layered from system → user → project → CLI flags
- Two control axes: Approval policies (untrusted/on-request/never/granular) and sandbox modes (read-only/workspace-write/danger-full-access)
- AGENTS.md is your project prompt: Write clear conventions and architecture notes that persist across sessions
- Multi-provider support: Configure OpenAI, Bedrock, or any compatible API endpoint
- Model per task: Use gpt-5.4-mini for quick work and gpt-5.5 for complex reasoning
- 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.