ReferenceThe flow command

Language specification

Runtime

Guides

Background

The Flow Book

The flow command

On this page

You check, test, run and inspect Flow programs with the flow command, and it keeps your runs in a background host. Scripts and tools can rely on two parts of it, its exit codes and its --json output (the CLI contract). The rest, described here, is for people at a terminal.

Find a command

flow help lists the commands, and flow help COMMAND describes one. flow help also takes a topic: exit-codes, json, environment or ids.

Command Does
flow new FILE.flow creates a program with a main and a @test; a Tool library is created with its toolkit's own new (Writing a library)
flow check [PATH…] [--entry E] [--fix] [--watch] checks programs without running them; --fix applies safe fixes; exits 0 when every program checks, and 2 when one doesn't or can't be read
flow test [PATH…] [--only TEST]… [--steps N] [--watch] runs @test functions and replays saved histories (testing)
flow fmt [PATH…] [--check] formats source with the one canonical formatter
flow build [DIR] [--check] generates a library's contract from its code; with --check it writes nothing and exits 1 when a contract is stale
flow doc [PATH…] [--out DIR] [--all] generates documentation from /// comments
flow explain [CODE] [--list] prints a diagnostic code's explanation, usual repair and example; --list lists the codes
flow run FILE [KEY=VALUE…] [--entry E] [--name X] [--binary] [-d] starts a run (entry) and attaches to it; -d prints the run's id and leaves it running
flow resume RUN [FILE] [--from N [--name X]] [--drop CALL…] [--resend [CALL…]] [-d] continues a run, or forks it with --from
flow stop RUN [--now] stops a run; a run already stopped or completed is left as it is, and the command exits 0
flow attach RUN attaches to a run again; Ctrl-C stops it
flow logs RUN [-f] shows a run's log; -f follows it, with the run's calls and answers as they're committed
flow runs lists stored runs
flow show RUN [CALL] [--last] [--at MOMENT] shows a run, one of its calls, or a task at one moment, from its record
flow replay RUN [FILE] [--last] [--trace [--from MOMENT] [--to MOMENT] [--limit N]] replays a history and reports the verdict; exits 0 when it matches and 1 when it doesn't
flow runs export RUN [--out FILE], flow runs import FILE [--name X] writes a run as one file, and copies one in under a new run id
flow runs delete RUN [--yes] removes a run that no writer holds
flow approve FILE [--yes] approves the remote native code a program reaches; exits 0 when all of it is approved, 2 when some is declined or can't be asked about, and 70 when an approval can't be remembered
flow update FILE accepts remote tags that moved since they were pinned
flow doctor checks the installation without running a program: paths, release identity, the standard library, and the language tools and completions it finds; exits 1 when Flow's own installation has a problem; findings about language tools and completions are informational
flow daemon start|status|stop [--now]|install|uninstall manages the background host; status exits 0 whether or not the host is running, and says which
flow mcp serves Flow to an MCP client over standard input and output
flow completions SHELL prints a completion script for the shell
flow help [COMMAND|TOPIC] prints help for a command or a topic
flow lsp [--std DIR] the language server; --std names the standard library's directory, the one holding v1/; not listed in help
flow dap the debug adapter, which steps through a stored run by replay; not listed in help

Name a run or a call

Wherever a command takes RUN, you can give a run's name, its full id, or a prefix of its id of at least 4 hexadecimal digits that names one run:

flow show nightlyflow show 7f3a
  • A prefix shorter than 4 digits, or one that names no run, is refused with unknown-run.
  • A prefix that begins several runs' ids is refused with ambiguous-run, which lists them.
  • When RUN is both a run's name and a prefix of another run's id, the name wins. A longer prefix or the full id still reaches the other run.
  • A name written as a full run id is refused with invalid-value, so a full id always reaches its own run.

The CLI shows an id as its first 12 hexadecimal digits. CALL is a call's id as flow show prints it, such as root#2; flow help ids explains the form.

With flow show --last FILE or flow replay --last FILE, give a program file instead of a run id. The command selects the newest stored run whose host noted the file's local-tree root and whose entry is in the file's module, in the store's order. The file may have changed or been deleted since the run. When no such run is stored, the command reports unknown-run and suggests running the file first.

Run a program and come back to it

