Support waking Codex on background exec_command output

Resolved 💬 2 comments Opened Jun 24, 2026 by fl4p Closed Jun 24, 2026

Proposal

Add an opt-in wake_on_output flag to unified exec_command so a long-running background command can re-enter Codex context when it emits output after the initial tool call has yielded.

Why

Today, exec_command can leave a process running and expose a session_id, but Codex only sees later output when it explicitly polls with write_stdin. This makes file/event-backed workflows awkward, especially commands that already block efficiently until a meaningful event arrives.

One concrete example is a channel/file-watch workflow where a helper blocks on filesystem events and prints a peer message only when the shared channel file changes. With an opt-in wake mechanism, the helper can be run once in the background and Codex can wake when a peer message arrives instead of burning turns on repeated bounded listens.

Suggested behavior

  • Keep existing exec_command behavior unchanged by default.
  • Add wake_on_output: true for explicit monitor/watch commands.
  • After the initial exec_command call has yielded, batch subsequent process output and deliver it as a bounded synthetic user message.
  • Mark injected terminal output as untrusted data.
  • Cap wake payloads so a noisy background process cannot dump unbounded context.

Patch branch

I have a working branch here for discussion, not an unsolicited PR:

https://github.com/fl4p/codex/tree/feat/wake-on-background-output

Implementation sketch in that branch:

  • Adds wake_on_output to the unified exec_command tool schema and request path.
  • Starts a background output waker only when the flag is true.
  • Ignores output while the initial exec_command tool call is still active, so initial output is not duplicated as a wake.
  • Batches later output briefly, caps each wake at 4 KiB, and labels it untrusted.
  • Uses the existing session steering/start-turn path to deliver the synthetic user message only when the session state allows it.

Local validation

On the patch branch:

  • just fmt passed
  • just fix -p codex-core passed
  • just test -p codex-core wake_on_output passed
  • just test -p codex-core background_output_wake passed
  • just test -p codex-core shell_spec passed

A broad local just test -p codex-core run is not clean in my environment because of existing/local fixture problems, including missing test binaries and a unified-exec timeout that also reproduces from clean upstream HEAD.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