Codex CLI
Run OpenAI Codex CLI locally for second-opinion audits, code review, and non-interactive task execution.
Prerequisites
Codex CLI must be installed and authenticated:
- Install:
npm install -g @openai/codex - Auth:
codex login - Verify:
codex --version
Core Execution Pattern
Use codex exec for delegated prompts (non-interactive):
codex exec "Your prompt here"
When the user says "codex prompt", treat it as:
codex exec "<user prompt>"
Model Guidance
Use the default configured model unless the user asks otherwise.
Latest tested working model in this environment:
codex exec -m gpt-5.3-codex "Your prompt"
Compatibility note:
gpt-5-codexmay fail if config usesmodel_reasoning_effort = "xhigh".- If you must use
gpt-5-codex, set reasoning effort explicitly:
codex exec -m gpt-5-codex -c model_reasoning_effort="high" "Your prompt"
Commands
Non-Interactive Execution
# Basic task
codex exec "Audit this logic for edge cases"
# Explicit model
codex exec -m gpt-5.3-codex "Review this implementation strategy"
# Full-auto mode (sandboxed, lower friction)
codex exec --full-auto "Implement the requested refactor"
# Read-only sandbox (analysis only)
codex exec -s read-only "Find bugs in this code path"
# Workspace-write sandbox
codex exec -s workspace-write "Apply the fix and update tests"
# Custom working directory
codex exec -C /path/to/project "Evaluate this repository"
# Save final output to file
codex exec -o output.txt "Summarize key risks"
# JSONL event stream
codex exec --json "Produce structured findings"
# Pipe context from stdin
cat context.txt | codex exec -
Code Review
Use codex review for repository diffs:
# Review uncommitted changes
codex review --uncommitted
# Review against a base branch
codex review --base main
# Review a specific commit
codex review --commit abc123
# Custom review instructions
codex review "Focus on security issues"
# Combined
codex review --base main "Check for performance regressions"
Important Flag Placement
--search and -a/--ask-for-approval are top-level flags. Put them before exec or review.
Correct:
codex --search -a on-request exec "Your prompt"
codex --search -a on-request review --uncommitted
Avoid:
codex exec --search "Your prompt"
codex exec -a on-request "Your prompt"
Useful Flags
| Flag | Description |
|---|---|
-m |
Model (recommended explicit example: gpt-5.3-codex) |
-s |
Sandbox: read-only, workspace-write, danger-full-access |
-a |
Approval policy (untrusted, on-failure, on-request, never) as a top-level flag |
-C |
Working directory |
-o |
Write last message to file |
--full-auto |
Sandboxed auto-execution (-a on-request -s workspace-write) |
--json |
JSONL event output |
--search |
Enable web search tool as a top-level flag |
--add-dir |
Additional writable directories |
-c key=value |
Override config (example: -c model_reasoning_effort="high") |
Best Practices
- Prefer
codex execfor delegated prompts instead of interactivecodex - Start with
-s read-onlyfor audits and second opinions - Use
--full-autoonly when you expect autonomous edits - Keep prompts explicit about expected output format
- Add
-owhen another tool or agent must consume the result - Run
codex review --uncommittedbefore committing as a quick extra pass