flow run attaches to the run it starts. It prints the result, and nothing else, on standard output. The calls it sends and their answers, the log lines and the final state go to standard error.

flow run app.flow day=2026-11-18flow run app.flow -d --name nightlyflow attach nightly

The client returns when the run ends, when it stops, or when it waits only for replies: no call is out, no timer is set, and each open call waits for a reply or a --resend. A run left waiting stays in the host, and a reply continues it with no client attached. Ctrl-C stops the run. Closing the terminal, or ending the client any other way, detaches it and leaves the run going. Runs in the background walks through this.

The commands that drive or change a run (run, attach, resume, stop, runs import and runs delete) talk to the background host, and start it when it isn't running. flow runs asks a running host about the runs it drives and reads the rest from the store, and never starts the host. replay, show, runs export and logs without -f read the store directly, without taking a run's lock. Every other command runs in the CLI's own process.

Check and test again on every save

With --watch, flow check and flow test run once, then again each time a .flow file or a flow.toml in the tree you gave them changes:

flow check . --watch

A save is one change. On Linux a file is read once its writer has closed it, so a save that empties a file and writes it again starts one round, however long the writing takes. On macOS and the BSDs the system doesn't report a writer closing a file, so a round starts once nothing more has been reported for 300 milliseconds.

A test that never ends would never fail, so flow test stops a test after 2^26 evaluation steps, counted across the test and its fakes, and fails it. --steps N sets another bound.

Answer prompts ahead of time

The CLI asks you something only when standard input and standard error are both terminals and you gave neither --no-input nor --json. FLOW_NO_INPUT=1 works like --no-input. Each question has a way to answer it ahead of time:

It asks Answer ahead of time with Without a person
whether to run remote native code that isn't approved yet flow approve FILE [--yes] refused, naming flow approve
whether to delete the run, at flow runs delete RUN --yes refused, naming --yes
whether to drop the calls that resuming onto edited code, or forking, would drop --drop CALL…, naming exactly those calls refused, listing the calls and the command that drops them
flow resume nightly app.flow --drop root#4 root#7

A run the background host drives asks no one. A run whose remote code isn't approved, or a resume that would drop calls, is refused with the command that gives the consent. A refusal exits 2.

When you say yes, exactly the calls you were shown are dropped, so a call that became droppable after the listing refuses the request. --drop has no blanket form, because a dropped call may be made again under a key no implementation has seen. A bare --resend doesn't ask and may name every open call that isn't held, because a resend goes out under the same key, which an implementation can recognize. The CLI lists the calls before it sends them.

Shape what a command prints

Standard output carries only data: a run's result, a listing's rows, a document or the --json document. Status lines, call and answer lines, progress, errors and suggested next commands go to standard error. A command writes standard output once its work is done. The exceptions are the commands that follow something, flow logs -f and flow mcp, which write each whole line as it happens.

These options work with every command, anywhere on the line:

Option Does
--json prints one JSON document on standard output (Read the JSON output)
-q, --quiet prints the result and errors only: no status lines, call lines, suggested commands, progress or waiting notices
-v, --verbose adds detail to human output, such as debug log lines, where each log line came from, the store, and every diagnostic
--color auto|always|never styles human output with ANSI codes
--no-input never prompts (Answer prompts ahead of time)

-q and -v change human output only, never the --json document. flow mcp, flow lsp, flow dap and flow fmt with no path write a protocol or source on standard output, so they refuse --json as a usage error.

NO_COLOR=1 flow check app.flowflow runs --color always | less -R

Color. --color always and --color never win over every variable. auto, the default, decides for standard output and standard error apart, and the first rule that applies wins:

  1. FORCE_COLOR or CLICOLOR_FORCE set, not empty and not 0: styled.
  2. NO_COLOR not empty: plain.
  3. CLICOLOR=0: plain.
  4. TERM=dumb: plain.
  5. Otherwise the destination is styled when it's a terminal.

A terminal used for input decides neither. Color only repeats what a word already says, and some human views print without it whatever you choose.

