Native async wake/sleep mechanism for long-running agent loops
What variant of Codex are you using?
CLI
What feature would you like to see?
Problem
When running autonomous autoresearch type loops, such as overnight ML experiments, multi-hour training runs, iterative research pipeline, the agent has no way to yield its turn while waiting on a long job. The current workaround is polling:
sleep 300; tail -n 80 experiment.log
Repeated dozens of times across a single training session, this fills the transcript with status checks that contribute nothing to reasoning (which is also very annoying to read through). Over a multipler hour or day run, this is the difference between a coherent research loop and one that falls apart because the context window is full of garbage. The alternative is that the agent just ends its turn, but this currently means that it will not start back up on its own after the run completes, which diminishes the length of time it can work for
Proposed behavior
The agent should be able to kick off a long-running command, end its turn (if it wants), and automatically resume with a new turn when the job finishes, not just receive a notification, but actually start working again with the completion context. N polling turns collapse to at most 1 completion turn. The agent's context budget is spent on the work, not the waiting.
Optionally, progress wakes at configurable checkpoints (e.g. every 2 hours, or at specific elapsed times) would let the agent check in at a small number of predetermined points rather than continuously.
Prior art
I built [AgentWake](https://github.com/onetensor/agentwake) to solve this for my own Codex autoresearch workflows. It uses tmux pane injection as the push channel, the agent submits a job via agentwake run, the job runs in a background tmux session, and when the job finishes, a minimal completion message is pasted into the agent's pane and submitted as input, so the agent actually wakes up and begins its next turn automatically (if the pane is idle). It includes idle aware delivery, progress wakes, and log preservation.
I've been using this daily with Codex agents for autonomous research loops, and it works well as a third party tool. However, a native implementation would be nice, it could hook into Codex's sandbox model, session management, and approval flow directly rather than going through tmux.
Recently, while using Claude Code, I saw that it had also shipped a native mechanism that addresses this same problem, where Claude can start background tasks and end its turn, then be woken when they complete without burning context on polling. The fact that this pattern emerged independently in both tools suggests it's a fairly fundamental need for agentic CLI workflows, not a niche preference.
Implementation note
AgentWake uses tmux because it was the most practical third-party approach for me to implement, there's no other reliable way to inject a future prompt into a running TUI from the outside. A native Codex implementation wouldn't need that. It could use internal TUI event hooks or the app-server directly, which would be cleaner and eliminate the tmux dependency entirely, I am just including my personal implementation because it may be useful.
Additional information
_No response_
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Reviewed previous issues, and I agree that it covers the same core idea of waking an idle Codex session when a background command completes, however, I am keeping this up due to some behavioural extensions/differences that could be useful.
I wanted to note a few additional behaviors from AgentWake that I believe are beneficial and may still be useful when designing a native implementation:
I have been using these behaviors in real long-running Codex/autoresearch workflows, and the main practical lesson has been that recording job completion and waking the model should be treated as separate steps: completion should be durable, while delivery can safely wait for an appropriate moment.
I am happy for this issue to be treated as an extension or design note related to #32188 rather than as a competing proposal. I mainly wanted to document the extra behaviors in case any of them are useful for the native design.
I have the same requirement for long-running local research and ML experiments.
My typical workflow is:
Goal mode does not fully solve this use case because it may continue producing turns while the experiment is still running. A foreground command keeps the current turn open, while ending the turn currently requires the user or an external watcher to manually resume the session.
The ideal behavior would be an opt-in mechanism such as
on_exit: "wake"or an awaitable background-task handle, with these properties:This would be particularly useful for overnight training, SDR experiments, simulations, long test suites, builds, and deployment jobs.
Durable completion vs delivery is the right split. Polling
sleep 300; tailfills the window; nativeon_exit: wakewith exactly one continuation turn (exit code, duration, bounded log) is the CLI fix. Treat completion as durable even if the pane is busy, then deliver when idle.That still lives in a local session. AgentWake/tmux die when the laptop sleeps. If the overnight training loop has to outlive the lid, it needs a host that does not sleep. I run that as hosted Hermes on a fenced VPS, $10/mo, 14-day trial: https://thumbgate.app — money/customer/prod pauses in the browser.