Save the final answer to a file
exec & automation
// what it does
-o/--output-last-message writes just Codex's final message to a file while progress still streams to stderr, so you capture the deliverable without the noise. Plain stdout redirection (> file) works too but only captures what went to stdout.
// shell
$ codex exec "write release notes for the last 10 commits" -o notes.md$ codex exec --output-last-message summary.txt "summarize the design doc"// gotcha
-o captures the last message only — intermediate reasoning and tool calls are not in the file. Use --json when you need the full event stream.