Wakes: Cron and Watch
A wake is something other than the user that puts work into a conversation: a cron’s prompt coming due, a line from a command the agent is watching, a value from a browser watch, a background job ending. This document covers the two the model starts for itself, Cron and Watch, and the path every wake takes into a conversation.
They work as Claude Code’s cron tools and Monitor do. They live while zelk has the conversation open, and their prompts and lines go into that conversation as notices. Nothing runs while zelk is closed, no wake runs in a session of its own, and none is tied to the browser.
The tools
Section titled “The tools”| Tool | What it does |
|---|---|
CronCreate{cron, prompt, recurring?} |
Posts prompt into the conversation at the times a five-field cron expression names, in the host’s local zone. recurring defaults to true; false fires once, at the expression’s next time. |
CronList{} |
The conversation’s pending crons: ID, expression, prompt, whether it recurs, its next time. |
CronDelete{id} |
Stops a pending cron. A prompt it already posted isn’t recalled. |
Watch{command, description, min_interval?, stop_after?} |
Runs command in the background and wakes the conversation with the lines it prints. Stopped with ProcessKill. |
A host offers the Cron tools with WithScheduling() (-scheduling in
zelk). Watch is offered wherever Bash is.
Sources, occurrences and the inbox
Section titled “Sources, occurrences and the inbox”Each cron and each watch is a source, recorded in the session’s log when it is created and when it ends. Each thing a source reports is an occurrence, numbered within the source.
- Occurrences are fixed when made. An occurrence’s payload (the lines, the due time, how many times were missed) is decided once. A retry sends the same payload under the same ID, so a duplicate is dropped, never a conflict.
- The inbox. An observer that doesn’t hold the session’s lease, such as a watch’s reader or a browser watch, writes occurrences to the session’s inbox. The inbox is a store-backed, append-only file outside the log, bounded per source (64 occurrences or 256 KiB). Past the bound, occurrences fold into the newest, which counts them. A busy session loses nothing.
- Crons don’t use the inbox. Their occurrences come from the expression and the clock, numbered under the lease when admitted.
- Admission is exactly once. The lease holder admits occurrences after the source’s recorded cursor and records the cursor’s advance in the same append as the accepted command. What an observer couldn’t record is reported as a gap in the next occurrence, never hidden.
Admission into the conversation
Section titled “Admission into the conversation”Admitting is one step in the driver, under the lease
(loop/sources.go). It consumes the occurrences, queues them as one
user item of background origin, and records which run they went to.
There is no host-side idle check that could race the user typing.
- An idle conversation starts a run with the notice.
- A run under way takes it in, often because it is waiting for exactly that line.
- A suspended conversation (waiting for an answer) admits nothing; its occurrences wait in the inbox, or as due crons.
Who dispatches
Section titled “Who dispatches”Agent.DispatchWakes(ctx, workspace) admits due and inboxed occurrences
for the workspace’s sessions with live sources. It finds them through
the catalog’s index, without reading every log, and never resumes an
unrelated unfinished run. The TUI calls it every five seconds, and ACP
on its own tick. A session with nothing waiting isn’t opened, so a poll
never takes its lease for nothing.
The lease serializes hosts, and occurrence IDs dedupe what two of them both admit.
- Syntax. Five fields: minute, hour, day of month, month, day of
week; 0 or 7 is Sunday; when both day fields are set, either matches.
Numbers, ranges, lists and steps only (
internal/cron). - Zone. A cron records an IANA zone, the host’s local one. A host
without that zone’s data refuses to fire it and says so. zelk computes
the times itself rather than relying on
time.Dateat a DST change. A local time that doesn’t exist that day fires once at the first valid minute after the gap. A time that happens twice fires once, at its first instance. Impossible dates never match. - The answer shows the times.
CronCreatereturns the cron’s ID and its next three times, in local time and UTC. A one-shot shows its one time. An expression that names no time in the next nine years is refused. - No approval. Creating or deleting a cron asks no one: it only posts a prompt into its own conversation, and the calls that prompt leads to are decided as they come. Deny and ask rules naming the tools hold, and plan mode refuses both.
- Exact times. 9:00 fires at 9:00. The tool description tells the agent to pick an off-minute when the user’s time is approximate.
- Catch-up fires once. Times missed while zelk was closed, or while the conversation was busy, are admitted as one occurrence when the conversation is next open and idle. It counts the times it folds in, and its prompt says how many came due only when that is more than one.
- No overlap. While an occurrence’s run is unfinished, times that fall due are counted into the next one admitted after it ends.
- No expiry. A recurring cron lasts until it is deleted. It is bounded by the user’s presence: it fires only while zelk is open.
- A live cron keeps its session from the 30-day retention sweep (retention), and each admitted occurrence counts as activity.
- An output mode of a background process. A watch is a
conversation-lifetime process: confined, listed and killed like any other. Its stdout is read as lines. Its stderr goes to a file in the session’s scratch directory, named in the answer, for the agent to read if the command misbehaves. - Lines. Lines arriving within 200 ms of each other make one occurrence; output that never pauses reports a second after its first waiting line. An occurrence is bounded at 16 KiB, oldest lines giving way and counted. A line over 4 KiB is cut and says so; invalid UTF-8 is replaced; output without a newline is flushed as a line after 1 s.
- Rate. At most one notice per
min_interval(10 s by default, 1 s at the least). More than 60 notices in an hour stops the watch, with a notice telling the agent to narrow its filter. - Its end. A watch runs until its command exits, it is killed,
stop_afterpasses, or the host closes. Its last notice says how it ended and carries the exit the watch saw: admitting it records that exit as the process’s end, so a later stop or inspection reports it. An end no watch saw, a command that didn’t survive a restart, records the process lost. A process stop withdraws the wake first and retires the source. Pending monitor occurrences are discarded during admission; an exit one carries is recorded as the process’s end first, never lost with it. A confirmed exit is recorded separately and releases the process’s slot. A parked run triggered only by withdrawn wakes ends interrupted without a model call: an idle stop ends it under its own lease before returning, running nothing else, and otherwise the session’s next execution does. See process stops. - Restarts. The process dies with the host that started it. When the conversation is next opened, the agent is told the watch ended and decides whether to start it again; zelk never runs a command again blindly. Each occurrence records the output cursor it reached, so a watch reattached within one host reads on without reporting a line twice.
- Approval. The command is decided like a Bash command when the
watch starts (
loop.WatchTool). - The description teaches coverage. A filter must match failures as well as success: a watch that greps only for “Ready” stays silent through a crash, and silence looks like progress. Every pipe stage must flush per line.
The source kind recorded for a watch is monitor, since watch is
already the browser watch’s kind. Each Watch records its process handle
and takes a fresh source ID at launch. The inbox, admission and exit
settlement use the source its launch created, so a late occurrence cannot
wake a replacement session or affect a replacement process that gets the
same handle, whatever process ID the environment gives it. Recovery reads the same
inbox and resumes from the recorded output cursor when it can reattach the
process.
A browser watch (user_browser_watch) observes a page and reaches the
conversation through the same inbox and admission.
Recorded wake withdrawal
Section titled “Recorded wake withdrawal”A wake withdrawal identifies a process handle or child session ID. It prevents new completion notices from joining model requests or being recovered. For a process it also closes the monitor source and suppresses run notices. Process exit and child settlement follow their own records. Notices accepted earlier keep their recorded history positions. Requests and readers hide the ones that have never reached a model.
Completion delivery waits for the job’s start record. Admission checks the originating process ID or child wake ID against the current log both when starting an execution and when joining an active one. A stale delivery cannot wake a replacement session that reuses the job’s handle.
The post-start state fixes what a provider attempt may deliver. A withdrawal preserves the notice IDs carried by open attempts, since either the portable or the native request may reach the model from that handoff. An attempt known to have ended without dispatch leaves its notices eligible for withdrawal. A sighting persists by accepted command ID after the conversation is compacted.