A response file gives another program a stable place to read an assistant's answer. Codex can save its final response separately from progress output, leaving only the assistant's reply in the destination file.

The saved response is a snapshot of the last assistant message, rather than a transcript of tool calls. This suits reports, summaries, and other answers that another program needs to read without parsing terminal progress messages.

You need Bash or zsh, a trusted Git project, and an installed Codex CLI connected to a working model provider. The output option works with an ordinary non-interactive request, so saving a reply does not require granting the model additional file access.

Steps to save the last Codex response with codex exec:

The output option replaces the destination's previous contents if the file already exists. An unused filename avoids losing an earlier reply or confusing it with a new result.

  1. Save a Codex reply to an unused file named codex-response.txt.
    $ codex exec -o codex-response.txt "Explain what a Git commit is in one short sentence."
    ##### snipped #####
    A Git commit represents a single change made to a file or directory. It contains a log of who made the change, when it was committed, and a brief description of what was changed.

    The relative destination codex-response.txt is in the directory where you run the command. The long form of -o is --output-last-message. The final reply is also printed in the terminal, while progress messages go to stderr. If the repository trust check stops execution, resolve the directory check before retrying.

  2. Read the saved response from codex-response.txt.
    $ cat codex-response.txt
    A Git commit represents a single change made to a file or directory. It contains a log of who made the change, when it was committed, and a brief description of what was changed.

    The file should contain the same final answer printed by the completed run; the wording and length can vary. A fresh result requires a successful run and a nonempty answer at the previously unused path. A missing or empty file, or an execution error, does not establish success. An existing file alone could be an older reply.

Share this guide