# flight
> Reference for the motherduck flight command group - init, push, pull, run, logs, the Flight Explainer, secrets, schedules, and versions.
Create and manage [Flights](/key-tasks/flights/), Python data pipelines that
run on a schedule or on demand. You build a Flight locally, push it to
MotherDuck, then trigger runs and read their logs.

## Usage

```bash
motherduck flight <command> [options]
```

## Commands

| Command | Description |
|---|---|
| [`guide`](#flight-guide) | Print the Flight authoring guide, or the Flight Explainer guide with `--explainer` |
| [`init`](#flight-init) | Initialize a new Flight in a local directory |
| [`push`](#flight-push) | Push a local Flight to MotherDuck |
| [`pull`](#flight-pull) | Pull a Flight from MotherDuck into a local directory |
| [`run`](#flight-run) | Run a Flight once, now |
| [`get-run`](#flight-get-run) | Show the status and timing of one Flight run |
| [`cancel`](#flight-cancel) | Cancel a running Flight run |
| [`logs`](#flight-logs) | Print the logs of a Flight run |
| [`explain`](#flight-explain) | Show a Flight run's steps, or preview its chart |
| [`list-runs`](#flight-list-runs) | List the runs of a Flight |
| [`list`](#flight-list) | List the Flights owned by the current user, or visible in their organization |
| [`list-versions`](#flight-list-versions) | List the versions of a Flight in MotherDuck |
| [`create-secret`](#flight-create-secret) | Create a flight secret |
| [`list-secrets`](#flight-list-secrets) | List your flight secrets |
| [`delete-secret`](#flight-delete-secret) | Delete a flight secret |
| [`delete`](#flight-delete) | Delete a Flight from MotherDuck |

Every command also takes the [global options](./index.md#global-options).

## Flight directories

A Flight directory holds:

```text
my_flight/
├── main.py                # the script, run as `python main.py`
├── requirements.txt       # packages to install first (optional)
├── chart.mmd             # the run chart for the Flight Explainer (optional)
└── flight.metadata.json   # name, schedule, config, instance_type, and the
                           # Flight ID that push and pull resolve
```

`chart.mmd` holds the Flight's chart as raw Mermaid, starting at the
`flowchart` line, with no code fences. See
[Watch Flight run progress with the Flight Explainer](/key-tasks/flights/observability/explain-flight-runs/).

`flight pull` writes the version's `instance_type` into `flight.metadata.json`
and `flight push` reads it back, so a Flight's size survives a copy or clone of
the directory:

```json
{
  "id": "<flight_id>",
  "name": "my_flight",
  "version": 6,
  "max_runtime_sec": 600,
  "instance_type": "F16"
}
```

Commands that act on one Flight take its directory (or `--dir`), and read the
ID from `flight.metadata.json`. Pass `--flight` instead to name it outright, as
an ID or an app URL:

```bash
--flight 123e4567-e89b-12d3-a456-426614174000
--flight https://app.motherduck.com/flights/my-flight-123e4567-e89b-12d3-a456-426614174000
```

A URL ending in `/versions/<n>` also selects that version for `pull`, unless
`--version` says otherwise.

Where a command below says **which Flight**, the rule is the same: `--flight`,
else the ID recorded in the Flight directory's `flight.metadata.json`. Given
both, the two must resolve to the same ID. Given neither, the ID is read from
`flight.metadata.json` in the current directory.

## `flight guide`

Print the Flight authoring guide — read this before writing or editing a
Flight.

The guide covers the runtime's expectations, the supported APIs, and the data
pipeline practices it assumes. It's written for an AI agent to consume
directly. See [working with agents](/getting-started/interfaces/motherduck-cli/agents/).

```bash
motherduck flight guide [options]
```

### Options

| Option | Description |
|---|---|
| `--explainer` | Print the Flight Explainer guide instead: the chart convention and the `@flight-run` and `@flight-log` lines a Flight prints so its runs can be viewed step by step |

### Examples

```bash
motherduck flight guide              # the authoring guide
motherduck flight guide --explainer    # the Flight Explainer convention
```

## `flight init`

Creates a new local Flight directory and writes `main.py`,
`requirements.txt`, and `flight.metadata.json` there. With `--chart`, it also
writes a one-step starter `chart.mmd`. It refuses to overwrite `main.py`,
`requirements.txt`, or `flight.metadata.json`. `--chart` also refuses an
existing `chart.mmd`. Without `--chart`, an existing `chart.mmd` is kept.

```bash
motherduck flight init [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Directory to create the Flight in. Defaults to a directory named after `--name` |

### Options

| Option | Description |
|---|---|
| `--name <string>` | Flight name. Required |
| `--dir <path>` | Directory to create the Flight in. Defaults to a directory named after `--name` |
| `--chart` | Also write a starter `chart.mmd` chart for the Flight Explainer |

### Examples

```bash
motherduck flight init --name my_flight             # create ./my_flight
motherduck flight init flight_dir --name my_flight  # create ./flight_dir
motherduck flight init --name my_flight --chart     # with a starter chart.mmd
```

## `flight push`

Publishes a local Flight to MotherDuck, creating it when
`flight.metadata.json` has no ID and updating it after that. Every push makes a
new version. The options below override what that file records, and are written
back into it.

When the directory has a `chart.mmd`, push sends it as the Flight's chart.
Without the file, the chart on MotherDuck stays as it was. An empty or blank
file clears the chart. A chart larger than 64 KiB is rejected before anything
is sent.

```bash
motherduck flight push [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Directory holding the local Flight. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--dir <path>` | Directory holding the local Flight. Defaults to the current directory |
| `--name <string>` | Flight name |
| `--schedule-cron <cron>` | Schedule as a 5-field cron expression in UTC, for example `"0 9 * * 1-5"`. Pass `""` to unschedule |
| `--config <json>` | Non-secret values exposed to the Flight as environment variables, for example `'{"TARGET_DB":"prod"}'` |
| `--access-token-name <string>` | MotherDuck access token the Flight runs with |
| `--secret-names <names>` | Comma-separated MotherDuck secret names to expose |
| `--max-runtime-sec <n>` | Per-run timeout in seconds. `0` means no timeout |
| `--instance-type <size>` | [Instance size](/about-motherduck/billing/flight-sizes/): `F4`, `F16`, or `F32`, named after its memory in GB. Defaults to the size in `flight.metadata.json`, else your plan's default |
| `--run` | Run the Flight once after pushing |

### Examples

```bash
motherduck flight push my_flight                # push ./my_flight
motherduck flight push                          # push the current directory
motherduck flight push my_flight --run          # push, then run it once
motherduck flight push my_flight --schedule-cron "0 9 * * 1-5"
motherduck flight push my_flight --schedule-cron ""     # stop the schedule
motherduck flight push my_flight --config '{"TARGET_DB":"prod"}'
motherduck flight push my_flight --instance-type F16   # new version at F16
motherduck flight push my_flight                       # still F16, not the plan default
```

## `flight pull`

Fetches a Flight from MotherDuck. It overwrites existing `main.py`,
`requirements.txt`, and `flight.metadata.json`, and writes `chart.mmd` when the
version has a chart, including an empty file when the chart was cleared. When
the version has no chart, pull removes any local `chart.mmd`. A later push
then leaves the Flight's current chart in place. To clear it, push an empty
`chart.mmd`. Find IDs with
[`flight list`](#flight-list).

```bash
motherduck flight pull [options] [id-or-url]
```

Which Flight: the positional ID or app URL, otherwise the ID recorded in
`flight.metadata.json` in the destination directory.

Where to pull: `--dir`, otherwise the current directory. Pull writes files, so
it always has a destination.

### Arguments

| Argument | Description |
|---|---|
| `id-or-url` | Flight ID or app URL. Defaults to the ID from `flight.metadata.json` |

### Options

| Option | Description |
|---|---|
| `--dir <path>` | Directory to pull the Flight into. Defaults to the current directory |
| `--version <n>` | Pull a specific version. Defaults to the one named by the Flight URL, else the latest |

### Examples

```bash
motherduck flight pull                             # update the Flight in the current directory
motherduck flight pull <id-or-url>                 # into the current directory
motherduck flight pull <id-or-url> --dir my_flight
motherduck flight pull <id-or-url> --version 2
```

## `flight run`

Runs a Flight's current version once, now. The run is queued and the command
returns its number right away. Check its status with
[`flight get-run --run <n>`](#flight-get-run) and read its output with
[`flight logs --run <n>`](#flight-logs).

```bash
motherduck flight run [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--flight <id-or-url>` | Flight ID or app URL |
| `--dir <path>` | Flight directory to read the Flight ID from. Defaults to the current directory |
| `--config <json>` | Override config values for this run only. Keys must already be defined on the Flight, for example `'{"TARGET_DB":"staging"}'` |

### Examples

```bash
motherduck flight run                            # the current directory's
motherduck flight run my_flight
motherduck flight run --flight <id-or-url>
motherduck flight run my_flight --config '{"TARGET_DB":"staging"}'
```

## `flight get-run`

Shows one run of a Flight: its status, the version and config it ran with, and
when it was queued, started, and ended. Run it again to poll a run until it
finishes. Run numbers come from [`flight list-runs`](#flight-list-runs).

```bash
motherduck flight get-run [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--run <number>` | Run number. Required |
| `--flight <id-or-url>` | Flight ID or app URL |
| `--dir <path>` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Examples

```bash
motherduck flight get-run --run 4                # the current directory's
motherduck flight get-run my_flight --run 4
motherduck flight get-run --flight <id-or-url> --run 4 -o json
```

## `flight cancel`

Stops a run of a Flight. Only a pending or running one can be cancelled, and
only on a Flight you own, unless you're an Admin, who can cancel runs of any
Flight in the organization. Run numbers come from
[`flight list-runs`](#flight-list-runs).

```bash
motherduck flight cancel [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--run <number>` | Run number to cancel. Required |
| `--flight <id-or-url>` | Flight ID or app URL |
| `--dir <path>` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Examples

```bash
motherduck flight cancel --run 4                 # the current directory's
motherduck flight cancel my_flight --run 4
motherduck flight cancel --flight <id-or-url> --run 4
```

## `flight logs`

Prints what a run has printed so far, stdout and stderr together, verbatim so
it can be piped. Run numbers come from [`flight list-runs`](#flight-list-runs).

It prints the last 100 lines unless `--tail` or `--head` says otherwise.
`--offset` pages from the same end: `--tail 50 --offset 50` prints the 50 lines
before the last 50. When more lines remain, it says on stderr which `--offset`
reads the next page. JSON output has it as `next_offset`.

```bash
motherduck flight logs [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--run <number>` | Run number. Required |
| `--flight <id-or-url>` | Flight ID or app URL |
| `--dir <path>` | Flight directory to read the Flight ID from. Defaults to the current directory |
| `--tail <number>` | Print the last `<number>` lines. Defaults to 100 |
| `--head <number>` | Print only the first `<number>` lines. Can't be combined with `--tail` |
| `--offset <number>` | Skip this many lines first, from the end `--head` or `--tail` reads from |

### Examples

```bash
motherduck flight logs --run 4                   # the current directory's
motherduck flight logs my_flight --run 4
motherduck flight logs --flight <id-or-url> --run 4 | grep -i error
motherduck flight logs my_flight --run 4 --tail 50
motherduck flight logs my_flight --run 4 --head 20
```

## `flight explain`

Shows what a run did: each step the Flight's chart declares, with the status,
rows, duration, and error its `@flight-run` log lines reported. A Flight that
declares no chart has no steps to show; the command says so and points to
[`flight guide --explainer`](#flight-guide). See
[Watch Flight run progress with the Flight Explainer](/key-tasks/flights/observability/explain-flight-runs/).

```bash
motherduck flight explain [options] [dir]
```

Which run: `--run`, else the run a `--flight` run URL names, else the most
recent run. That lookup returns the run's number. It is not left null.

`--watch` reads that run every 5 seconds until it ends. In table mode it prints
each step's status change as it happens, then the final table. With `-o json`
or `-o csv` it prints only the final result.

`--open` also opens the run in the app's Flight Explainer and prints the URL on
stderr. The link does not force the explainer tab on. JSON includes that URL
as `url` whether you pass `--open`.

`--preview` shows the chart with no run: each step, its kind, and the steps it
leads to. It reads the pushed version's chart the same way the app does. A
legacy `@flight` block in `main.py` counts only when the chart field is absent
or does not parse, and an empty chart field means no chart. `--version` picks
the version. `--file` renders a local `.mmd` or `.py` file instead, so you can
check a chart before pushing. `--preview` cannot be combined with `--run`,
`--watch`, or `--open`.

### Arguments

| Argument | Description |
|---|---|
| `dir` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--run <number>` | Run number. Defaults to the run a `--flight` run URL names, else the most recent run |
| `--flight <id-or-url>` | Flight ID or app URL. A run URL also selects that run |
| `--dir <path>` | Flight directory to read the Flight ID from. Defaults to the current directory |
| `--watch` | Read the run again every 5 seconds until it ends. In table mode, prints each step's status change as it happens, then the final table. With `-o json` or `-o csv`, prints only the final result |
| `--open` | Also open the run in the app's Flight Explainer, and print its URL on stderr |
| `--preview` | Show the steps the chart declares, without a run |
| `--version <n>` | With `--preview`: the version to read. Defaults to the version a `--flight` URL names, else the current one |
| `--file <path>` | With `--preview`: render a local `.mmd` or `.py` chart file instead of a pushed Flight |

### Output

The run heading is printed on stderr. The table is stdout. It lists one row per
step, in chart order, with child steps indented under their parent. A fan-out
with more than one instance shows its status as `failed (×2)` and lists each
instance on its own row under the summary. Steps that a failed or cancelled run
never reached show as `not reached`. A step a succeeded run never started shows
as `skipped`. Durations come from the steps' `ts=` fields, so they're blank when
a Flight doesn't print them. A non-zero exit code is appended to the heading.

```text
$ motherduck flight explain my_flight --run 42
Run 42 (version 7): FAILED, exit code 1
step       label                 status       rows   duration  error
---------  --------------------  -----------  -----  --------  ----------------------------------
extract    Pull orders from API  ok           12840  4.2s
normalise  Flatten and cast      ok           12840  900ms
load       Write to warehouse    ok           12840  14s
verify     Row counts match?     failed              700ms     12840 rows loaded, 12838 in source
publish    Promote to prod       not reached
```

With `-o json`, the result is a `run` object with `flight_id`, `run_number`,
`flight_version`, `status`, `outcome`, `exit_code`, `started_at`, `ended_at`,
`has_chart`, `truncated`, `url`, and a `steps` array. Each step has `step`,
`label`, `parent`, `depth`, `kind`, `status`, `rows`, `duration_ms`, `error`,
`instance_count`, `instances`, and `not_reached`. A step a failed or cancelled
run never reached keeps the status `pending` and sets `not_reached: true`.
With `-o csv`, each step is one row: `step`, `label`, `parent`, `kind`,
`status`, `rows`, `duration_ms`, `error`, `instance_count`, `not_reached`.

The command reads the first 5,000 lines of the run's log, and a read can also
be cut at 4 MB. When the log was cut, it warns, sets `truncated: true`, and
steps that started after that point read as pending.

### Examples

```bash
motherduck flight explain                           # latest run, current directory
motherduck flight explain my_flight --run 4
motherduck flight explain --flight <run-url> --watch --open
motherduck flight explain --flight <id-or-url> -o json
motherduck flight explain my_flight --preview       # the chart, no run
motherduck flight explain --preview --file my_flight/chart.mmd
```

## `flight list-runs`

Lists a Flight's runs, newest first, with the version each one ran and how it
ended. The run numbers here are what `--run` takes.

```bash
motherduck flight list-runs [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--flight <id-or-url>` | Flight ID or app URL |
| `--dir <path>` | Flight directory to read the Flight ID from. Defaults to the current directory |
| `--limit <number>` | Limit results. Defaults to 100 |
| `--offset <number>` | Result offset. Defaults to 0 |

### Examples

```bash
motherduck flight list-runs                      # the current directory's
motherduck flight list-runs my_flight --limit 5
motherduck flight list-runs --flight <id-or-url>
```

To watch one run from a script, poll [`flight get-run`](#flight-get-run) with
`-o json` and read the `status` field rather than parsing the table.

## `flight list`

Newest first, by the time each Flight was last updated.

`--name` filters the page `--limit` and `--offset` selected, so it can return
fewer rows than `--limit`. Raise `--limit` to search deeper.

```bash
motherduck flight list [options]
```

### Options

| Option | Description |
|---|---|
| `--limit <number>` | Limit results. Defaults to 100 |
| `--offset <number>` | Result offset. Defaults to 0 |
| `--name <text>` | Only Flights whose name contains this text, case insensitive |
| `--all` | Include Flights shared with your organization. Defaults to false |

### Examples

```bash
motherduck flight list
motherduck flight list --name nightly            # names containing "nightly"
motherduck flight list --name nightly --limit 500
motherduck flight list --all                     # the organization's too
```

## `flight list-versions`

Lists a Flight's versions in MotherDuck, one per push, newest first, with the
`instance_type` each one runs on. Fetch one with
[`flight pull --version <n>`](#flight-pull).

```bash
motherduck flight list-versions [options] [dir]
```

### Arguments

| Argument | Description |
|---|---|
| `dir` | Flight directory to read the Flight ID from. Defaults to the current directory |

### Options

| Option | Description |
|---|---|
| `--flight <id-or-url>` | Flight ID or app URL |
| `--dir <path>` | Flight directory to read the Flight ID from. Defaults to the current directory |
| `--limit <number>` | Limit results. Defaults to 100 |
| `--offset <number>` | Result offset. Defaults to 0 |

### Examples

```bash
motherduck flight list-versions                  # the current directory's
motherduck flight list-versions my_flight
motherduck flight list-versions --flight <id-or-url> --limit 5
```

## `flight create-secret`

Stores a flight secret in MotherDuck, from `KEY=VALUE` pairs or a dotenv file.
A Flight reads its fields as environment variables once it's attached with
[`flight push --secret-names`](#flight-push). Values are never printed back.

```bash
motherduck flight create-secret [options] <name> [pairs...]
```

### Arguments

| Argument | Description |
|---|---|
| `name` | Name of the secret. This is what `--secret-names` takes |
| `pairs...` | Inline `KEY=VALUE` fields. Omit when using `--secrets-file` |

### Options

| Option | Description |
|---|---|
| `--secrets-file <path>` | Read fields from a dotenv-format file instead of inline `KEY=VALUE` pairs. Double-quote any value containing `#` or leading or trailing whitespace |
| `--if-exists <action>` | What to do when the name is taken: `ignore`, `error`, or `replace`. Defaults to `error` |

### Examples

```bash
motherduck flight create-secret my_api_creds api_key=key123
motherduck flight create-secret my_api_creds --secrets-file ./secrets.env
motherduck flight create-secret my_api_creds --if-exists replace api_key=key456
motherduck flight create-secret my_api_creds --if-exists ignore api_key=key123
motherduck flight push my_flight --secret-names my_api_creds   # attach it
```

:::warning
Inline values are visible in your shell history and to other processes on the
machine. `--secrets-file` keeps them out of the command line.
:::

## `flight list-secrets`

Lists the flight secrets stored in MotherDuck: their names and shape, never
their values. These are the names `--secret-names` takes.

```bash
motherduck flight list-secrets [options]
```

### Examples

```bash
motherduck flight list-secrets
motherduck flight list-secrets -o json
```

## `flight delete-secret`

Removes a flight secret from MotherDuck. Any Flight that still names it fails
on its next run, so check [`flight list`](#flight-list) first if you're unsure.

```bash
motherduck flight delete-secret [options] <name>
```

### Arguments

| Argument | Description |
|---|---|
| `name` | Name of the secret to remove |

### Options

| Option | Description |
|---|---|
| `--if-not-exists <action>` | What to do when the secret isn't there: `ignore` or `error`. Defaults to `error` |
| `--dangerously-skip-confirmation` | Delete without interactive confirmation |

### Examples

```bash
motherduck flight delete-secret my_api_creds
motherduck flight delete-secret my_api_creds --if-not-exists ignore
motherduck flight delete-secret my_api_creds --dangerously-skip-confirmation
```

## `flight delete`

Deletes a Flight from MotherDuck, along with its versions, schedule, and run
history. This can't be undone. The local files stay where they are.

```bash
motherduck flight delete [options]
```

### Options

| Option | Description |
|---|---|
| `--flight <id-or-url>` | Flight ID or app URL. Required |
| `--dangerously-skip-confirmation` | Delete without interactive confirmation |

### Examples

```bash
motherduck flight delete --flight <id-or-url>
motherduck flight delete --flight <id-or-url> --dangerously-skip-confirmation
```

:::warning
Pass `--dangerously-skip-confirmation` only in scripts where you've already
confirmed the ID.
:::

## Related

- [Flights](/key-tasks/flights/)
- [Scheduling and runs](/key-tasks/flights/scheduling-and-runs/)
- [Watch Flight run progress with the Flight Explainer](/key-tasks/flights/observability/explain-flight-runs/)
- [Flight authentication, config, and secrets](/key-tasks/flights/flights-authentication-config-and-secrets/)
- [`dive`](./dive.md)


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

URL-encode query parameter values and send a GET request:

```text
GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fsql-reference%2Fmotherduck-cli%2Fflight%2F&page_title=flight&text=<url-encoded user feedback, max 2000 characters>
```

Optionally append `&source=<url-encoded interface identifier>` such as `claude.ai` or `chatgpt`.

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed query parameters, and `429` when rate-limited.
