Quick reference for codex โ OpenAI's AI coding agent for the terminal. Install: npm install -g @openai/codex ยท Run: codex to start.
| Command | Explanation | Typical Usage |
|---|---|---|
| codex | Start an interactive session in the current directory | Beginning a coding session โ Codex reads your files and waits for instructions |
| codex "prompt" | Run a one-shot prompt and exit โ no interactive session | Quick tasks from the shell: codex "add error handling to server.py" |
| codex -a auto-edit | Auto-apply file edits without asking; still prompts before running shell commands | Faster editing sessions where you trust the changes but still want shell control |
| codex -a full-auto | Fully autonomous โ applies edits and runs commands without prompting | CI pipelines, sandboxed environments, or tasks you've already reviewed the approach for |
| Command | Explanation | Typical Usage |
|---|---|---|
| /resume | Reload a previously saved session โ picks up context, files, and conversation history | Continuing work from a previous day or after closing the CLI mid-task |
| /compact | Summarises conversation history to free up context while keeping the working thread | Session is getting long but the task isn't done โ preserve context without starting over |
| /plan | Enter planning mode โ Codex proposes an execution strategy and waits for approval before acting | Before a risky or multi-step task; when you want to review the approach before anything is touched |
| /status | Display current session config: model, approval mode, and token usage | Quick check on what model you're using or how much context has been consumed |
| /new | Start a fresh task in the same CLI instance โ clears conversation without restarting the process | Moving to a completely unrelated task without closing and reopening the terminal |
friendly, pragmatic, or neutral
suggest, auto-edit, full-auto
codex-1, o4-mini, o3
AGENTS.md
AGENTS.md entirely
AGENTS.md at your project root to give Codex persistent context โ stack, conventions, commands to know, things to avoid.
AGENTS.md at the start of every session. It's the Codex equivalent of Claude Code's CLAUDE.md.
--project-doc <path> to load a different file, or --no-project-doc to skip it entirely.
codex -m o3 "prompt" or set a default in ~/.codex/config.yaml.
OPENAI_API_KEY as an environment variable, or add it to ~/.codex/config.yaml.
~/.codex/config.yaml โ set your default model, approval mode, and other preferences so you don't have to pass flags every time.
config.yaml:model: codex-1approvalMode: auto-edit
cat file.py | codex -q "add docstrings to every function"
codex -q "generate tests for auth.py" > tests/test_auth.py
codex -q -a full-auto --dangerously-auto-approve-everything "fix lint errors"
auto-edit once you're comfortable, and reserve full-auto for sandboxed CI or pre-reviewed tasks.
Ctrl+C cancels the current operation mid-stream. Codex will not apply partial changes โ you can redirect or refine your prompt and try again.
codex --version and npm update -g @openai/codex regularly to pick up new models and fixes.