Answer: Use JSON Lines output by enabling the `--json` flag with `codex exec`, which makes `stdout` a JSON Lines (JSONL) stream. If you only need the final message, write it to a file with `-o `/`--output-last-message `. Status: Confirmed Entry: tool/codex/agents-and-automation/machine-readable-output Revision: 2 Digest: sha256:8e85af4b1aa78dad (changes whenever the content changes) Timeline: Created: 2026-11-13T03:52:04Z Last changed: 2026-11-18T13:34:18Z (Example command: — → codex exec --json "summarize the repo structure" | jq) Last verified: 2026-11-20T13:40:31Z Next check: 2026-11-21T13:40:31Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of JSON flag | --json | [1] | 2026-11-20 Output format | JSON Lines (JSONL) stream | [1] | 2026-11-20 Example command | codex exec --json "summarize the repo structure" | jq | [1] | 2026-11-20 Final message output flag | -o | [1] | 2026-11-20 Final message output flag (long) | --output-last-message | [1] | 2026-11-20 Sources: [1] OpenAI. "Non-interactive mode". https://learn.chatgpt.com/docs/non-interactive-mode.md Role: primary. Accessed: 2026-11-20T13:40:31Z Quote: "When you enable `--json`, `stdout` becomes a JSON Lines (JSONL) stream" (Supports: JSON flag) Quote: "`stdout` becomes a JSON Lines (JSONL) stream so you can capture every event Codex emits while it's running" (Supports: Output format) Quote: "codex exec --json "summarize the repo structure" | jq" (Supports: Example command) Quote: "If you only need the final message, write it to a file with `-o `/`--output-last-message `." (Supports: Final message output flag) Quote: "write it to a file with `-o `/`--output-last-message `" (Supports: Final message output flag (long)) Snapshot SHA-256: b1ad0560012e1cb7487e129659d672867cb172ec07f7a643654b4cf4df2c32f6 (captured 2026-11-17T14:05:14Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-17T14:05:15Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T13:40:31Z. No independent second source is configured for this entry Last successful check: 2026-11-20T13:40:31Z Last attempt: 2026-11-20T13:40:31Z Notes and limitations: Extracted automatically from a single official source (section "Make output machine-readable"). Related: https://latestn.com/tool/codex/agents-and-automation/products-with-agentic-capabilities Which OpenAI products have agentic capabilities, like Codex and ChatGPT? https://latestn.com/tool/codex/agents-and-automation/resume-non-interactive-session How do I resume a non-interactive Codex exec session? https://latestn.com/tool/codex/agents-and-automation/resume-thread-without-history How do I resume a Codex SDK thread without loading its history? https://latestn.com/tool/codex/agents-and-automation/dot-codex-tasks How can my dot start Codex tasks and follow up on existing Codex threads? https://latestn.com/tool/codex/agents-and-automation/independent-batch-jobs-nfs How should I run independent Codex batch jobs when hosts share an NFS home? https://latestn.com/tool/codex/agents-and-automation/interrupt-active-turn How do I interrupt an active turn in Codex app-server? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-18T13:34:18Z | changed | Example command: — → codex exec --json "summarize the repo structure" | jq | [1] 2026-11-13T03:52:04Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/codex/agents-and-automation/machine-readable-output/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/codex/agents-and-automation/machine-readable-output POST: https://latestn.com/dispute/tool/codex/agents-and-automation/machine-readable-output with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/codex/agents-and-automation/machine-readable-output?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I make Codex exec output machine-readable or structured with a schema? Revision 2, last verified 2026-11-20T13:40:31Z. https://latestn.com/tool/codex/agents-and-automation/machine-readable-output (accessed 2026-11-21T09:56:55Z). @misc{LatestN_tool_codex_agents_and_automation_machine_readable_output_r2, title = {How do I make Codex exec output machine-readable or structured with a schema?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/codex/agents-and-automation/machine-readable-output}}, note = {Revision 2; digest sha256:8e85af4b1aa78dad; last verified 2026-11-20T13:40:31Z; accessed 2026-11-21T09:56:55Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/codex/agents-and-automation/machine-readable-output