Headless runs

One-shot prompt

codex exec "summarize this repo"

Runs one prompt non-interactively. Prints the final agent message to stdout. See non-interactive mode.

Review a diff

git diff | codex exec "review this diff"

Reviews a diff from stdin. Pipes the diff as additional context; progress goes to stderr. See non-interactive mode.

JSON events

codex exec --json "list failing tests"

Streams machine-readable events. Emits JSONL for scripts, including thread and turn events. See non-interactive mode.

Save the final message

codex exec -o summary.md "summarize this repo"

Saves the final message. Writes it to a file; runs are read-only unless --sandbox workspace-write is set. See non-interactive mode.

0 Comments for this cheatsheet. Write yours!