Skip to content

codex exec exits 0 even when command_execution fails with nonzero exit code #15536

@aquiles-ai123

Description

@aquiles-ai123

codex exec exits 0 even when the requested command fails and the JSON transcript marks it failed

Summary

When codex exec is used non-interactively to run a prompt that executes a failing shell command, the command failure is correctly recorded inside the transcript, but the outer codex exec process still exits with code 0.

This makes it hard to use codex exec safely in automation, because a failing tool command is not reflected in the CLI process exit status.

Repro

Plain output mode:

codex exec --ephemeral --skip-git-repo-check --color never -C /home/cryptotrading74   "Run exactly: false and stop."
printf "outer_exit=%s
" "$?"

Observed output excerpt:

exec
/bin/bash -lc false in /home/cryptotrading74 exited 1 in 0ms:

codex
Ran `false`. It exited with status `1`.

outer_exit=0

JSON mode:

codex exec --ephemeral --skip-git-repo-check --color never --json -C /home/cryptotrading74   "Run exactly: false and stop."   > /tmp/codex_false_exit.jsonl
printf "outer_exit=%s
" "$?"

Observed transcript excerpt:

{"type":"item.completed","item":{"id":"item_1","type":"command_execution","command":"/bin/bash -lc false","exit_code":1,"status":"failed"}}

Observed shell exit:

outer_exit=0

Expected behavior

If the requested command fails and the task ends in that failed state, codex exec should return a nonzero exit code, or provide a documented flag that enables failure-propagating exit behavior.

Actual behavior

The nested command fails, the transcript marks it as failed, but codex exec itself returns 0.

Why this matters

This makes CI and scripting brittle because callers cannot rely on the process exit status to detect command failure.

For comparison, true CLI parse errors do propagate a nonzero exit code correctly. For example:

printf '' | codex exec --ephemeral --skip-git-repo-check --color never -C /home/cryptotrading74 - false
printf "outer_exit=%s\n" "$?"

returns:

error: unexpected argument 'false' found
...
outer_exit=2

So the CLI already uses nonzero exits for real invocation failures, but a nested command_execution failure inside exec still yields outer exit 0.

Files / artifacts

  • /tmp/codex_false_exit.jsonl
  • /tmp/codex_false_exit_repro2.jsonl

Suggested title

codex exec exits 0 even when command_execution fails with nonzero exit code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingexecIssues related to the `codex exec` subcommand

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions