- Schedule actions by absolute time, relative delay, cron or interval.
- Wait for conditions (HTTP, K8s, Docker, TCP, file, shell, LLM) and fire an action only when satisfied.
- Chain jobs in a DAG with
DependsOn/Triggers. - Run in daemon mode that survives closing the CLI — ideal for long deploys,
terraform apply, database migrations. - Give agents a
@schedulertool so they plan their own follow-ups (“wait for the deploy and notify me”).
All three ChatCLI modes (interactive CLI, gRPC server, K8s operator) can use the scheduler. The daemon is optional — in casual use the scheduler runs in-process and the WAL replays jobs the next time you open the CLI.
Flow overview
Each job can fire immediately, wait for a condition, chain other jobs, and propagate lifecycle hooks. The diagram below shows a typical deploy + verify + notify pipeline:Why you need this
Before the scheduler, ChatCLI was always synchronous. You asked, waited, got a response. Now:terraform apply runs, waits for the deployment to become Available, then runs the final check. You come back hours later and ask /jobs history to see what happened.
Two execution modes
- In-process (default)
- Daemon (autonomous)
No setup. Open chatcli as usual and use The prompt status line shows
/schedule / /wait / /jobs. The scheduler runs inside the process.[jobs: 1⏳] while jobs are active./schedule — create a job
--when values
The DSL accepts multiple formats:
--do values
Seven action types:
Full flag set
Skills travel with the job
Anagent: job fires with the same knowledge the creating run had. Skill names are stored in the job payload and re-resolved against the skills directory at fire time — so this works even in daemon mode, where the executing process has no access to the session that scheduled the job.
- Jobs created by an agent via
@schedulerinherit the creating run’s active skills (pinned + auto-activated) automatically; pass an explicitskillslist (even empty) to override. - Jobs created by you via
/schedulecarry only what you pass with--skill(repeat the flag for multiple). - Resolution is best-effort: a skill that no longer exists is skipped, never fatal.
Examples
/wait — wait for a condition in the background
Sugar for “wait for X to happen and optionally do Y”.
/wait returns at once. It registers the wait as a job, prints the job ID and gives the prompt back; the scheduler polls the condition with nobody watching. When the job ends, the terminal says so above the prompt — condition met (and what the --then action printed), timed out, or failed.
--block is the opt-in for the old behavior. While it holds, a progress line prints every 20s, and Ctrl+C lets go of the prompt without stopping the job — it keeps running, and its end is announced like any other. On surfaces with no terminal to hold (web page, ACP, MCP) --block is declined and the job runs in the background.
--async is still accepted: it is what /wait now does by default.
Durations accept 30s, 5m, 2h, 1d, "10 min", "2 hours". A duration, number or --on-timeout value that cannot be read is an error — it is never replaced by a default in silence.
Condition DSL
Examples
Timeouts
--on-timeout fail(default) — mark astimed_outand stop.--on-timeout fire_anyway— run the action even without satisfaction.--on-timeout fallback— run the alternate action defined inWaitSpec.Fallback(via JSON spec) then fail.
/jobs — manage
<id> it also takes the job name or the start of the ID (four characters or more): /jobs show api-ready, /jobs cancel 5ef3. A name several jobs carried resolves to the live one, else to the most recent.
/jobs clear works against the daemon too.
Reading the listing. NEXT FIRE says what the job is due to do: in 4m for a queued job, polling, 9m left for a job waiting on its condition (with the time until the wait gives up), running while the action runs, after dependencies for a blocked one. overdue is kept for a job still queued past its time. LAST shows how the latest execution went; for a job waiting on a condition it reads not met yet ×12 or check failed ×12 — the condition has been checked 12 times — instead of a bare skipped / failed, which described one check and read as a verdict on the job. /jobs show adds what the wait is for, its budget, the checks so far and what the last check reported.
Autocomplete (press Tab) suggests:
- Subcommands (
list,show,cancel,wait, …) - Live job IDs and names for
show/cancel/pause/resume/logs/wait - Values for
--status(pending, running, waiting, …) and--owner(me, user, agent, worker, system, hook)
Daemon mode
Lifecycle
--detachre-execs withsetsid(Unix) /CREATE_NEW_PROCESS_GROUP(Windows), freeing the terminal. Log goes to<socket_dir>/daemon.log.- The interactive CLI auto-detects a daemon on the configured socket and becomes a thin client —
/schedule,/wait,/jobsround-trip over IPC. - Stale sockets (dead process) are cleaned automatically before
start.
IPC protocol
UNIX socket with 4-byte length-prefix + JSON payload frames. Kinds:ping,bye— health/closeenqueue,cancel,pause,resume,query,list,snapshot,stats— operationssubscribe— server-sent events for UI
systemd / launchd
chatcli daemon install prints a template ready to paste into /etc/systemd/system/chatcli-scheduler.service or ~/Library/LaunchAgents/.
@scheduler — tool for agents
Inside the ReAct loop, the agent can call @scheduler with 7 subcommands. This lets agents plan their own pauses autonomously.
The tool keeps the model in control of its own turn. A
wait without async holds the turn until the condition is met or the wait times out, which is right for seconds and wrong for minutes. async: true returns the job ID at once; max_block: "60s" holds for at most that long and then returns with the job still running. Either way the model checks back with query (by ID or by the name it chose), and notify: true has the user’s terminal announce the end. A waiting job reports wait_polls, wait_deadline and wait_detail in list.In wait, every is the poll interval and timeout the wait’s budget (the action’s own timeout is action_timeout). schedule takes wait_timeout, on_timeout and notify as well. Durations accept 30s, 5m, 2h, 1d, "10 min"; one that cannot be read is an error.Synchronous
wait shows life signs. While a sync wait polls, a ⏳ heartbeat line prints every 30s (streamed live to ACP/MCP clients) with the job status, elapsed time and when the wait gives up. If the wait budget runs out, the job is not cancelled — it keeps running in the background, and the tool result tells the model to pick it up later with query or to re-issue with "async": true.Evaluators and actions — plug-in registry
Built-in evaluators
Each implementsConditionEvaluator in cli/scheduler/condition/:
shell_exit
Runs a command, compares exit code with
expected (default 0).http_status
GET/POST to URL, exact or regex match against body.
file_exists
File presence, min size, stable mtime.
k8s_resource_ready
kubectl get + jsonpath; Pod, Deployment, StatefulSet, Service, etc.docker_running
docker inspect; running + healthcheck.tcp_reachable
TCP dial with timeout.
regex_match
Shell cmd + regex against stdout/stderr/combined.
llm_check
Headless LLM answers YES/NO.
custom
User script — args via env
CHATCLI_SCHEDULER_SPEC.all_of / any_of
Composite with short-circuit and per-child negation.
Built-in actions
Incli/scheduler/action/:
- slash_cmd — invokes
/foo argsvia the command handler. - shell — shell command under CoderMode safety (allowlist/denylist from
/config security). - agent_task — boots ReAct loop with the task.
- worker_dispatch — single-agent worker invocation.
- llm_prompt — headless LLM call, option to append to history.
- webhook — HTTP POST/GET/PUT with JSON body, headers, expected status.
- hook — fires chatcli hook by event.
- noop — useful for triggers-only pipelines.
- agent_resume — resumes an agent parked via
@park. Loads the snapshot, re-enters the ReAct loop with restored history. See Agent Park & Resume. - park_poll — polling driver for
@park for_url/for_cmd. Runs every interval; whensuccess_whenmatches or the deadline elapses, fires anagent_resume. Crash-safe via WAL-replay self-rescheduling.
Durability
WAL (Write-Ahead Log)
- One file per job:
~/.chatcli/scheduler/wal/<jobid>.wal - Framing:
magic[4] | length[4] | crc32[4] | payload | crc32[4]— double CRC detects torn writes. - Atomic write via
tmp+rename+dir fsync. - Corrupt files are renamed to
<jobid>.wal.corruptfor inspection.
Snapshot
- Written every
SNAPSHOT_INTERVAL(default 5m) tosnapshot.json. - Atomic replace via tmp-rename.
- Boot prefers: snapshot → overlay any newer
.wal.
Replay on boot
Running/Waitingjobs at crash time come back asPendingwithAttemptspreserved.- Missed fires honor
MissPolicy:fire_once(default) — coalesce all missed ticks into a single fire.fire_all— fire per missed tick (opt-in, can saturate).skip— ignore the missed window, forward to next.
Garbage collection
- Terminal jobs stay for
TTLon disk (default 24h) for/jobs history. - GC loop (
WAL_GC_INTERVAL, default 1h) unlinks expired.wal.
Security
Action allowlist
CHATCLI_SCHEDULER_ACTION_ALLOWLIST controls which action types may be scheduled. Default:
shell→ enqueue preflight + fire-time re-check against CoderMode (see next section).webhook→ hardened HTTP client (honors your proxy and CA bundle) with timeout and max response size; targets that resolve to cloud-metadata or link-local addresses are refused. Thehttp_statusreadiness check uses the same client.agent_task→ re-enters the ReAct loop, which keeps its own interactive policy.slash_cmd→ flows through the CLI’s CommandHandler (subject to the normal session rules).
CoderMode preflight for shell
Every shell command embedded in a job (inAction, in Wait.Condition, or in all_of/any_of composite children) is passed to CoderMode’s PolicyManager — the same one /coder and /agent use interactively. Three outcomes:
The preflight runs before the WAL write, so dangerous jobs never get persisted. At fire time,
RunShell on the bridge reloads the on-disk policy and re-classifies — if the operator added a Deny rule between schedule and execution, the job fails instead of running.
How to edit the CoderMode policy
/config security is now hierarchical. The bare form still dumps the read-only panorama; new subcommands mutate the PolicyManager live and persist to ~/.chatcli/coder_policy.json:
/schedule refuses a command:
deny and forget always prompt [y/N]. allow prompts only when the pattern is “broad” (e.g. @coder exec alone, or a very short suffix). Add --yes / -y to skip the prompt in scripts.
Scope of changes: allow / deny / forget update the JSON immediately; the interactive CLI (workerPolicyAdapter) reloads on every Ask prompt, and the scheduler reloads on every RunShell. If you edited the JSON externally, run /config security reload to force every cache to re-read.
The older paths remain valid:
-
Through the
/coderinteractive prompt — choosing “Allow always” or “Deny forever” on a safety prompt also persists the rule viaPolicyManager.AddRule. Same infrastructure as/config security allow/deny. -
Edit
~/.chatcli/coder_policy.jsondirectly — useful for bulk onboarding (ship a ready-made file to the team) or for per-project rules in<root>/coder_policy.json(merged with the global).Patterns use prefix matching on<toolName> <args>as the PolicyManager normalizes. Deny always beats allow.
--i-know and i_know (agents)
When you want to schedule a command outside the allowlist without adding it permanently:
Job.DangerousConfirmed=true and the job passes preflight even with an Ask classification. Denylist still blocks — --i-know does not override an explicit deny.
Agents get the equivalent via tool call:
/agent. To keep agents from using i_know, set CHATCLI_SCHEDULER_ALLOW_AGENTS=false or keep dangerous commands on the denylist (agents can never bypass denylist).
Full bypass (trusted automation)
For internal automation in a trusted environment you can disable the policy check per-job entirely:- Operator enables it:
CHATCLI_SCHEDULER_SHELL_ALLOW_BYPASS=true - Job carries
bypass_safety: truein the action payload:
/coder (choose “Allow always”) or use --i-know explicitly on /schedule. Bypass is for CI/CD in ephemeral containers where the sandbox is the isolation.
Rate limiting
Global + per-owner token bucket with nanodelay tolerance:Retry-After hint.
Circuit breakers
One breaker per evaluator type and one per action type, classicclosed → open → half_open:
k8s_resource_ready breaker opens and all dependent jobs fail-fast with ErrBreakerOpen instead of saturating the worker pool.
Audit log
Every mutation (create, transition, cancel, fire) writes a JSON line to~/.chatcli/scheduler/audit.log. Rotation via lumberjack (default 10 MiB, 7 backups, 30 days).
Authorization
OwnerUserandOwnerSystemmay cancel any job.OwnerAgentmay only cancel jobs it owns or those of child workers.- Cross-owner cancel returns
ErrNotAuthorizedand fires thePreJobCancelhook for auditing.
Observability
Prometheus metrics
Events
The scheduler publishes oncli/bus and fires chatcli hooks:
job.created,job.scheduled,job.firedjob.wait_started,job.wait_tick,job.wait_satisfiedjob.running,job.completed,job.failed,job.timed_out,job.cancelled,job.skippedjob.retry_queued,job.paused,job.resumed,job.dependency_resolvedbreaker.opened,breaker.half_open,breaker.closeddaemon.started,daemon.stopped
Scheduler.<event> as HookEvent.Type — you can wire a Slack webhook to Scheduler.job.failed via ~/.chatcli/hooks.json.
Status line
When jobs are active, the prompt prefix gains[jobs: 2▶ 1⏳ 1✗]:
▶running👁waiting (polling)⏳pending⛓blocked (waiting on deps)✗failed
Full configuration
See Environment Variables → Scheduler for the ~25 env vars./config scheduler
Internal architecture (brief)
- Schedule pump (1 goroutine) drains the priority queue by
NextFireAt. - Worker pool (N goroutines =
WORKER_COUNT) runs handleJob (wait → action → finalize). - Snapshot loop (1 goroutine) periodic freeze.
- GC loop (1 goroutine) reaps expired terminal records.
Next steps
Cookbook: automations
Practical recipes: deploy with wait, cron backup, DAG pipeline.
Reference: Commands
Full table of flags and subcommands.
Reference: Env vars
All 25+ scheduler variables.
Hooks System
Wire Slack/PagerDuty webhooks to scheduler events.