# Schedules

> Run commands or reminders on a cron, decide what happens to runs missed while the Mac slept, read run logs, and keep schedules running while Flow is quit.

The Schedules page runs a shell command (or files a reminder) on a cron schedule. A run can open in a new session so you can watch it, or run in the background with its output kept in a log. Each schedule decides what happens to runs that came due while the Mac was asleep or Flow was quit, and which runs wait for your approval first. Schedules can also keep firing while Flow is quit, through a small launchd agent.

> **Note:** Schedules is an experiment (BETA). Turn it on in Settings › Experiments (`features.automations`). While it is off the page is hidden and nothing runs, in the app or through the launchd agent (which is uninstalled). Your schedule files, history and Inbox are kept. When you turn it back on, every schedule starts again from that moment, so nothing that came due while it was off fires.

## Open the page

- Click **Schedules** in the sidebar's Tools band. Its badge counts the Inbox items waiting for you.
- Run **Go to Schedules** from the command palette (`⇧⌘P`). It has no default shortcut; bind one in Settings › Keyboard as `keyboard.go_to_schedules`.
- From a terminal: `flow-cli page schedules`. You can also open a part of the page directly: `schedules:inbox`, `schedules:new`, `schedules:ID` (one schedule's inspector), `schedules:log:ID` or `schedules:timeline:7d`.

The page lists every schedule with its directory, cron, missed-run rule, next run and last run. You can sort by Name, Directory, Next run or Last run, group rows by directory, and filter by name, command, directory or goal. A row's hover buttons are **View latest log**, **Run now** (or **Stop run** while it runs) and **Pause** (or **Resume**). Click a row to open its inspector, where every field is edited in place and saved to the schedule's file at once.

## Create a schedule

1. Click **New** in the page header. A blank inspector opens. **Runs in** starts as the directory of the active session.
2. Type a **Schedule name**.
3. Under **Command**, type the command. It runs in your login shell with a real TTY, so interactive CLIs such as `claude` work. Leave it blank to make a reminder: each slot then lands in your Inbox instead of running.
4. Set **Runs in** to an absolute path or a `~` path. A value is saved only once it names a directory that exists; until then the hint under it turns orange and says why. **Choose…** opens a folder picker, and the chips offer `~`, `~/src`, `~/Desktop` and directories your other schedules and sessions use.
5. Pick **Output**: **New session** or **Background** (see [Output](#output-new-session-or-background)).
6. Under **Schedule**, click a preset chip or type a cron expression. The field shows it in words (for example "Weekdays at 09:00") and the line below lists the next three runs.
7. Under **If a run is missed**, pick a **Grace** period and a rule (see [Missed runs](#missed-runs)).
8. Under **Needs approval**, choose **Never**, **Recovery runs** or **Every run** (see [Approval and the Inbox](#approval-and-the-inbox)).
9. Leave **Notify me on failure** and **Skip if the previous run is still going** on, or turn them off.
10. Click **Create schedule**. An invalid cron is refused with "Fix the cron expression first". Otherwise a toast confirms it with the next run time.

### Output: new session or background

| Output | File value | What a run does |
|---|---|---|
| New session | `session` | Opens a new session group in the sidebar and types the command into one of its panes, so you can watch it live. The pane's output is copied into the run's log. |
| Background | `background` | Runs as a detached process with its own TTY. Its output goes only to the log. |

While Output is **New session**, a **Session setup** card offers the same choices as the command palette's New session flow:

- **Base** (only for a directory in a git repo): **New worktree** gives each run a fresh worktree under `your-repo/.worktrees`, so runs never collide. **Existing** reuses one of the repo's worktrees for every run. **Repo root** runs in the checkout itself, so uncommitted changes are shared with you.
- **Branch** and **From** (New worktree): the branch name template, `sched/{slug}-{date}` by default, and the ref it forks from. A blank From means the repo's default base.
- **Cleanup** (New worktree): **Keep**, **On merge** (the default) or **After 7d**. Flow removes a run's worktree only while it is clean, no session has it open and its schedule is not running. The branch is deleted only when it is merged. Deleting a schedule leaves its worktrees where they are.
- **Layout**: **Default** (one pane) or a layout profile from the directory's `.flowspace.json`. With a profile of several panes, **Command in** picks the pane that runs the command.
- **Label**: the group's name template, `{name} · {time}` by default, with a preview of the next run's name.
- **Space**: the sidebar label the group is filed under, or **No label**.
- **On start**: **Open quietly** (the default: the group opens in the background, marked unread) or **Bring to front**.

Templates fill in `{name}` (the schedule's name), `{slug}` (its slug), `{date}` (the run's local `YYYY-MM-DD`) and `{time}` (for example `Tue 14:35`).

### What every run gets

| Variable | Value |
|---|---|
| `FLOW_SCHEDULE_ID` | The schedule's id (its file name). |
| `FLOW_SCHEDULE_NAME` | The schedule's name. |
| `FLOW_SCHEDULED_FOR` | The slot this run is for, local `YYYY-MM-DDTHH:MM`. A catch-up or replay run gets the missed slot, not the current time. |
| `FLOW_RUN_LOG` | The run's log file. |
| `FLOW_SCHEDULE_CWD` | The directory the run starts in (also its working directory). |

> **Tip:** Use `$FLOW_SCHEDULED_FOR` instead of `date` in commands that care about the day, so a replayed run does the right day's work.

## Cron syntax

A schedule uses a standard five-field cron expression in the Mac's local time:

```text
minute  hour  day-of-month  month  day-of-week
```

- Each field is a comma-separated list of `*`, `a`, `a-b`, `*/n`, `a/n` or `a-b/n`.
- Months and weekdays also take three-letter names in any case (`jan`, `mon`).
- Day-of-week runs 0 to 7, where both 0 and 7 are Sunday.
- When day-of-month and day-of-week are both restricted (neither starts with `*`), a day matches if either one matches, as in Vixie cron. Otherwise both must match.
- A step longer than its field selects only the start value.
- On a daylight-saving change, a slot inside the skipped hour does not run, and a slot inside the repeated hour runs once.

The editor's preset chips:

| Chip | Expression |
|---|---|
| Every 15 min | `*/15 * * * *` |
| Hourly | `0 * * * *` |
| Daily | `0 9 * * *` |
| Weekdays | `0 9 * * 1-5` |
| Weekly | `0 9 * * 1` |

A new schedule starts with `0 9 * * 1-5` (weekdays at 09:00). If an expression has no run in the next 40 days, the editor says so. A file with an invalid cron still loads, but the schedule never runs until you fix it.

## Missed runs

While Flow is running, it checks your schedules continuously and runs each slot on time. If the checks stop for more than two and a half minutes (the Mac slept, or Flow was quit with no launchd agent), Flow treats the gap as an outage when it is back:

1. If every missed slot is within the schedule's **Grace** period, it runs once, late.
2. Otherwise the **If a run is missed** rule decides what happens to the slots beyond grace.

Grace choices are None, 15m, 30m (the default), 1h, 2h and 4h. With None, anything missed goes straight to the rule.

| Rule | File value | What happens |
|---|---|---|
| Skip | `skip` | Wait for the next scheduled run. A slot still within grace runs late. |
| Run once | `once` (default) | One catch-up run, however many were missed. Best for idempotent jobs. |
| Replay each | `replay` | Run the command once per missed slot, oldest first, each with its own `$FLOW_SCHEDULED_FOR`. **At most** caps it at the newest 5, 24 (the default) or All. |
| Recovery command | `recover` | Run a different command with the outage's details, for example an agent that decides what to do. |
| Ask me | `ask` | Hold it in your Inbox until you run or skip it. |

A paused schedule's slots are never "missed": resuming starts it again from that moment. A schedule you have just created never inherits earlier slots.

### Recovery command

With **Recovery command**, a wake after missed slots runs the recovery command instead of the normal one. The default is `claude -p "$FLOW_RECOVERY_BRIEF" --permission-mode plan`. Use **Goal** to describe what a good recovery looks like; it goes into the brief.

| Variable | Value |
|---|---|
| `FLOW_RECOVERY_BRIEF` | A plain-language summary: what was missed and when, how long Flow was offline, the last success, the normal command and the goal. |
| `FLOW_MISSED_COUNT` | Number of missed runs. |
| `FLOW_MISSED_TIMES` | The missed slots, local ISO times, comma-separated. |
| `FLOW_OFFLINE_SECONDS` | How long Flow was down. |
| `FLOW_LAST_EXIT` | Exit status of the last real run (empty when there is none). |
| `FLOW_GOAL` | The goal text. |
| `FLOW_PLAN_FILE` | Write a short plan here. |
| `FLOW_COMMAND_FILE` | Write the exact command to run here, or leave it empty to skip. |

When the recovery command exits 0, Flow follows its answer. With approval set to **Recovery runs**, the plan and the proposed command wait in your Inbox as a recovery plan, and you can edit the command before approving. Otherwise a non-empty command file runs at once ("ran per recovery plan") and an empty one is recorded as "recovery agent chose to skip". A recovery agent should only write the two files, never do the work itself.

## Approval and the Inbox

| Needs approval | File value | Behavior |
|---|---|---|
| Never | `never` (default) | Runs start on their own. Missed runs follow the rule above. |
| Recovery runs | `recovery` | Normal runs start on their own. Catch-ups (Run once, Replay each) and a recovery agent's plan wait in the Inbox. |
| Every run | `every` | Every slot lands in the Inbox first. A schedule with no command always works this way, as a reminder. |

When anything can wait in the Inbox, **If unanswered by** sets when an item expires: **1 hour** or **4 hours** after it arrived, **End of day** (23:59) or **Next run** (the default; the next slot takes its place). Then **Skip** (the default) drops it, or **Run anyway** runs it if it has a command.

Click **Inbox** in the page header to see the items. Each schedule has at most one item; newer slots merge into it.

- **Waiting for you**: each card's main button is **Approve & run** (a recovery plan), **Run now** (missed runs, or a reminder with a command) or **Mark done** (a reminder without one). A card can also show **Agent log** or **Last run log**, **Skip** (**Skip today** for a reminder), **Snooze 1h** and **Edit rules** (opens the schedule's inspector).
- **Snoozed**: items you snoozed, each with **Bring back**.
- **Handled today**: what was resolved today.

When an outage left missed runs, a banner above the list sums up what happened and links to the Inbox.

## Run history

The inspector's **History** section lists the schedule's recent decisions. Click a run to open its log; click a held entry to open the Inbox. Each entry has a type:

| Type | Meaning |
|---|---|
| `ok` | Ran on time (or by Run now) and exited 0. |
| `fail` | Exited non-zero, or was lost. |
| `late` | A missed slot within grace, run late. |
| `caught` | A catch-up run (Run once). |
| `replay` | A replay run (Replay each). |
| `recovery` | A recovery command run. |
| `approved` | An Inbox item you approved, or one run on expiry. |
| `done` | A reminder you marked done. |
| `held` | Waiting in the Inbox. |
| `skipped` | Skipped by rule, by you, on expiry, or because the previous run was still going. |
| `stopped` | You stopped it. |
| `running` | Running now. |

The **Timeline** under the list shows each schedule's runs from 12 hours ago to 24 hours ahead, with missed, held and recovery slots marked and sleep periods shaded. Click its expand button for a bigger view over 24h, 3 days or 7 days; there, click a run's tick to open its log.

Flow keeps the newest 50 history entries and the newest 50 log files per schedule. A run that is still going is never pruned.

## Run logs

Click **View latest log** on a row, a run in History, or a log button on an Inbox card. The log opens in a pane at the right of the page; drag the gap to resize it. Up to five logs open as tabs (a sixth closes the oldest), and **Close log pane** closes them all.

The pane's header shows the run's status, name, start time and duration, and the `directory $ command` it ran. Its toolbar has:

- **Search log**: a literal, case-insensitive search with a match count. **Only matches** hides the other lines.
- The level control: **All**, **Errors**, **Warn**, **Info** and **Debug**, each with its line count.
- **Wrap**: wrap long lines instead of scrolling sideways.
- **Follow** (live runs only): stay at the bottom as output arrives. Scrolling up turns it off.
- **Highlights**: opens the highlight rules editor. The number is how many rules are on.

The footer shows the line, error and warning counts and the log file's path. A very large log opens at its last 8 MiB, and a line longer than 8 KB is cut with "… N more bytes".

### Log levels

A line's level is the first of these words it contains, matched case-sensitively anywhere in the line: `ERROR`, then `WARN`, then `INFO`, then `DEBUG` or `TRACE` (both count as Debug). Lines without one show only under **All**.

Flow writes its own lines into every log as `HH:MM:SS.mmm LEVEL message`: the reason for the run (wake, missed and policy lines), then `flow: run "NAME" · scheduled_for=…` and `DEBUG $ COMMAND`, and at the end `flow: exit STATUS · DURATION`, logged as ERROR when the status is non-zero. A replay adds `scheduler: replay i/n` lines.

### Highlight rules

The rules editor lists the rules from top to bottom. Each has an on/off toggle, a colour swatch, a name, a regular expression (shown red while it is invalid), its hit count in this log, a scope and a delete button. **+ Add rule** appends a new one; **Reset** restores the built-in set.

Rules match case-insensitively and run in order; an earlier rule wins where two overlap.

| Scope | Effect |
|---|---|
| Match | Colours the matched text. |
| Tint | Colours the matched text in bold, and the first matching Tint rule tints the line's background with a coloured left marker. |
| Line | The first matching Line rule sets the colour of the whole line. |

The built-in rules:

| Rule | Pattern | Scope | On |
|---|---|---|---|
| Errors | `\b(ERROR\|FATAL\|PANIC)\b` | Tint | yes |
| Warnings | `\bWARN(ING)?\b` | Tint | yes |
| Info | `\bINFO\b` | Match | yes |
| Debug | `\bDEBUG\b` | Line | yes |
| Trace | `\bTRACE\b` | Line | yes |
| Timestamps | `^\d{2}:\d{2}:\d{2}\.\d{3}` | Match | yes |
| flow | `\b(scheduler\|flow):` | Match | yes |
| Retries | `rate.?limit\w*\|retry\w*\|SIGTERM` | Match | yes |
| PR refs | `#\d+` | Match | yes |
| Quoted | `"[^"]*"` | Match | yes |
| Durations | `\b\d+(\.\d+)?\s?(ms\|s\|m\|h)\b` | Match | no |

The rules are shared by every run log and by the Shells tab's output, and are saved in the `schedules.highlight_rules` setting as a JSON array. Each rule looks like this (`scope` is `match`, `line` or `tint`; `color` is `#rrggbb`):

```json
{ "name": "Errors", "pattern": "\\b(ERROR|FATAL|PANIC)\\b", "color": "#ff6961", "scope": "tint", "enabled": true }
```

An empty array means no rules; a value that does not parse brings back the built-in set.

## Run schedules while Flow is quit

While Flow is open, the app runs your schedules. To keep them firing while it is quit, Flow installs a launchd agent. The switch is in Settings › Advanced › Schedules, **Run schedules while flow is quit** (`schedules.launchd`, on by default). The agent is installed only when all of these are true:

- Flow.app runs from `/Applications` or `~/Applications` (not from a build folder, a mounted volume or a translocated copy).
- The setting is on and the Schedules experiment is on.
- You have at least one schedule.

The agent is `~/Library/LaunchAgents/com.worldbreakstudios.flow.scheduler.plist`. Every 60 seconds (and when it loads) it runs the `flow-scheduler` binary inside Flow.app, which takes one scheduler step and exits. While Flow is open the app holds the scheduler lock and the agent exits at once, so it is idle. Its own output goes to `.scheduler.log` in the schedules directory.

The line under the switch shows the agent's state:

| Status | Meaning |
|---|---|
| launchd agent installed | The agent is installed and loaded. |
| Not installed — needs Flow.app in /Applications | Flow is not running from an Applications folder. |
| Off | The setting is off. |
| Blocked in System Settings → General → Login Items | macOS refused the agent. Switch Flow back on there. |
| Unavailable — … | Something else failed; the reason follows. |

The page's status bar says **Scheduler · launchd · runs while flow is quit** when the agent is installed, **Scheduler · in-app · catches up on wake** when it is not, and **Scheduler · another flow process holds the lock** when another copy of Flow is running your schedules. `flow-cli state` reports the agent as `scheduler.launchd`: `installed`, `not_installed`, `off`, `blocked` or `unavailable`.

Runs made while Flow is quit are headless. A **New session** schedule runs in the background instead, with only its log and a "ran headless — flow was quit" note in its history. The exception is a schedule whose session setup makes a **New worktree** in a git repo: only the app can make worktrees, so it waits, and when Flow opens its missed slots go through grace and the missed-run rule like any outage.

To check the scheduler from a terminal:

```sh
/Applications/Flow.app/Contents/MacOS/flow-scheduler status --dir ~/.flow/schedules
```

It prints one JSON line with the last tick (unix seconds, or null), whether the lock is held, the schedule count and how many schedule files failed to parse.

## Pause, stop and delete

- **Pause** a schedule with its row's Pause button, the **Enabled** switch in its inspector, or `flow-cli schedule-enable ID off`. A paused schedule never runs and shows "Paused — no upcoming runs". **Resume** starts it again from now; the slots it skipped while paused are not treated as missed.
- **Run now** starts a run for the current minute. It is refused for a reminder ("Add a command first — this one is a reminder") and while the schedule is already running.
- **Stop run** stops a running run, which is then recorded as `stopped`.
- **Delete**, at the bottom of the inspector, asks "Delete “NAME”?" first. It stops a running run, then removes the schedule's file, its logs and its history. Worktrees its runs made stay.

To pause every schedule at once, turn off the Schedules experiment.

On this page, `Esc` closes the innermost open thing: the colour picker, the rules editor, the expanded timeline, the delete confirmation, then the inspector. `⌘` shortcuts keep their usual meaning.

## Where schedules live

Schedules live in `~/.flow/schedules/`, beside Flow's settings file. `flow-cli read schedules` prints the directory as `dir`.

| Path | What it is |
|---|---|
| `ID.json` | One file per schedule. The id is a slug of the name when it was created (`Customer DB backup` becomes `customer-db-backup`, with `-2`, `-3` when taken). Renaming a schedule never renames its file. |
| `ID/YYYY-MM-DDTHHMM.log` | One log per run, named by its start minute. |
| `.state.json` | The scheduler's own state: history, Inbox and outages. Don't edit it. |
| `.engine.lock` | The scheduler lock. Only the process holding it runs schedules. |
| `.scheduler.log` | The launchd agent's output. |

You can write a schedule file by hand. Every field is optional and takes its default when left out, and unknown keys are ignored. A file that is not valid JSON, or has a wrong type or an unknown value, is skipped and listed under `errors` in `flow-cli read schedules`. Edits made on the page rewrite only the keys they change, so the rest of a hand-written file stays as you wrote it.

```json
{
  "name": "Customer DB backup",
  "command": "pg_dump -Fd -j 4 \"$PROD_URL\" -f ~/backups/${FLOW_SCHEDULED_FOR%%T*}",
  "cwd": "~/src/ops",
  "cron": "0 3 * * *",
  "output": "background",
  "enabled": true,
  "grace_minutes": 30,
  "missed": "recover",
  "replay_max": 24,
  "recovery_command": "claude -p \"$FLOW_RECOVERY_BRIEF\" --permission-mode plan",
  "goal": "Keep a backup less than 24h old without loading prod during business hours.",
  "approval": "recovery",
  "expiry": "eod",
  "on_expiry": "skip",
  "notify_on_failure": true,
  "skip_if_running": true
}
```

| Key | Type | Default | Effect |
|---|---|---|---|
| `name` | string | `Untitled schedule` when blank | Shown everywhere; becomes the id at creation. |
| `command` | string | blank | The command to run. Blank makes a reminder. |
| `cwd` | string | `~` | The directory a run starts in. A `~` path is kept and expanded at run time. A hand-written path is not checked; runs fail and say why if it is missing. |
| `cron` | string | `0 9 * * 1-5` | When it runs. |
| `output` | string | `session` | `session` or `background`. |
| `enabled` | bool | `true` | `false` pauses it. |
| `grace_minutes` | number | `30` | The grace period. |
| `missed` | string | `once` | `skip`, `once`, `replay`, `recover` or `ask`. |
| `replay_max` | number | `24` | The most slots a replay runs (the newest); `0` replays all. |
| `recovery_command` | string | `claude -p "$FLOW_RECOVERY_BRIEF" --permission-mode plan` | What `recover` runs. |
| `goal` | string | blank | What a good recovery looks like; for a reminder, its text. |
| `approval` | string | `never` | `never`, `recovery` or `every`. |
| `expiry` | string | `next` | `1h`, `4h`, `eod` or `next`. |
| `on_expiry` | string | `skip` | `skip` or `run`. |
| `notify_on_failure` | bool | `true` | Toast when a run exits non-zero or is lost. |
| `skip_if_running` | bool | `true` | Skip a slot that comes while the previous run is still going. |
| `session` | object | none | The session setup for `output: session`: `base` (`new`, `existing` or `root`), `branch`, `from`, `cleanup` (`keep`, `merged` or `7d`), `worktree`, `layout`, `pane`, `name`, `label` and `focus` (`quiet` or `front`). A file without it runs in its `cwd` in one pane, named after the schedule. |

## Manage schedules from the command line

`flow-cli` covers what the page does, which makes schedules easy to set up from a coding agent:

```sh
flow-cli schedule-add --name "Morning PR triage" --cwd '~/src/flow' --cron '30 8 * * 1-5' \
  --command 'claude -p "Review the open PRs on this repo." --permission-mode plan' \
  --output session --grace 2h --missed skip       # prints the new id
flow-cli schedule-update ID --cron '0 9 * * 1-5'   # only the flags given change
flow-cli schedule-enable ID off                   # pause; "on" resumes
flow-cli schedule-run ID                          # run now
flow-cli schedule-stop ID
flow-cli schedule-remove ID
flow-cli read schedules                           # every schedule, its next run and any file errors
flow-cli read schedule-runs ID --limit 5          # history, newest first, with each run's log path
flow-cli read schedule-inbox
flow-cli schedule-approve ITEM                    # also schedule-skip ITEM, schedule-snooze ITEM --minutes 60
```

`schedule-add` and `schedule-update` take a flag per field (`--command`, `--cwd`, `--cron`, `--output`, `--grace`, `--missed`, `--replay-max`, `--recovery-command`, `--goal`, `--approval`, `--expiry`, `--on-expiry`, `--notify-on-failure on|off`, `--skip-if-running on|off`, `--disabled`) and for the session setup (`--base`, `--branch`, `--from`, `--cleanup`, `--worktree`, `--layout`, `--pane`, `--session-name`, `--label`, `--focus`). Quote a `~` path in `--cwd` so the schedule keeps it short; `--cwd` must name an existing directory. See [flow-cli](https://flow.worldbreakstudios.com/docs/cli/flow-cli.md) for the rest of the CLI and [Agent skills](https://flow.worldbreakstudios.com/docs/cli/agent-skills.md) for the schedules skill an agent can follow.

## Settings

| Key | Type | Default | Effect |
|---|---|---|---|
| `features.automations` | bool | `false` | Turns Schedules on (Settings › Experiments). |
| `schedules.launchd` | bool | `true` | Install the launchd agent that runs schedules while Flow is quit (Settings › Advanced). |
| `schedules.highlight_rules` | JSON array | the built-in rules | The run logs' highlight rules. |
| `schedules.inspector_w` | number | `360` | The inspector's width, 300 to 900. Set it by dragging the inspector's left edge; double-click the edge to reset. |
| `schedules.log_width` | number | `540` | The run-log pane's width, set by dragging. |
| `schedules.devices` | string | `all` | With Puddles, which devices' schedules the list shows: `local`, `all` or a device id. |

## Other devices

With [Puddles](https://flow.worldbreakstudios.com/docs/features/puddle.md) on and another device connected, the list also shows that device's schedules, each with its device badge (greyed "as of" while the device is offline). You can run, stop, pause and resume them, and approve, skip or snooze a waiting item; the action runs on that device. Creating, editing and deleting a schedule happen only on its own device, and its logs stay there.

## Limits

- Times are the Mac's local time.
- A New session run's log has only what the pane printed while Flow was open. If a persistent pane reattaches while the run is going, the replayed output appears in the log a second time.
- Runs made while Flow is quit never open a session, and a New worktree session waits for the app.
- The launchd agent is installed only for Flow.app in an Applications folder.
