exec and review commands for headless execution.
The exec command
Run a one-off task without the interactive TUI:Output formats
By default,exec provides human-readable output with progress indicators. For programmatic use, enable JSON output:
Exit codes
codex exec returns meaningful exit codes for automation:
Command options
The review command
Request an automated code review from Codex:Review targets
The review command supports multiple targets:- Uncommitted
- Commit
- Base branch
- Custom
Review staged, unstaged, and untracked files:
Review output
Reviews produce structured feedback:Resume and continue
Non-interactive mode supports resuming previous sessions:CI/CD integration
Codex is designed to integrate seamlessly into automated workflows.GitHub Actions
GitLab CI
.gitlab-ci.yml
Jenkins
Jenkinsfile
Structured output
Constrain the agent’s response to a specific JSON schema:Ephemeral sessions
Run without persisting to disk:- One-off queries
- Sensitive data that shouldn’t be logged
- Reducing disk I/O in high-volume scenarios
Automation best practices
1
Use --full-auto for trusted environments
In sandboxed CI runners, use
--full-auto to auto-approve operations:2
Enable JSON output for parsing
Always use
--json in automation to get structured events:3
Check exit codes
Handle failures gracefully in scripts:
4
Capture final output
Use
--output-last-message for the agent’s final response:Parsing JSONL output
Using jq
Using Python
Next steps
Interactive mode
Learn about the TUI for development
Sandboxing
Understand security in automation