Progress, symbols and links. Three variables take auto, always or never, and have no flag:

  • FLOW_PROGRESS: progress on standard error. auto shows it when standard error is a terminal, TERM isn't dumb, and you gave neither -q nor --json.
  • FLOW_UNICODE: progress symbols beyond ASCII. auto uses them when the terminal is known to show them.
  • FLOW_HYPERLINKS: terminal hyperlinks on file locations. auto adds them only in terminals known to support them, and the plain location is printed too.

Human output is laid out in the width COLUMNS gives when it's a positive number, and a bounded default otherwise. Width changes the layout only. Progress and styling never reach the JSON document or the MCP protocol, and formatted source, generated documentation and completion scripts are never styled. Output redirected to a file reads without cursor movement.

Text from outside the program. Text the program's own source didn't supply, such as a Tool's reply or an error message, is shown with its controls escaped, as diagnostics render it, and never obeyed. The JSON document keeps the original bytes.

Read the JSON output

--json makes a command print exactly one JSON document on standard output, whether it succeeds or fails, with the same exit code it has without --json:

flow runs --json | jq '.data.runs[] | select(.state == "waiting") | .run'

The document's keys, the shape of each command's data, and how times, ids and large values are written are the machine output contract. flow help json prints a summary. On a terminal the document is indented, and elsewhere it's on one line. Standard error may still carry human status lines when it's a terminal.

Check, format and document programs

flow check reports, for each program, its entry's signature and the Tools it can reach:

flow check app.flow --fix

--fix applies the safe fixes that don't overlap, to sources that haven't changed since they were checked. Within a file it takes fixes in source order and leaves out one that overlaps a fix it already took; the next check reports that diagnostic again. It never edits a generated contract, which flow build writes again, though it still reports a contract's diagnostics. With --json the document carries what a tool needs to compare an edit with the checked bytes (command output).

flow fmt lays source out in the canonical form:

flow fmt . --check

It rewrites each file you name in place and searches each directory you name for .flow files. With no path it formats standard input to standard output. A search skips entries whose names start with ., follows no symbolic link, and leaves out build and dependency directories named target or node_modules; a file you name is formatted wherever it is. With --check it writes nothing and names each file that isn't in canonical form. It exits 0 when it's done, 1 when --check found a file that isn't canonical, and 2 when a file or a directory can't be read, a file doesn't parse, or a file can't be written. It still formats the other files.

flow doc documents every module the program and its libraries form, each named by its path at the version it resolved to; --all adds std's:

flow doc app.flow --out site/api

It documents a function with its type parameters' requirements and the local and anonymous functions written in it, and a type with the doc comments of its fields, constructors and their named payloads' fields, in the order they're written. With --out it writes one page per module, named by the module's path. When modules of different roots have the same path, it writes none of their pages and exits 2, and still writes the other pages.

In an editor, going to the definition of an import opens the library's root, and going to a Tool's definition opens its generated contract. Going to its implementation reaches the native function the contract was generated from. An editor never points into source that changed since it was read, and shows no location for native bytes it can't read.

Look inside a run

flow show RUN reads the run's record. It never runs the program or starts an implementation:

flow show nightlyflow show nightly root#4flow show nightly --kind call --search refund

It shows the run's state and why it stopped, its open calls, each with its Tool, arguments, return type, whether it's held and the command that answers it, and its latest 20 facts; --all shows every fact. flow show RUN CALL shows one call: its arguments, its return type written as Flow, and its answer or how to answer it. Calls are grouped with their answers, facts keep their numbers, and host notes are shown apart.

  • Choose facts. --kind selects facts by kind, --search by a substring of their summary, and --fact by number. The view keeps each fact's number, and says how many facts there are and how many it hides.
  • Show one value whole. --fact N --value PLACE shows one value of fact N, exactly, however large it is. PLACE is the value's place in the fact, as an omitted value's retrieval command writes it.
  • Read a recorded source. --source MODULE shows a module from the recorded, checked sources, never the file you're editing. Control and format characters are shown escaped, and --json and an export keep the recorded text unchanged.
  • Re-run for more detail. --rerun re-runs the program as replay does, answering every call from the record, and adds the values that come from re-running, such as where in the source each call was made. They're a view, not history.
  • Stop at a moment. --at MOMENT re-runs up to that moment and shows the step the task took there and its stack, innermost frame first, with each frame's bound locals. It lists the run's other tasks where this replay left them, labelled as a view. A moment the run never reached is refused, naming the last one it can reach. --at with CALL is a usage error.
  • Browse full screen. --tui opens a terminal inspector over the same view, where you can pick a run, a call or a fact, and filter by Tool. It needs a terminal.

