A non-interactive agent run writes to two channels, and automation breaks when nobody writes down which channel the parser may read. This pairing exercise takes roughly twenty minutes for two engineers and produces a one-page card: the consumer contract, the alternatives considered, and one written decision rule. It assumes Codex CLI's documented non-interactive behavior: by default, progress goes to stderr and the final agent message goes to stdout; with the documented --json flag, stdout becomes a JSON Lines event stream, one JSON object per line (non-interactive mode). No command in this article was executed while writing it; the steps below are observation-based tests to run in your environment.
The failure this exercise prevents
A script that shells out to an agent often starts as a few lines and a text search. Someone later adds the JSON flag for logging, and a text-oriented parser can keep matching because JSON Lines is still text and may contain the same words. The pipeline can then report success while the downstream consumer receives a serialized event instead of a final answer.
The reverse also happens when streams are merged: progress lines land inside the final message, so a summarizer expecting one paragraph may read many. Such failures may not throw an exception and may not be visible in a green build.
The exercise targets platform and CI engineers who wire an agent into a pipeline other people depend on. It is not about prompt quality, model choice, or whether the agent's answer is correct. It is about the shape of the bytes that leave the process.
Prerequisites and constraints
Codex CLI must be installed and authenticated on the machine that runs the exercise, and one throwaway repository should be available for test runs. Both participants need a terminal, and one of them needs write access to the consumer script under review. Confirm flags against the help output of the installed version and the linked documentation before trusting any example here.
The exercise also assumes that the consumer is a program, not a person. If a human reads the output in a terminal, most of the decisions below collapse into whatever is readable, and the card is not worth writing.
Step 1 — Write the consumer contract before touching the CLI
Describe the downstream consumer in one sentence, without naming any flag. A useful phrasing is: the parser receives a single block of text and never sees progress output. Write the sentence on the card and leave the flag column empty for now.
Next, decide which documented output shape the consumer needs: the final message only, which points to default mode, or the event stream, which points to the JSON output flag. The supplied documentation describes those two shapes; do not invent a third. Picking the mode before the contract is how teams end up parsing stderr.
Step 2 — Record what each stream carries in default mode
Input: a trivial non-interactive request in the throwaway repository. Redirect stdout and stderr to separate files. Observe which file contains the final answer and which contains progress narration. According to the documentation, stdout should hold the final agent message and stderr should hold progress. Mismatch: if the answer appears on stderr or progress appears on stdout, record the installed version and the observed behavior on the card; do not silently prefer the documentation. This is a version check, not proof that the answer is correct.
Step 3 — Record what changes under JSON output
Input: the same request with the documented --json flag. Observe stdout as JSON Lines. Each non-empty line should parse as a JSON object. Mismatch: if a line is not a JSON object, stop and record the version; do not build a parser on an assumed shape.
Do not assume the event types are stable or fully enumerated on the documentation page. Keep the raw list and select fields in a later stage, after the event names for the installed version are confirmed from real output. Verification criterion: the parser can read one line at a time and reject a malformed line without falling back to text parsing.
Step 4 — List the alternatives, including the ones you reject
A pairing exercise is only useful if the rejected options are written down with a reason. The table below is the artifact; fill the reason column from what the two participants observed, not from memory.
| Option | Kept or rejected | Reason to record |
|---|---|---|
| Default mode, stdout redirected to a file | Kept for text consumers | Final message arrives as one block |
| Default mode with streams merged | Rejected | Progress contaminates the final message |
| JSON output, parse JSON Lines | Kept for machine consumers | One object per line is parseable |
| JSON output, flattened with a JSON processor | Conditional | Convenient, but discards event structure |
| Parse stderr for the answer | Rejected | Documentation places progress there |
| Interactive session, human reads terminal | Rejected for CI | Not reproducible in a pipeline |
Step 5 — Apply the decision rule
Write one sentence on the card and treat it as binding for the pipeline: if a machine consumes the run, the machine reads stdout only, and stdout is either entirely text or entirely JSON Lines, never a mix.
The rule forces a second decision: whether the consumer needs the final message or the event history. Text consumers take default mode and never enable JSON output; event consumers take JSON output and never fall back to text parsing. Progress output stays on stderr, is written to a log file, and is never parsed by anything that decides the pipeline's outcome.
Step 6 — Verify with a failing run
Input: a request expected to fail, such as asking the agent to read a path that does not exist. Observe the exit status, stdout under the chosen mode, and stderr. Interpret the result this way: a non-zero exit should propagate; stdout should remain parseable under the chosen mode; stderr should contain diagnostic detail. Keep success and failure checks separate, because a documented error condition does not prove that an unrelated side effect occurred on success. Record the observed version and result on the card.
Common failure modes
Silent mode drift. JSON output is added for logging, and the text parser keeps working on the happy path because JSON Lines is still text. The card prevents this only if the mode is written next to the parser, not next to the command.
Stream merging. Merging streams to see everything makes progress narration part of the final message. The fix is to keep the streams separate and read the log file only when a run fails.
Exit code as quality signal. A zero exit code means the process completed, not that the answer was correct. The card should say which check judges content, and that check is usually a separate test.
Unknown event types. A parser that branches on every event type breaks when a new one appears. Keeping the raw list and selecting later costs a little memory and survives version changes.
Do not use traces as a delivery record
A completed span is not proof that the downstream consumer received the message. A span describes one operation with a span ID, trace ID, timestamps and optional attributes, and a parent span ID relates a child to its parent within the trace (traces). That record describes instrumented work, not proof of external delivery, so the stream contract still needs its own verification step.
Tradeoffs and when not to run this exercise
The exercise costs about twenty minutes and one page, and it buys a parser that fails loudly instead of quietly. The cost is real for small scripts: a one-off command that a human reads does not need a contract card, and neither does a pipeline that has exactly one consumer and no plans to add logging.
Skip it when the CLI version is about to change, because the card will describe a mode that no longer exists. Run it again after any upgrade that touches output flags, and treat the observed output as the new source of truth.
AI assistance and review
This draft was produced with AI assistance from operator-supplied source notes, and no command in it was executed for the article. A human should verify the flags, the event shapes and the current DEV policy against the installed version and the linked documentation before publishing.
This article was created with AI assistance.
Top comments (0)