Session 9
Scripting & CI: codex exec
Goal. Run Codex non-interactively so it fits into scripts and CI pipelines.
- 1
codex exec "…"runs Codex without the interactive TUI — e.g.codex exec "summarize the repository structure and list the top 5 risky areas". It streams progress to stderr and prints only the final message to stdout, so you can pipe it:codex exec "generate release notes for the last 10 commits" | tee release-notes.md. - 2Useful flags:
--json(machine-readable stream),--output-schema(structured JSON to a schema),-o(write the result to a file),--sandbox workspace-write(allow edits, safer than full access). - 3For GitHub Actions, use the official Codex Action rather than handling API keys yourself.
You'll see. Codex running headless in a script — producing release notes or a risk summary you redirect straight to a file.
Cost. Each codex exec is its own run and bills like any task; keep the prompt focused for CI.
Takeaway. codex exec turns Codex into a scriptable command — perfect for CI jobs, batch tasks, and piping output into other tools.