Exec and Automation
Use Codex exec for non-interactive scripts, CI checks, and structured automation.
Key takeaways
- Use
codex execwhen a task is repeatable, scoped, and should produce structured evidence: dependency audits, doc checks, refactor plans, CI helpers, and batch reviews. - Keep prompts deterministic, pin model, permissions, and working directory, and prefer JSON or line-oriented output when scripts consume the result.
- Log query time, sources, and network policy whenever automation depends on code-mode web search for fresh evidence.
- Pin
--cdand artifact directories for image flows, and validate app-server v2 clients with a smoke test likecodex debug app-server send-message-v2 --help. - Never let
execmake production-impacting changes automatically, and verify cloud exec provider behavior separately from localcodex exec.
Interactive Codex is useful for exploration. exec is useful when the task is repeatable, scoped,
and should produce structured evidence.
Good Exec Use Cases
| Use case | Expected output |
|---|---|
| Dependency audit | Findings, affected files, recommended fix |
| Documentation check | Missing pages, broken links, metadata gaps |
| Refactor planning | Change list, risk, verification plan |
| CI helper | Machine-readable result and concise summary |
| Batch review | Per-file findings with severity |
Automation Rules
- Keep prompts deterministic and scoped.
- Pin model, permissions, and working directory where practical.
- Prefer JSON or line-oriented output when consumed by scripts.
- Fail clearly when required context is missing.
- Archive outputs that support later review.
Current CLI Notes
- Code mode can call standalone web search directly, including from nested JavaScript tool calls. Automation that depends on fresh web evidence should log query time, sources, and network policy.
codex exec --imageand app/CLI image attachment flows now expose saved local file paths more reliably, so screenshot-based automation should pin--cdand artifact directories.- App-server integrations can read account token usage, and CLI/app-server auth supports ChatGPT v2 personal access tokens.
- Include
codex debug app-server send-message-v2 --helpor an equivalent smoke test when validating internal app-server v2 clients. - Plugin automation should consume
codex plugin add/remove --json,codex plugin list --available --json, and marketplace JSON outputs for audit logs. - Cloud exec provider behavior should be verified separately from local
codex exec; do not assume identical permissions or environment requirements.
Anti-Patterns
- Running broad write tasks without an owner.
- Letting
execmake production-impacting changes automatically. - Treating generated summaries as verification without tests or diffs.