Skip to content

Schedules and waits

A thread doesn’t have to run only when you write to it. It can wake itself at a time, or when something it’s waiting for happens.

Ask in plain words:

Every weekday at 9, check the slow query log and tell me if anything got worse.

Remind me in two days to remove the feature flag.

The agent saves a schedule on the thread: a prompt and when to run it. At each time, the same thread wakes with that prompt and its whole history, so it continues what it was doing and doesn’t start from nothing.

A thread has one schedule. Asking for another replaces it. “Change it to 8:30” does what you’d expect. The agent can pause or clear its own schedule too, so “check every hour until the deploy is done, then stop” works.

A scheduled run doesn’t mark the thread as new. You hear from it only if the agent decides it has something to tell you, or if the run fails. A daily check that finds nothing stays out of your way.

Between runs, a thread with nothing for you waits in the Scheduled fold at the foot of the list, with its next run where the time would be.

A thread with a schedule has a clock chip in its header, showing the next run. Click it for the schedule: when it runs, when it last ran and how many times, the saved prompt, and three controls.

  • A switch, On or Paused.
  • Run now, which runs it immediately as a normal turn.
  • Delete…

Settings → Schedules lists every thread’s schedule in one place, soonest first.

  • The computer was asleep, or endurable was off. When it’s back, everything missed runs as a single turn that’s told how many runs it missed.
  • The thread is archived. The schedule is paused until you unarchive it.
  • The thread’s last turn failed. The schedule waits until you retry or dismiss the failure.
  • The previous run is still going. The next one is skipped and counted as missed. Runs never pile up.

Repeating schedules run at most every five minutes. A repeating schedule can have an end date. Times are in your computer’s time zone unless you name another, which the schedule then shows: “Every weekday at 9:00 AM (Europe/Berlin)”.

A wait is for something outside the agent’s control: a build that takes twenty minutes, a pull request that needs a human to merge it, another thread finishing. The agent sets a wait and ends its turn. No model time is spent. When the event happens, the thread wakes.

An agent can wait on:

  • Files changing in the thread’s folder, matched by path and glob. “When dist/ has a new .js file.”
  • A command’s output: the wait runs a command, such as pnpm dev or tail -F on a log, and wakes the agent on the lines it prints (all of them, or only lines containing some text, such as ERROR) or when the command exits.
  • Another thread finishing a turn.
  • Its own pull request: merged, closed, updated by someone, checks passed or failed, a conflict with its base branch found or resolved.
  • A source an extension provides, such as an alerts feed or a queue.

Every wait has a reason, which is what the agent intends to do when it fires. A one-off wait also has a timeout, from ten seconds to seven days. If the timeout passes first, the agent is woken and told so.

A standing wait doesn’t close after it fires. It fires on every matching event, for weeks if needed, until it’s canceled. It needs no timeout. So that a noisy source can’t run up your usage, a standing wait wakes the thread at most ten times in any 24 hours by default, and the agent can set that anywhere up to 48. Past that, events are recorded as notes the agent reads the next time it runs.

A wait can also be notes only: it never wakes the agent, and what it hears is there to read at the agent’s next turn.

A thread can have twenty waits open at once, five of them standing.

A wait on a command starts that command where the thread’s commands run, in its sandbox if it has one, and owns it: the command stops when the wait closes. So a one-off wait for “the server is ready” stops the server once it fires. For a dev server or a log you want watched for days, the agent makes the wait standing.

  • Starting the command asks for approval just as running it in the terminal would, in whichever permission mode the thread is in.
  • It needs tmux. With it, the command keeps running through an endurable restart, and the wait reads on from where it left off, including what was printed while endurable was off, without repeating a line. If the command printed more than 64 MB in that time, the oldest of it is lost, and the wait says so.
  • It can run for months. What it prints is kept only until the wait has read it.
  • Archiving the thread stops the command and closes the wait, as it stops anything else the thread left running. To put a thread away and keep it listening, snooze it instead.
  • If the thread moves to another machine, the command starts again there, once the thread’s files have arrived.

A standing wait can hand each event to a small script the agent writes, instead of waking the agent every time. The script decides what’s worth your agent’s attention, so a log that prints the same error four hundred times wakes it once:

// Runs for each line the command prints.
if (!event.text.includes("ERROR")) return;
state.seen = state.seen ?? {};
const kind = event.text.replace(/\d+/g, "#");
if (state.seen[kind]) note(`Again: ${kind}`);
else {
state.seen[kind] = true;
wake(`A new kind of error: ${event.text}`);
}

A script gets the event and a state object it keeps between events, and can:

  • wake(text): wake the agent with that message, within the wait’s wakes for the day.
  • note(text): leave a note the agent reads next time it runs, without waking it.
  • ask(...): put a question to you (below).
  • close(): end the wait.

Scripts run in a sandbox with no files, network or timers, and no model, so running one costs nothing. Running the same script on the same event and state always gives the same result, so a run cut off by a restart just runs again.

The script is pinned when the wait is set. Editing the file changes nothing until the agent repins it, which keeps the script’s state.

If a script throws, the wait pauses and wakes the agent with the error. Events that arrive meanwhile wait, in order, until the agent fixes the file and resumes the wait, so nothing is skipped. A paused wait holds up to a thousand events, and counts any it had to drop past that. The waits chip shows “Paused”, and its list shows each script, how many events wait for it, and the state it keeps.

A script can ask you a question directly, without waking the agent first:

ask("Run the pending migration?", ["Yes", "No"]);

It can ask anything the agent can ask in a question card: choices, a written answer, several questions on one card, or a form, often prefilled from what it heard:

ask({
prompt: "Throttle the noisy client?",
form: [
{ type: "input", name: "client", label: "Client", default: clientFromTheLine },
{ type: "select", name: "limit", label: "Requests a minute", options: ["10", "60", "600"], default: "60" },
],
});

The card says which wait’s script asked it, and on what. Your answer wakes the agent, as any answer does, and tells it where the question came from. A script has one card waiting on you at a time; anything else it asks meanwhile goes to the agent as a note. A question brings an archived or snoozed thread back to the list, like any question. If the wait closes before you answer, the card says so, and you can still answer.

A thread with open waits has an hourglass chip in its header. It lists each wait with its reason, what it listens for, when it gives up, and Cancel. A wait with a script also shows the script, how many events are waiting for it, and, folded away, the state it keeps.

Canceling doesn’t wake the agent. It learns about it on its next turn.

When a wait fires, the transcript shows a card: “Wait fired · 2 paths changed”, with the reason and what was heard.

On a Mac, endurable keeps the computer from idle-sleeping while any agent is working, or while a thread has a one-off wait open that can wake it. The display can still sleep. Closing a laptop’s lid still puts it to sleep, and work resumes when you open it.