None of these changes the history or its replay verdict. flow replay RUN checks a record against its program, and --trace prints a task's steps (replay).

Move a run to another machine

flow runs export RUN writes one file, to standard output or to the file --out names:

flow runs export nightly --out nightly.flowrunflow replay nightly.flowrunflow runs import nightly.flowrun --name nightly-copy

The file holds the run's history, with every module source it names, and its host notes. Export only reads, so it works while the run is going, and gives the history as of its last commit. The file replays without being imported, and flow test replays it as a regression test. It isn't cleaned for sharing: it may hold sources, inputs, answers and host notes.

flow runs import FILE copies the run in under a new run id, so each key still names exactly one call. It copies every fact through the last, End included, and records the first fact's parent as a fork of the exported run at its last fact, for an open run and a completed one alike. An open run goes on from its last fact with its keys under the new id, and a completed one arrives completed and can be replayed. An imported run was started from no file on this machine, so flow resume without FILE continues it on its recorded program. Import refuses a damaged or truncated file. Replies addressed to the original run's keys never reach the copy.

Know what the background host does

The background host is flow daemon, the same binary as the CLI, one per FLOW_HOME. It drives every live run flow run and flow resume start. You don't start it yourself: a CLI client starts it when it isn't running, detached in a new session and with no administrator rights. A toolkit reply connects only to the socket it is given or that FLOW_REPLY_SOCKET names; it never starts a host.

flow daemon statusflow daemon stop

It keeps its files under FLOW_HOME, by default ~/.flow:

