Native async wake/sleep mechanism for long-running agent loops

Open 💬 3 comments Opened Jul 10, 2026 by onetensor

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_

View original on GitHub ↗

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