When to use non-interactive mode
codex exec fits repeatable analysis, controlled generation, and CI checks. Inputs should be stable, outputs machine-consumable, and permissions stricter than in a human-driven session.
codex exec "Review the current diff. Return only actionable findings with severity, file, and line. Do not edit files."
Design observable automation
- Pin the working directory and repository revision.
- Declare the output format and success criteria.
- Keep secret-free logs and propagate failure codes.
- Add time, cost, and retry limits.
Do not publish directly
In CI, begin by producing a reviewable report or patch. Merges, deployments, and external comments require clear rules and a service identity with minimal permissions.
Exercise
Create a local script that reviews the diff and stores a report. Test it with one good change and one defective change. Confirm that failure is visible and the working tree remains untouched.