A job that exits green with an empty payload is the cheapest failure to ship. If your CI or internal automation shells out to an agent CLI, the interesting question is not which model it calls. It is which stream you decided to trust—and whether that decision survives a redirect, a timeout, and a version bump.
This is a decision guide for that choice using one tool: OpenAI's Codex CLI in non-interactive mode. Two documented output contracts exist. A team can pick one by accident, often by merging streams when debugging.
Illustrative scenario, not a real deployment: a nightly job uses the CLI to draft release notes, then a second job posts the file. If the wrapper merges progress and final output, the poster may ingest progress text as if it were the notes. The cited vendor page supports the split; it does not report this scenario.
What the documentation actually says
Per the vendor's non-interactive mode documentation, in default output mode codex exec writes progress to stderr and sends the final agent message to stdout. The same page says that adding --json changes stdout to a JSON Lines event stream, where each line is a JSON object.
Be precise about the scope. The documentation states the stream split and the JSONL shape. It does not enumerate event types, field names, exit codes, terminal event rules, or what partial output looks like after a timeout or kill. Those are version-specific observations, not contractual guarantees. Also, the cited page says --json changes stdout; it does not leave the JSONL destination as an open question.
JSON Lines is not the same thing as a resumable event stream. MDN's Server-Sent Events documentation notes that an event ID does not by itself retain or replay events. Nothing in the Codex page promises replay, so do not build a consumer that assumes it can resume a JSONL stream from the last ID.
The gate: three questions before you pick
- Does a human watch the run live? If yes, the default split is the simplest fit: progress on stderr, final message on stdout. A human can watch diagnostics without parsing JSON objects.
- Does anything consume the output programmatically? If yes, decide which stream is the payload channel. In default mode stdout is the final-message channel; under
--jsonstdout is the event channel. In default mode stderr is diagnostics and should not reach the consumer. - Can you pin the CLI version in the job image? If you cannot pin, prefer the contract with the fewest undocumented assumptions. That is usually default text output, because JSONL consumers often end up depending on record shapes the cited page does not specify.
If the answers are 'no human,' 'yes consumer,' and 'yes pinned,' either contract can work. Choose by how much structure the consumer needs, not by which looks more modern.
Contract A: stdout is the answer, stderr is the show
Treat stdout as the payload, stderr as diagnostics, and the process exit status as the first gate. The second gate is payload presence, because an empty payload is not a result.
The wrapper should preserve stdout and stderr as separate channels, capture the exit status, and fail the job when the status is nonzero or stdout contains zero bytes. Why the double gate? A consumer that checks only the exit status can forward a zero-byte file downstream. A consumer that checks only for a non-empty file can forward a partial one after a kill. The documentation does not specify partial-output behavior, so treat truncation as a risk to test, not a documented outcome.
Fit: human-readable deliverables, diffable artifacts, and anything a person will read before it matters. Misfit: consumers that need one JSON object per line, or pipelines where two people will argue about what counts as 'the final message.'
Contract B: the JSONL event stream
With --json, the cited page says stdout becomes a sequence of JSON Lines records: each line is a JSON object. The contract work moves from 'is the file non-empty' to 'did the stream arrive in a form my parser can accept.'
Before writing a parser, run one sample against your installed version and inspect stdout and stderr separately. That is a proposed check, not a result reported here. The parser should ignore records it does not recognize and should fail the job when a line is not valid JSON. A truncated final line is invalid: if a timeout or kill leaves half an object, a JSON parser should error, and the wrapper must convert that error into a failed job rather than an empty artifact. Zero lines should also fail if your workflow expects at least one event; verify whether zero lines can ever be a legitimate result for your prompt and version.
Do not assume there is a documented terminal event. The page does not specify one. If your consumer needs a terminal marker, verify it against the installed version and pin that version.
Fit: you need structured records, multiple consumers will read the stream, or you want to build parsing once rather than scrape prose. Misfit: you cannot pin the version and cannot absorb changes in record shape.
Side-by-side
These rows are design comparisons, not vendor guarantees.
| Contract A (default split) | Contract B (--json) | |
|---|---|---|
| Payload | Final agent message on stdout | JSON object per line on stdout |
| Success check | Exit status plus non-empty stdout | Exit status plus every emitted line parses as a JSON object |
| Progress visibility | Progress on stderr by default | Event stream on stdout; stderr content not specified by the cited page |
| Version sensitivity | Fewer documented fields to depend on | Depends on record semantics not specified by the cited page |
| Best for | One human-facing artifact | Multiple programmatic consumers |
Failure modes worth testing
- Merged streams in the wrapper. If stdout and stderr are merged, Contract A loses its separation. Search your CI configuration for merged redirection before debugging anything else.
- Diagnostics leaking into artifacts. If you retain or ship stderr, inspect what it contains in your environment. The vendor page describes progress on stderr but does not specify its contents.
- Timeout treated as empty success. A killed process may leave zero bytes or a partial line. The documentation does not promise a particular outcome, so map both 'empty payload' and 'invalid payload' to failure explicitly.
- Mixed contracts in one repository. Two wrappers, one using
--jsonand one not, can eventually share a parser. Name the contract in the wrapper and keep one contract per pipeline. - Silent version drift. An unpinned upgrade can change behavior your parser depends on. Pin the CLI and re-run the smoke check on version bumps.
- Assuming replay. A JSONL stream is not automatically resumable. Do not infer replay semantics from event IDs or from the presence of an event stream.
How to check your choice
These are proposed checks for a human to run against the installed CLI. They were not executed for this draft, and no results are reported here.
- Observe the default split. Use a small input, such as a two-line temporary file, and a trivial prompt asking for a one-sentence summary. Run the default non-interactive mode once while capturing stdout and stderr into separate files. Observe which file contains the final message and which contains progress. Mismatch: if stdout contains progress or stderr contains the final message, your installed behavior differs from the cited documentation; stop and reconcile the version and configuration before building a consumer.
- Observe the JSONL shape. Run the same input with the JSON option, again capturing stdout and stderr separately. Inspect stdout line by line. Expected by the cited page: each line is a JSON object. Mismatch: if stdout is empty, not JSONL, or contains non-JSON lines, do not write a parser until you have resolved the discrepancy. Do not judge the run by guessed field names, because the page does not specify them.
- Force a failure. Use a controlled invalid input or unsupported option to make the command fail. Record the exit status, which stream carries the diagnostic, and whether any payload appears on stdout. Criteria: your wrapper must fail the job on nonzero status and must not forward partial or empty payloads. The exact failure behavior is version-specific and is not documented on the cited page, so record what you observe.
- Interrupt a run. Start a prompt long enough to interrupt—for example, one that summarizes a larger temporary file—then kill the process. Inspect the captured stdout. Criteria: if the output ends with an incomplete JSON object, the parser must reject it; if stdout is empty, the wrapper must reject it. Do not treat process termination as success.
- Add a smoke check. On a known-good tiny input, assert the contract your wrapper relies on. For Contract A, the wrapper's success path should require a zero process status and non-empty stdout. For Contract B, assert the same status and that every stdout line parses as a JSON object, with at least one line if your workflow requires one. Run the check whenever the CLI version changes.
When this is over-engineering
If a person runs the command in a terminal and reads merged output, there is no contract to defend. Stop there. The same is true for a throwaway local script whose output nobody reads. The gate matters once output crosses a boundary: into a file another job reads, into a queue, or into something a customer sees.
The decision record
Write four lines and revisit them when the version changes:
- Contract chosen: A or B.
- Owner: whoever owns the pipeline, not whoever wrote the wrapper.
- Expiry: the next CLI major version bump, or the day a second consumer appears.
- Exit criteria: if two consumers need different shapes, stop patching the wrapper and move parsing into one normalizing step.
Whichever way you decide, the question that should reverse it is narrow: would a truncated or empty payload currently reach the next stage without failing the job? If yes, the contract is not the problem—the gate is.
Disclosure: This article was created with AI assistance. The Codex CLI behavior described is limited to the linked vendor documentation; general shell semantics and engineering recommendations are labeled as such. No commands were executed for this draft, and no CLI results were observed. All checks above are proposed observation-based tests for a human to run against the installed version. Event types, exit codes, partial-output behavior, and failure-path output were not verified here; verify them against your installed CLI and the current vendor documentation before relying on a parser.



