CLI flag to save trajectory/output as JSON for non-interactive `codex exec` runs

Resolved 💬 3 comments Opened Aug 14, 2025 by ramsey-coding Closed Oct 30, 2025
💡 Likely answer: A maintainer (pakrym-oai, contributor) responded on this thread — see the highlighted reply below.

What feature would you like to see?

Description

Currently, Codex CLI automatically writes per-session JSONL logs under
$CODEX_HOME/sessions/YYYY/MM/DD/rollout-*.jsonl.

This works, but:

  • The output path is buried in the date-sharded sessions/ structure.
  • There is no CLI option to explicitly choose a log file path.
  • For non-interactive runs (codex exec), there is no direct way to capture the complete trajectory and outputs in a JSON file as part of the same command, without post-processing the .jsonl files manually.

Example of current workflow

CODEX_HOME=codex_logs codex exec --full-auto "update CHANGELOG for next release"

Proposed Feature
Add a CLI option to specify a JSON log output path for the current run. For example:

codex exec --full-auto \
  --json-log ./workspace.json \
  "update CHANGELOG for next release"

Where:

--json-log <path> writes the complete merged trajectory (actions, observations, final output) as a JSON array to <path> after the run completes.

Request

Please consider adding --json-log to both interactive and non-interactive (exec) modes, so users can directly capture structured session output without manual post-processing.

Are you interested in implementing this feature?

_No response_

Additional information

_No response_

View original on GitHub ↗

3 Comments

pakrym-oai contributor · 11 months ago

Hi, can you please try codex exec --experimental-json (will soon become the default --json behavior)? It will stream a structured JSON output.

ramsey-coding · 10 months ago

@pakrym-oai Can I get to chose the path to save the json file as well? Can I specify path?

pakrym-oai contributor · 10 months ago

The output is printed to stdout you can redirect to file using standard redirection codex exec --json ... > file.json