Two entry commands: codex and codex exec
After installation you have two ways to launch Codex, each suited to a different scenario:
| Command | Mode | Best for |
|---|---|---|
codex |
Interactive terminal UI | Daily development, codebase exploration, multi-turn conversations |
codex exec |
Non-interactive (single run) | Shell scripts, CI/CD pipelines, batch automation |
codex (no subcommand) opens a full-screen terminal interface where you can have multi-turn conversations with the AI, review file diffs, and use all the slash commands described below.
codex exec requires no interaction at all — pass the task as an argument, Codex completes it and exits with a meaningful exit code, making it easy to check success or failure in a script.
Slash commands (/model, /init, etc.) are only available inside the codex interactive UI. They are not supported in codex exec. To control behavior in non-interactive mode, use CLI flags or config.toml.
Common CLI flags
Below are the most frequently used flags. The full list of command-line options is documented in the official Codex CLI reference:
# Check the currently installed version
$ codex --version
# Choose a model for this session (works in both interactive and exec mode)
$ codex --model gpt-4o
$ codex exec --model gpt-4o "add JSDoc comments to every function in src/utils.js"
The --model <id> flag takes a model ID string and takes precedence over the model field in ~/.codex/config.toml. For a permanent change, edit the config file; for a one-off test, the flag is quicker.
The official docs list more command-line options than covered here. This guide intentionally stays minimal to avoid stale information. Use codex --help or the official repository README for the full, up-to-date flag reference.
Slash commands cheat sheet
In the composer input at the bottom of the Codex interactive UI, type / to open the command picker. Continue typing to filter, then press Enter to run.
| Command | What it does |
|---|---|
/model |
Switch the model mid-session without restarting |
/approvals or /permissions |
Adjust what Codex is allowed to do without asking you first (approval policy) |
/init |
Scan the current project directory and generate an AGENTS.md draft |
/status |
Show current session status — connection, model, context usage |
/feedback |
Capture request IDs and logs and send feedback to OpenAI for issue tracking |
/fast |
Switch to a faster response mode |
/personality |
Adjust the AI's reply style and personality |
/agent |
Manage agent-related settings |
/raw |
Toggle raw output mode — shows unformatted model responses |
The three you'll reach for most often are /model (swap models on the fly), /permissions (tune the approval policy), and /init (bootstrap project memory). The rest are situational.
Approval policy & sandbox modes
Codex's safety system has two independent layers: the approval policy controls when Codex must ask before acting; the sandbox mode controls what Codex is technically allowed to do at the OS level.
Sandbox modes
| Sandbox mode | What it allows | Typical use |
|---|---|---|
read-only |
Read access only — no file writes, no command execution | Code review, pure analysis tasks |
workspace-write |
Default. Read files, edit files within the workspace, run routine local commands. Cannot touch anything outside the workspace. | Day-to-day development, the vast majority of tasks |
danger-full-access |
No restrictions — all sandbox guardrails removed | Installing global packages, modifying system config. Use with care. |
danger-full-access removes all technical limits — Codex can execute any system operation. Only enable it when you genuinely need it, and make sure you understand what the AI is about to do before confirming.
Approval policy
The approval policy decides whether Codex prompts you before taking action. Use /permissions (or /approvals) in an interactive session to tune it on the fly. The default setup — workspace-write sandbox — is designed to be low-friction: Codex only asks when an action would reach outside the workspace. Use /permissions to tighten or loosen this at any time.
Using codex exec in scripts
codex exec lets you embed AI coding capabilities into any shell script or CI pipeline with no human in the loop. Here are practical examples to get you started:
# Simplest form: pass a task, Codex runs and exits
$ codex exec "add JSDoc comments to every function in src/utils.js"
# Specify a model for this run
$ codex exec --model gpt-4o "check package.json dependencies for known security vulnerabilities"
#!/bin/bash
# Automatically draft a changelog entry in CI
set -e
# Make sure the API key is available
if [ -z "$OPENAI_API_KEY" ]; then
echo "Error: OPENAI_API_KEY is not set"
exit 1
fi
# codex exec exits non-zero on failure; set -e stops the script automatically
codex exec "Based on git diff HEAD~1, write a concise CHANGELOG entry for this commit and append it to CHANGELOG.md"
echo "CHANGELOG updated successfully"
- No approval prompts:
codex execis non-interactive by design — it never pauses to ask for confirmation, making it safe to use in unattended automation. - Reliable exit codes: Exit code
0means success; non-zero means failure. Useset -eor check$?in your scripts. - Inject secrets via environment variables: Pass
OPENAI_API_KEYthrough your CI provider's secrets mechanism — never hard-code it in your scripts. - Pair with AGENTS.md: If you generate an
AGENTS.mdupfront (using/initin interactive mode),codex execwill also read it and understand your project conventions.
AGENTS.md: persistent project memory
AGENTS.md is a Markdown file placed in your project root. Codex reads it automatically every time it starts, treating it as background context for every conversation. Write anything you want Codex to always know: project summary, tech stack, directory layout, code style conventions, commands to avoid, and so on.
The /init slash command scans your current directory structure and generates a draft AGENTS.md to get you started. Edit it from there.
# Type this in the Codex composer input:
/init
Frequently asked questions
Does codex exec support slash commands?
No. Slash commands are a feature of interactive mode. codex exec accepts the task as a command-line argument and does not support /model, /init, or any other slash commands. To select a model in exec mode, use the --model flag instead.
What exactly does /feedback send?
/feedback captures your session's request IDs and connection logs — not your code content — and sends them to OpenAI to help diagnose issues. If you hit an unexplained bug or performance problem, running /feedback is the fastest way to report it.
Can I make Codex stop asking for confirmation on every action?
Yes. Use /permissions (or /approvals) in an interactive session to adjust the approval policy and lower the confirmation threshold. For fully automated pipelines, codex exec is the better choice — it never shows interactive confirmation prompts.
What should I put in AGENTS.md?
Anything you want Codex to remember about your project: a short description, the tech stack, directory structure notes, code style rules, the commands used to build/test/lint, and any files that should never be modified. The more specific you are, the more reliably Codex follows your conventions.