Entry Holds
daemon.sock the socket clients connect to; only its owner may connect
daemon.lock the lock that makes one process the host for this FLOW_HOME
daemon.log the host's own log
runs/<id>/ each run's history and caches
approvals the remote library commits whose native code may run (Approve a repository's native code)
  • Idle exit. The host exits after 30 seconds with nothing to do: no run it holds is waiting, nothing is attached, and nothing is due. A run that waits for a reply, has a retry_at timer or has a call out keeps it alive. A stopped or ended run doesn't. Two clients that start a host at once start two processes, and the lock lets one of them serve while the other exits. flow daemon install keeps it running as a per-user service (Runs in the background).
  • Processes. For each run the host starts an evaluator, a flow process in the client's working directory with the client's environment, and the evaluator starts the run's implementation processes. If an evaluator dies, its calls out stay open, with no stop recorded, until flow resume continues the run. A panic during evaluation stops the run with the host reason for the evaluator ending.
  • Environment. flow run and flow resume send the client's environment and working directory with the request. The host keeps them in memory for that run only, starts the run's processes with them, and adds its own socket as FLOW_REPLY_SOCKET, so a toolkit's reply reaches it. Nothing writes them to disk. A host that restarts has no environment for any run, so each run it was driving stops with the reason host restarted. Replies still reach those runs, and the next flow resume supplies the environment and continues.
  • Upgrades. Every connection begins with a handshake. A client of the same build goes ahead, and an older client is refused. A newer client drains an older host: the old host gives up its socket and lock, keeps driving its runs, and releases each one, with a flow.released note, once none of its calls is out without a hold. It then hands the run's id, environment and working directory to the new host, which continues the run as flow resume with that environment would. If the new host can't be reached, the run waits for the next flow resume. A client attached during the drain loses its connection, and the run goes on.
  • Stopping the host. flow daemon stop stops every run the host drives, as flow stop does, waits until none of their calls is out, and exits. With --now it cancels those calls, as flow stop --now does, and exits once the stops are recorded. A host that ends any other way, at a reboot or when it's killed, leaves its runs as they were. The next flow resume of such a run records that the host restarted.
  • What it never does. It never closes an open call, never sends a call again unless the call's implementation asked or you resend it, and makes no decision about what a run means.

On a platform where the daemon cannot run, flow run and flow resume refuse. flow check, flow test and flow replay need no host and work there.

Set where Flow keeps its files and toolchains

The CLI and the daemon take these settings from their environment, where an empty variable is unset:

Variable Sets When it's unset
FLOW_HOME where Flow keeps its files ~/.flow
FLOW_CACHE fetched repositories, the listings a library's process is handed and the freshness records of contracts cache under FLOW_HOME, else a directory under the temporary directory
FLOW_OFFLINE any value but 0: the host fetches nothing online
FLOW_STD the standard library to use instead of the installed one the installation's
FLOW_REPLY_SOCKET the socket a toolkit reply connects to an explicit socket is required
FLOW_OTEL any value but 0: export telemetry (Telemetry) no export

The host prepares no implementation (The host boundary): it keeps no environment or build of its own for a library, and starts command and extract as they are written. A toolkit makes its own build or environment on demand (Writing a library). An application that embeds Flow chooses these settings for itself (Embedding). No history records them.

Generators. The host stops a library's extract or an MCP server's tool listing after 15 minutes, and generates no contract from it.

Symbolic links. A local library is read at its import path, even where a symbolic link on that path leads outside the program's directory, because the program's tree is its author's. A fetched library is read only within its own root: one that holds a symbolic link leading out of it is refused by flow check and flow run alike, before anything starts. A link that stays inside the library is read like any other file.

Pins. The commit pinned for each remote tag is kept in a per-machine cache. A tag that moved is accepted only through flow update FILE. A run never reads that cache: replay and resume use the commits its Program facts record.

Telemetry. The CLI exports traces, metrics and logs of its own work over OTLP only when FLOW_OTEL is set to any value but 0, so a variable meant for another service, such as OTEL_EXPORTER_OTLP_ENDPOINT, never sends your runs anywhere. Once it's on, the standard OpenTelemetry variables configure export: the endpoint and header variables, OTEL_SDK_DISABLED=true, which turns it off, and OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER and OTEL_LOGS_EXPORTER, each otlp or none. Export is HTTP with protobuf payloads. Another exporter or protocol is refused with a status line, and the command goes on without export. What's exported describes the CLI's work, never a call's arguments, a reply or the environment, and a failed export never changes a command's output or exit code.

FLOW_OTEL=1 OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 flow run app.flow

Approve a repository's native code

The first time a run would start an implementation from a remote library at a given commit, the CLI asks before the run starts, and remembers your answer for that commit in FLOW_HOME's approvals, never in a history. To give the consent ahead of time:

flow approve app.flowflow approve app.flow --yes

flow approve asks once at a terminal, and --yes approves without asking, for CI. A declined or missing consent refuses the run. A local library isn't asked about. A re-ask, a reply or a nested run uses the commits the run recorded, which were approved when it started, so it never asks. A new nested run whose bundle reaches remote code that isn't approved is refused, and the runs request that started it answers Refused. The MCP server never asks, and refuses a run whose code isn't approved.

Read a run's store and notes

The host keeps each run in a directory under FLOW_HOME/runs: its history, with the host's notes in it, and a host log. The history is the truth about the run, and everything else beside it is a cache the host may delete, such as checkpoints and the index of run names. Run ids are 128 random bits.

flow runs --since 2hflow runs delete nightly --yes

The host writes every commit to the operating system before its consequence, and synchronizes the history to storage only right before it sends a call, asks a held call again, or sends one again for a caller (durability). So a crash of a process tears at most a history's last span, and a loss of power can lose answers and replies recorded since the last call went out. The host keeps no record of where its last synchronization falls, so after a loss of power it reports a history whose earlier span tore under a whole later one as damaged, and doesn't resume it. One writer holds a run at a time, by an advisory lock on its directory.

Checkpoints. Beside a history the host may keep checkpoints: the state the run reached at a fact, from which it continues or replays instead of running from the start. The store keys each by the run, the segment, the fact and the program's identity, and may delete any of them. A checkpoint that can't be restored to exactly the state re-running reaches is discarded, and the run is re-executed from its start.

Notes. The host writes these host notes, each under its name in the flow namespace. A note's bytes are its members in order, in the value encoding: a time as an Instant, a count or a fact's number as a number, a text, a name, a run id or a command line as a text, and a choice as its number followed by what it carries.

A note such as flow.stopped or flow.waiting describes the recorded state until a fact follows it. When a live host is driving the run, flow show and flow runs use its current state instead. A resume accepted while the run is stopping shows running at once, before another fact is recorded.

Name Members Written when
flow.stopped the last fact's number; reason, a stop reason; and open, the calls open when it stopped a run stops, and again, with the same reason and the calls still open, in the commit of each answer or reply that arrives while it's stopped
flow.waiting the last fact's number; open, each open call; and each held call with its next retry_at each commit that leaves the run waiting
flow.resent calls, and request: 0, or 1 followed by the asking key a caller asked for open calls to be sent again, before any of them is sent
flow.replied call, and from: who sent the reply, as the host knows them the commit that records a reply from outside the implementation
flow.named name a run is given its name
flow.released for: the build of the host taking the run over a host gives the run up during an upgrade
flow.bound tool: the declaration, as its library, 0 or 1 followed by the library's version, its module path and its name; by: command or mcp followed by the command line that starts its process, or in process the host binds a declaration the run can reach, each time it binds the run
flow.late-answer call, and outcome: its number as the history format gives it, then its value at the call's return type, or a problem's reason as a text an implementation answered a call that was already answered or closed; the answer is dropped
flow.declined call, reason the host declined a call instead of sending it the first time
flow.source-root root: the absolute directory the program was formed from on this machine the host binds a run whose program it formed from files here; resume reads it to find the file the run was started from
flow.started at: when the run started; build: the build of the host that started it the run's first commit
flow.receipt key: the asking key, as the asking run's id and a call id; answer: the answer given, at the asking call's result type the commit that makes the change a request with an asking key asked for
flow.ended at: when the run ended; outcome: 0 when the entry returned a value, 1 when it returned its Err its own commit right after the one that holds End, written in the same write

A flow.stopped reason is its number, then its members, as runs.StopReason types it:

Number Reason Members
0 asked by: 0, or 1 followed by the id of the run whose runs.stop asked
1 fault fault, module, line and column from 1; fault is 0 division-by-zero, 1 stopped-task, 2 first-of-none, 3 call-depth, 4 value-depth, 5 decimal-scale, 6 int-size, 7 decimal-size or 8 text-size
2 tool-bug call, problem: 0 no-answer and its words, 1 not-an-answer and what is wrong, 2 process-ended, or 3 dropped; words are cut to at most 4 KiB
3 working none
4 host host, the host's name, and words, its description of the cause
5 outer run, the starter's id, and call: 0, or 1 followed by the starter's call whose closing stopped it

For a cause of its own, the host writes host with the name flow and words such as "the host driving it was stopped", "the process evaluating it ended" or "the host driving it restarted".

Serve Flow to an MCP client

flow mcp serves checking, formatting, testing, documentation and diagnostic explanation, beside run, resume, stop, replay, show and runs, to an MCP client over standard input and output, one JSON-RPC message per line:

{ "mcpServers": { "flow": { "command": "flow", "args": ["mcp"] } } }

Each tool means what the command of the same name means, and publishes its input and result schemas; its result is the data of that command's --json document (command output). The server answers requests concurrently, so a long run holds up no other request. It runs a run's evaluation in its own process. A client that cancels the call driving a run stops the run, and nothing answers that call. The server never asks a person anything.

  • show takes run, an optional fact kind, and an optional offset and limit, from 1 to 200, 50 by default. Without offset it returns the first limit facts; with one, the limit facts from that position. It filters before it pages, and keeps facts' numbers. Fact text is cut to 1024 code points, and a fact value larger than 4096 bytes of JSON is left out whole, with a reference that fetches it. An optional source module and source_offset return up to 4096 code points of a recorded source at a time. logs: true adds the run's log lines.
  • replay takes an optional trace with from, to and limit, and show an optional at and value, as flow replay --trace, flow show --at and --value do. test takes an optional only, a list of test names.
  • runs lists stored runs newest first, without running a program or reading module sources, and shows no value. limit is 20 by default, from 1 to 200, and after continues after a page's next_after. You can filter a page by entry, and by since and until start times as RFC 3339 text. flow runs takes the same filters, and its times may also be a date, meaning its midnight in local time, or a duration back from now, such as 2h. Filtering never widens the scan: inspected counts the runs looked at before filtering. Listing selects, resumes and changes nothing.

Exact rules: the CLI contract, requests to a run, stopping a run, the history format.