ReferenceRuns in the background

Language specification

Runtime

Guides

Background

The Flow Book

Runs in the background

On this page

You start a run that takes an hour, or one that waits two days for a person to approve something. You want to close the terminal, check on the run later, and stop it if you need to. The flow command runs every live run in a background host, so the run doesn't depend on the terminal that started it.

Start a run, leave, and come back

The host is one background process per user, flow daemon. You don't start it yourself: the first flow run, or a library's reply, starts it, and it exits after 30 seconds with nothing to do. It keeps its socket, its log and every run's history under ~/.flow, or under FLOW_HOME if you set it.

  1. Start a run and watch it. flow run prints calls as they are sent and answered, then the result, and exits with the run's exit code:
    flow run app.flow --name nightly day=2026-11-18
    Or start it detached. -d prints the run's id and returns at once:
    flow run app.flow -d --name nightly
  2. List your runs and their state (running, waiting, stopping, stopped or completed):
    flow runs
  3. Follow what the run's Tools write to their log:
    flow logs nightly -f
  4. Watch the run again, as flow run did:
    flow attach nightly

--name gives the run a label you can type instead of its id. A name that another run already has is refused. Closing the terminal detaches from the run and leaves it going.

In CI or a container the host starts the same way, and it exits on its own once nothing it holds is waiting (the flow command).

Show a person progress

A long run can tell whoever watches it how far it has got. The console library's note writes one line to the run's log, at Info unless you say Warning:

use "github.com/buttercrab/flow@v1/libraries/console/console"flow report(sources: Int) -> Result<Unit, ToolProblem> = {    console.note("step 3/10: read ${sources} sources")?    console.note("source 7 was unreachable; going on without it", level: Warning)?    Ok(())}
Open snippet in Playground (new tab) ↗

flow logs RUN shows the notes. A note is a Tool call, recorded like any other, so resume and replay answer it from history and don't write it again. The log is separate from history: the host keeps a bounded amount of it, and the program never reads it back. To ask a person something, make a call they answer instead (People and webhooks).

Stop a run

Ctrl-C in flow run or flow attach stops the run. So does flow stop RUN:

  1. The program stops where it is, and the run sends nothing new.
  2. Calls already out run to the end, and the run records their answers. A second Ctrl-C, or flow stop RUN --now, cancels them instead.
  3. The command returns as soon as the stop is recorded.

You can stop a run at any moment, and the program never sees the stop. A stopped run stays open until you continue it with flow resume RUN. Until then, the run records any answer or reply that arrives and hands it over on resume, and each held call is asked again once when you resume.

To watch a run with no risk of stopping it, use flow logs RUN -f. Ctrl-C there only leaves the view.

A run that waits for a reply

When a run waits only for replies, such as a person's approval, flow run returns with exit code 3. It lists the open calls and the command that answers each one. The run stays in the host: a reply continues it with nobody attached, and a held call is asked again at the time its library asked for (People and webhooks).

Keep the host running

The host exits when it is idle and ends with your login session. To keep it running, install it as a per-user service:

flow daemon install

It uses a LaunchAgent on macOS and a systemd --user unit on Linux.

  • macOS 13 and later shows a "Background Items Added" notification. The item appears under System Settings > General > Login Items, where you can turn it off.
  • A Linux server you reach over SSH may end the host when you log out. The service needs lingering, which flow daemon install turns on when it may. When it may not, it prints the loginctl enable-linger command for an administrator to run.

The service runs the flow you installed it with, through the bin/flow link of an install.sh installation, so an upgrade carries it to the new release. Each FLOW_HOME gets its own service. flow daemon status says whether the host is running and whether it is installed, and flow daemon uninstall removes the service.

The host keeps each run's environment in memory and never writes it to disk. When the host restarts, for any reason, every run it was driving stops with the reason host restarted. Replies still reach those runs. To continue one, run flow resume RUN from a shell that has the run's environment.

Hold a call for a long local job

A Tool that starts hours of work, such as a build or a training job, should not keep its call out for all that time. Start the work as a detached process, keyed by the call, and hold:

from datetime import datetime, timedelta, timezonefrom flow_toolkit import tool, context, Hold@tooldef train(config: Config) -> Model:    key = context().key    job = jobs.find(key) or jobs.start_detached(key, config)    if job.finished:        return job.result()    raise Hold(retry_at=datetime.now(timezone.utc) + timedelta(minutes=5))

The host asks the call again every five minutes, with the same key each time. So each re-ask finds the same job instead of starting another, and the one after the job finishes returns its result. If the Tool process or the host restarts meanwhile, the job keeps running, and flow resume asks the call once more, which finds it.

Move a run to another machine

  1. Write the run as one file, with its history, its sources and its host notes:
    flow runs export RUN --out run.flowrun
  2. Replay the file anywhere, without importing it:
    flow replay run.flowrun
  3. On the other machine, copy it in. It gets a new run id:
    flow runs import run.flowrun

Replies addressed to the original run's keys never reach the copy, so point any webhook at the new run's keys (the flow command).

Exact rules: stopping a run, open calls, the CLI contract.