---
title: weft CLI reference
description: Every weft command (studio, dev, runs, open, export, doctor, mcp, vacuum, version, help) with each flag's environment variable, default and effect, and the exit codes.
url: https://weftgo.dev/docs/reference/cli/
type: reference
sources:
  - 'weft/otel/options.go:104-123 (DevMode), 169-198 (DevDetail, dev-gated); weft/otel/pipeline.go:241-311, 931-960 (the gate, its WARNs and the DevMode INFO lines); weft/obsdb/request.go:93, 149, 167-168 (the gap and raw_off fixes name otel.DevMode()); weft/CHANGELOG.md:124 (0.19.0: DevMode), 35 (0.20.0: DevDetail)'
  - 'observed: the release candidate''s weft binary (go build ./cmd/weft at ../weft-rc020): weft --help and every -h; weft studio on a scratch SQLite file and a second start on it; weft runs, weft open (no id, a run id, --with-token), weft doctor against it after posting docs-site/examples/otherlang/stock-spans.json; usage errors; weft vacuum --retain 1h'
  - weft/cmd/weft/resolve.go:1-120 (the one resolver, the token rule, the stderr line)
  - weft/cmd/weft/main.go:286-300 (gotArgs), 413 (version takes no arguments)
  - 'weft/CHANGELOG.md:43 (0.20.0: the resolver, open''s ids, runs'' columns, doctor''s discovery/data/otlp lines and hints, the banner''s sign-in line), 57 (usage errors, two-dash flags in -h, vacuum''s WAL), 83-85, 93 (breaking: the lock; the lock file left on exit, non-regular files and hard links refused — v0.20.2; the --url default, the runs columns, the manifest label), 159 (0.19.0 breaking: export --wefttest)'
  - 'weft/cmd/weft/main.go:1-242 (the package doc: every command), 236-237 (exit codes), 324-344 (the usage text), 350-373 (run: 0, 1, 2 and the app''s code), 390-426 (dispatch: help, version, unknown command)'
  - 'weft/cmd/weft/main.go:441-495 (weft studio''s flags), 504-514 (wantAddr: --addr, then WEFT_STUDIO_ADDR, both pin), 522-551 (manifestOptions), 569-577 (clientFlags); weft/cmd/weft/resolve.go:15-80 (resolveStudio), 589-605 (runDoctor), 633-702 (serveWith: the banner, the notes, the discovery file), 731-738 (ReadHeaderTimeout 10 s, IdleTimeout 2 min), 768-808 (SIGINT, SIGTERM, SIGHUP: five-second grace), 823-862 (serveBootWith: the token lines), 874-908 (newServer: --db forms), 925-981 (dbFile, dbLabel, maskDSN)'
  - 'weft/cmd/weft/dev.go:71-143 (weft dev''s flags; the manifest, retention and pricing notes are dropped), 197-233 (devEnv), 252-384 (devStudio), 415-475 (the loop: exit with the app''s code, 127)'
  - 'weft/cmd/weft/api.go:37-50 (2 min timeout, redirects never followed), 63 (512 MiB response cap), 122-124 (the 401 hint), 146-161 (parseArgs: positional arguments anywhere), 167-296 (the runs table cells), 300 (page size 100), 304-451 (runRuns), 455-466 (parseSince), 475-512 (runOpen), 568-637 (runExport), 802-888 (unzipFixtures)'
  - 'weft/cmd/weft/mcp.go:39-44 (max_bytes 64 KiB, at most 4 MiB), 388-474 (the 22 tools), 112-162 (runMCP: --url, --token, --read-only)'
  - 'weft/cmd/weft/vacuum.go:21-25 (--retain), 31-50 (resolveRetain: exit 2), 69-124 (runVacuum and its lines), 126-164 (openVacuumDB: a missing file is refused), 167-180 (fileSizes: the file and its -wal sidecar, apart)'
  - weft/cmd/weft/pricing.go:14-38 (--pricing, WEFT_PRICING, exit 1)
  - 'weft/cmd/weft/logflags.go:22-31 (--log-level, --log-format), 36-73 (install: warning accepted, case-insensitive)'
  - weft/cmd/weft/token.go:17-30 (the dev token), 52 (printable), 56-82 (resolveToken)
  - weft/cmd/weft/devproc_unix.go:64 (devSignals), 69-74 (SIGHUP sent as SIGTERM)
  - weft/internal/listen/listen.go:56-67 (DefaultAddr, DefaultSpan 10, ProbeTimeout 2 s), 144-192 (Choose)
  - weft/internal/doctor/doctor.go:31 (Timeout 5 s), 43-55 (Lines), 153-230 (Run), 408-418 (panel FAIL)
  - 'weft/README.md:379-410 (The weft command: the command table, the flag table)'
  - 'weft/cmd/weft/browser.go:18-45 (openURL: open, rundll32 url.dll,FileProtocolHandler, xdg-open; openBrowser: one line, never an exit)'
  - 'weft/cmd/weft/main.go:522-550 (manifestOptions: the banner line, the read and parse errors; 456-464 decodes into {weft int, agents []}, so missing keys pass), 724-734 (httpServer: ReadHeaderTimeout 10 s, IdleTimeout 2 min, no write or body timeout)'
  - 'weft/cmd/weft/api.go:37-48 (CheckRedirect: never followed), 57-63 (maxBody, maxUnzip 512 MiB), 94-100 (the redirect error), 802-888 (unzipFixtures: every refusal; 534-541 the two layout messages; 547-565 names and declared sizes before any write; 569-579 old *.json removed; 590-592 the as-read size check), mcp.go:171 (weft mcp uses the same client)'
  - 'weft/internal/doctor/doctor.go:119-124 (redirects not followed), 140-171 (studio and token lines), 207-233 (db), 235-262 (content), 264-320 (ingest), 322-347 (runtimes), 349-358 (panel), 415-445 (the manifest line, labelled manifest since 0.20.0; v0.20.2), 185-216 (the token line), 485-497 (discovery: off ok, none warn)'
  - weft/AGENTS.md:415-463 (block 7, setup B and the API over a terminal)
  - weft/CHANGELOG.md:2423-2446 (0.11.0, the weft command), 2489-2498 (weft doctor)
  - 'observed: the weft binary built from the v0.17.0 worktree; every --help and -h captured, and each command run against a scratch Studio'
  - 'weft/cmd/weft/main.go:411-415 (version, --version, -version: any argument, -h included, is usageError version takes no arguments, exit 2)'
  - 'weft/cmd/weft/main.go:885-906 (newServer: an empty --db is the default, only --db is parsed as a URL), 925-933 (dbFile: WEFT_DB read as a plain path), 947-950 (dbLabel: the default label)'
  - 'weft/cmd/weft/vacuum.go:117 (vacuum: <path> <before> → <after> bytes (WAL <before> → <after> bytes)), 118-120 (the WAL not checkpointed yet), 129-146 (openVacuumDB: WEFT_DB as a path, os.Stat; a missing file is no database at <path>, an existing one is vacuumed)'
  - 'observed: WEFT_DB=''clickhouse://u:fakepw@127.0.0.1:1/db'' weft studio from the v0.17.0 binary started, printed studio: token created in <cwd>/clickhouse:/u:fakepw@127.0.0.1:1/db.token and studio: db $WEFT_DB or ./.weft/weft.db (default), and /api/meta reported db.kind sqlite at that path; weft vacuum with it printed weft: no database at clickhouse://u:fakepw@127.0.0.1:1/db (nothing to vacuum), exit 1, in an empty cwd, and in the cwd that studio had run in vacuum: clickhouse://u:fakepw@127.0.0.1:1/db 217088 → 435480 bytes, exit 0 (the B4 fix check, factcheck/audit-b4-fixes.md F1)'
  - 'observed: weft version -h from the v0.20.2 binary (go build ./cmd/weft at 13af06ea) prints weft: version takes no arguments (got "-h") and exits 2; cmd/weft/main.go:290-299 (gotArgs: each argument quoted, never a Go slice), 411-414'
  - 'observed: weft v0.20.2 (go build ./cmd/weft at 13af06ea) in a scratch directory, 2026-10-27: weft studio --db sqlite://other.db (the banner), docs-site/examples/otherlang/stock-spans.json posted to /v1/traces, then weft doctor (exit 0)'
---

# weft CLI reference

The `weft` binary has nine commands. `weft studio` and `weft dev` serve Studio; `weft runs`, `weft open`, `weft export`, `weft doctor` and `weft mcp` are clients of a running Studio's JSON API; `weft vacuum` maintains the database; `weft version` prints the version. This page lists every flag with its environment variable, default and effect. The how-to pages are [Use the weft command](https://weftgo.dev/docs/observe/cli/), [Develop with weft dev](https://weftgo.dev/docs/observe/weft-dev/) and [Let Claude Code or Cursor read your runs](https://weftgo.dev/docs/observe/weft-mcp/).

```sh
weft --help
```

```text
weft — the weft framework's command line

Usage:
  weft studio  [--addr] [--db] [--token] [--rotate-token] [--manifest] [--open] [--no-playground] [--retain] [--pricing] [--log-level] [--log-format]
  weft dev     [studio's flags] [--no-watch] [--watch dir] [-- command args…]   (default: go run .)
  weft runs    [--url] [--token] [--agent] [--since] [--failed] [--status] [--limit] [--json]
  weft open    [id] [--url] [--token] [--open] [--with-token]   (a run, public, session or trace id; none: the Studio root)
  weft export  <run id> [--url] [--token] [--format json|jsonl|otlp] [--wefttest dir [--fixtures-only [--test name]] [--force]]
  weft doctor  [--url] [--token]
  weft mcp     [--url] [--token]   (a read-only stdio MCP server over the Studio API; weft mcp -h lists its tools)
  weft vacuum  [--db] [--retain]
  weft version

Environment (each mirrors a flag): WEFT_STUDIO_ADDR (--addr), WEFT_DB (--db),
WEFT_STUDIO_TOKEN (--token), WEFT_MANIFEST (--manifest), WEFT_STUDIO_URL (--url;
unset, the API commands read the discovery file a running weft studio wrote,
WEFT_DISCOVERY=off skips it, else http://127.0.0.1:7331),
WEFT_RETAIN (--retain; a Go duration of at least 1h, 0 = off), WEFT_PRICING (--pricing),
WEFT_LOG_LEVEL (--log-level: debug|info|warn|error), WEFT_LOG_FORMAT (--log-format: text|json).
Run "weft <command> -h" for a command's flags.
```

Flags use Go's `flag` package: `-flag` and `--flag` are the same, a value follows as `--flag value` or `--flag=value`, and a boolean turns off with `--open=false`. `weft <command> -h` prints that command's flags, each spelled `--name`, and exits 0. The exception is `weft version`, which has no flags: `weft version -h` prints `weft: version takes no arguments (got "-h")` and exits 2 (`--help` likewise, naming `--help`). Every usage error names its arguments in words, never a Go slice: `weft: runs takes no arguments (got "extra")`, `weft: export needs exactly one run id (got none)`. `weft open` and `weft export` accept their run id anywhere among the flags. `weft runs`, `weft mcp`, `weft studio`, `weft doctor` and `weft vacuum` take no positional argument. `weft dev` takes the app's command after its own flags; put `--` first when that command has flags of its own.

## Commands

| Command | What it does | Talks to |
|---|---|---|
| [`weft studio`](#weft-studio) | Serves Studio (setup B): the UI, OTLP ingest and the playground, over SQLite or ClickHouse | — (it is the server) |
| [`weft dev`](#weft-dev) | `weft studio` in-process plus your app, restarted on a `.go` save | — (it is the server) |
| [`weft runs`](#weft-runs) | Lists the newest top-level runs, one row each | `GET /api/runs` |
| [`weft open`](#weft-open) | Prints the page of a run, public id, session or trace, or the Studio root; `--with-token` signs it in | `GET /api/runs/{id}`, `/api/sessions/{id}`, `/api/traces/{id}` |
| [`weft export`](#weft-export) | Writes a run's export to stdout, or its replay test to a package directory | `GET /api/runs/{id}/export` |
| [`weft doctor`](#weft-doctor) | Checks a running Studio, one line per check | `GET /api/meta` |
| [`weft mcp`](#weft-mcp) | A read-only MCP server over stdio for a coding agent | 22 read tools |
| [`weft vacuum`](#weft-vacuum) | One retention sweep, then `VACUUM` or `OPTIMIZE TABLE … FINAL` | the database file or DSN |
| [`weft version`](#weft-version) | Prints the weft version the binary was built from | — |
| [`weft help`](#weft-help) | Prints the usage text | — |

## Common flags

Each connection flag mirrors one environment variable; the flag wins when both are set. The flags without a mirror (`--open`, `--no-playground`, `--rotate-token`, `--watch`, `--no-watch`, `--read-only` and the per-command flags) shape one run of the command, not a connection.

| Flag | Environment | Default | Commands |
|---|---|---|---|
| `--addr` | `WEFT_STUDIO_ADDR` | `127.0.0.1:7331`, unpinned: a busy port moves to the next free one in 7331–7340. Either form set pins the address. A Studio already holding the same SQLite file refuses the start ([One Studio per database](#one-studio-per-database)) | `studio`, `dev` |
| `--db` | `WEFT_DB`, a bare SQLite path, never a URL | `./.weft/weft.db` | `studio`, `dev`, `vacuum` |
| `--log-format` | `WEFT_LOG_FORMAT` | `text` when a level is set; with neither set, Go's default log line | `studio`, `dev` |
| `--log-level` | `WEFT_LOG_LEVEL` | `info` | `studio`, `dev` |
| `--manifest` | `WEFT_MANIFEST` | the nearest `weft.json` from the working directory upward | `studio`, `dev` |
| `--pricing` | `WEFT_PRICING` | the table shipped with this weft (`studio/pricing.json`) | `studio`, `dev` |
| `--retain` | `WEFT_RETAIN` | off: every run is kept | `studio`, `dev`, `vacuum` |
| `--token` | `WEFT_STUDIO_TOKEN` | `studio`, `dev`: the database's stable token in `<db>.token`, never printed; a generated one, printed, for a database with no file. The clients: the discovery file's, when it names the resolved Studio | every command but `vacuum` and `version` |
| `--url` | `WEFT_STUDIO_URL` | the discovery file's Studio (`WEFT_DISCOVERY=off` skips it), else `http://127.0.0.1:7331` | `runs`, `open`, `export`, `doctor`, `mcp` |

**One resolver for the clients.** `weft runs`, `open`, `export`, `doctor` and `mcp` find the Studio in one order: `--url`, else `WEFT_STUDIO_URL`, else the discovery file a running `weft studio` or `weft dev` wrote (the trust rules `otel.Install` uses: loopback, fresh, 0600 and yours), else `http://127.0.0.1:7331`. The token is `--token`, else `WEFT_STUDIO_TOKEN`, else the discovery file's when that file names the resolved Studio, so a token goes only to the Studio it belongs to. When you named no Studio, one line on stderr says which was taken:

```text
weft: Studio http://127.0.0.1:7331 (discovery file ~/.cache/…/weft/studio.json)
```

Before 0.20.0 the clients other than `weft mcp` read `--url`, else `WEFT_STUDIO_URL`, else 7331, and never the file.

[Environment variables](https://weftgo.dev/docs/reference/env/#the-weft-command) has the same variables with the code that reads each one.

## Exit codes

| Code | When |
|---|---|
| 0 | Success, including `-h`, `--help` and `weft help`, `weft dev` reusing a running Studio, and `weft dev` stopped by Ctrl-C, SIGTERM or SIGHUP |
| 1 | A failure, printed as one `weft: …` line on stderr, `weft studio` on a database another Studio holds included. `weft doctor` prints its own lines instead and exits 1 when a check reads `FAIL` |
| 2 | A usage error: an unknown command or flag, a bad flag value (`--status bogus`, `--retain 30m`, `--log-level loud`), an argument a command does not take, `weft version -h` included |
| the app's | `weft dev --no-watch`: the app's exit code; 127 when the command cannot start, 1 when a signal ended it |

## weft studio

Serves setup B: [`studio.New`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#New) with the UI at `/`, OTLP ingest on `/v1/traces` and `/v1/logs`, the playground, and a token wall. [Run Studio](https://weftgo.dev/docs/observe/studio/setup/#run-the-weft-studio-binary) covers the three setups.

```sh
weft studio --db sqlite://other.db --open=false
```

```text
studio: http://127.0.0.1:7331/
studio: token created in ~/work/other.db.token (stable for this database; --rotate-token renews it)
studio: db other.db
studio: no weft.json from ~/work upward; no manifest (--manifest names one)
studio: apps find this Studio through ~/xdg/weft/studio.json (WEFT_STUDIO_URL overrides it, WEFT_DISCOVERY=off ignores it)
studio: sign in with `weft open --with-token` (prints this Studio's link, the token in its fragment)
```

The discovery file went to `$XDG_RUNTIME_DIR/weft/` because the directory had no `.weft`; after a default start it goes to `./.weft/` ([the location order](https://weftgo.dev/docs/observe/weft-dev/#the-discovery-file)). The last line is printed when Studio did not open the browser. In the outputs on this page, `~/work` and `~/xdg` stand for the scratch directories the commands ran in.

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--addr address` | `WEFT_STUDIO_ADDR` | `127.0.0.1:7331`, unpinned | The listen address. Set, it pins: a busy address is exit 1, with no probe and no other port. Unset, the [port policy](https://weftgo.dev/docs/observe/weft-dev/#the-port-policy) applies. Either way the database lock is taken first ([One Studio per database](#one-studio-per-database)) |
| `--db url` | `WEFT_DB`, a bare SQLite path | `./.weft/weft.db` | `sqlite://path` or `clickhouse://user:pass@host:9000/db`. `sqlite://:memory:` has no file. Any other form is exit 1. The banner masks a DSN's password as `***`. Without `--db`, `WEFT_DB` is opened as a SQLite file whatever it holds, and the banner reads `studio: db $WEFT_DB or ./.weft/weft.db (default)` |
| `--log-format format` | `WEFT_LOG_FORMAT` | `text` when a level is set, else Go's log line | `text` or `json`, the server log on stderr. Another value is exit 2 |
| `--log-level level` | `WEFT_LOG_LEVEL` | `info` | `debug`, `info`, `warn` (or `warning`) or `error`, in any case. Another value is exit 2 |
| `--manifest path` | `WEFT_MANIFEST` | the nearest `weft.json` upward | The manifest served at `/api/manifest`, read once at start. A file that cannot be read or does not decode is exit 1 ([start lines](#start-lines-and-errors)) |
| `--no-playground` | — | playground on | Turns the playground and its runtime link off |
| `--open` | — | on when stdout is a terminal | Opens the browser on the UI with the token in the URL fragment; `--open=false` turns it off. The opener is `open` on macOS, `rundll32 url.dll,FileProtocolHandler` on Windows and `xdg-open` elsewhere; when it cannot start, the start goes on ([start lines](#start-lines-and-errors)) |
| `--pricing path` | `WEFT_PRICING` | the shipped table | A pricing table that replaces the shipped one whole. A file that does not load is exit 1, naming the path and the field |
| `--retain duration` | `WEFT_RETAIN` | off | `studio.Retain`: a Go duration (`720h`), at least `1h`; `0` is off. Under `1h`, negative or unparsable is exit 2 |
| `--rotate-token` | — | off | Writes a new `<db>.token` before serving. Panel tokens signed with the old one stop verifying. On a reuse it is not applied, and a line says so |
| `--token string` | `WEFT_STUDIO_TOKEN` | `<db>.token`, created on the first start | The API token. Set, it overrides the file and leaves it alone |

The banner prints, in order: the port note (when the wanted port was busy), the UI link (bare unless the token was generated for this process), where the token came from, the database, then the manifest, retention and pricing notes, and the discovery file's path. A database with no file prints its generated token instead of a token line:

```sh
weft studio --db sqlite://:memory: --addr 127.0.0.1:7466 --no-playground --retain 720h
```

```text
studio: http://127.0.0.1:7466/#token=<generated>
studio: dev token <generated> (WEFT_STUDIO_TOKEN fixes it)
studio: db :memory:
studio: no weft.json from ~/work upward; no manifest (--manifest names one)
studio: retention 720h0m0s: runs that are not running and were last seen longer ago are deleted (studio's tables only)
studio: apps find this Studio through ~/work/.weft/studio.json (WEFT_STUDIO_URL overrides it, WEFT_DISCOVERY=off ignores it)
```

<span id="start-lines-and-errors"></span>

The other lines a start can print:

| Line | When |
|---|---|
| `studio: token from --token`, `studio: token from WEFT_STUDIO_TOKEN` | A fixed token |
| `studio: token from <path> (stable for this database; --rotate-token renews it)` | A later start on the same file |
| `studio: manifest <path> (--manifest)`, with `WEFT_MANIFEST` or `found upward` in the parentheses | A manifest was loaded; `<path>` is the resolved path |
| `weft: --manifest: <error>`, `weft: WEFT_MANIFEST: <error>`, `weft: manifest <path>: <error>` (found upward) | The manifest file cannot be read: exit 1 |
| `weft: manifest <path>: does not parse: <error>` | The file does not decode as a JSON object, or its `weft` is not a number, or its `agents` is not an array: exit 1. Missing keys are not checked: `{}` starts and is served |
| `weft: could not open a browser (<error>); open the link yourself` | `--open` and no opener could start (a container, a headless box); never an exit |
| `studio: no discovery file (<error>); apps need WEFT_STUDIO_URL=<url>` | The discovery file could not be written; Studio serves anyway |
| `` weft: studio already running at http://127.0.0.1:7331 (pid 1683241) on ~/work/other.db: one Studio per database file — sign in to it with `weft open --with-token`, or stop it first `` | Another Studio holds the database file's lock: exit 1, the database is not opened |
| `` studio: sign in with `weft open --with-token` (prints this Studio's link, the token in its fragment) `` | Studio did not open the browser |
| `studio: shutting down (interrupt)` | SIGINT, SIGTERM or (on unix) SIGHUP: a five-second grace window for open requests, then the discovery file is removed |

### One Studio per database

`weft studio` and `weft dev` take an exclusive lock on `<db>.lock` beside a SQLite database (`flock`, `LockFileEx` on Windows). The lock is held while they serve and released by the kernel when the process ends, a crash included. It is taken before the port policy, so a second `weft studio` on the same file is refused whatever its port, its directory or its timing, with exit 1 and the line above. Before 0.20.0 it said `…, reusing` and exited 0, and only on the wanted port. `weft dev` reuses the holder instead of refusing. It names the holder only from this user's 0600 lock file with a loopback URL and a live pid.

The lock file holds the holder's URL and pid while it serves and stays on disk after the process exits. Leave it there: removing it races the next start. A symlink, a directory or any other non-regular file at that path is refused at start, and on unix so is a hard link (a file with more than one link). The refusal reads `lock …/weft.db.lock: dblock: the lock file is not a regular file`; weft never follows, truncates or chmods such a file, so remove it to start. The lock stands for the file a symlinked database path names; two hard links or two case-insensitive spellings of one database file are not detected. A ClickHouse database takes no lock.

The HTTP server bounds a request's headers at 10 s and an idle keep-alive connection at 2 minutes. Writes and body reads have no server timeout: `/api/live` and the runtime link's command stream stay open, and a 16 MiB ingest upload may be slow.

## weft dev

`weft studio` in-process, with the same flags and port policy, plus the app: the command after its flags (after `--` when the command has flags of its own), by default `go run .`. [Develop with weft dev](https://weftgo.dev/docs/observe/weft-dev/) covers the loop.

```sh
weft dev -- go run ./cmd/app
```

```text
answered: Order 42 has shipped.
failed: weft: run failed at step 1: weft: run exceeded the maximum number of steps
studio http://127.0.0.1:7331/ · app pid 2825860 · runtime rt_921efe69d315c004 registered
studio: shutting down (interrupt)
```

The first two lines are the app's own output; the third is `weft dev`'s start line; the last follows Ctrl-C.

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--addr`, `--db`, `--log-format`, `--log-level`, `--manifest`, `--open`, `--pricing`, `--retain`, `--rotate-token` | as on `weft studio` | as on `weft studio` | As on `weft studio`. The manifest, retention and pricing notes are not printed: the start line replaces the banner |
| `--no-playground` | — | playground on | Turns the playground off; the start line then reads `playground off (--no-playground): no runtime link` |
| `--no-watch` | — | watching on | Does not restart the app on a `.go` change; `weft dev` exits with the app's exit code |
| `--token string` | `WEFT_STUDIO_TOKEN` | `<db>.token` | The API token; the app receives it as `WEFT_STUDIO_TOKEN` |
| `--watch dir` | — | the working directory | A directory to watch for `.go` changes, repeatable; given, the list replaces the default. A path that is not a directory is exit 2 (not checked under `--no-watch`) |

The app's environment gains `WEFT_ENV=dev` (unless the shell set `WEFT_ENV` to something), `WEFT_STUDIO_URL`, `WEFT_STUDIO_TOKEN` and `WEFT_DB` (the absolute SQLite path); those three override the shell's. For a database with no file or ClickHouse `weft dev` does not set `WEFT_DB`, so a `WEFT_DB` from the shell passes through ([the table](https://weftgo.dev/docs/observe/weft-dev/#the-environment-weft-dev-sets)).

## weft runs

Prints the newest top-level runs, one row each, paging `GET /api/runs` 100 rows at a time:

```sh
weft runs
```

```text
weft: Studio http://127.0.0.1:7331 (discovery file ~/xdg/weft/studio.json)
ID                                                      AGENT    STATUS     STARTED                    STEPS  DUR   COST     PROMPT  STOPPED BY  ERROR
otel-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7  support  succeeded  2026-10-01 12:00:00 +0200  2      3.2s  $0.0029  -       -           -
weft: weft open <id> shows one in Studio; weft export <id> --format jsonl writes it out
```

That run is the stock-span run from [Inspect agents written in other languages](https://weftgo.dev/docs/observe/other-languages/#check-it-with-an-otlpjson-body), which records no prompt or stop. `STARTED` is local time with its zone. `DUR` is the run's duration, `COST` its whole bill (own plus delegated), `PUBLIC ID` a column of its own when a row has one, and `ERROR` a failed run's kind and why, cut to 60 characters. The table is stdout; the Studio line and the hint naming the next step go to stderr. `PROMPT` is the first line of the run's prompt preview, cut to 40 characters with `…`, or `-` for a content-off run. `STOPPED BY` is what ended the run, with a cancelled run's cause in parentheses, or `-` when none was recorded. Every cell prints control characters as spaces.

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--agent string` | — | every agent | Only this agent's runs (the API's `agent=`) |
| `--failed` | — | off | Only failed runs (`status=failed`). With `--status` other than `failed` or `cancelled` it is exit 2 |
| `--json` | — | off | Prints the rows as Studio serves them, a JSON array (`prompt_preview`, `stopped_by` and `cancel_cause` included when set) |
| `--limit int` | — | `50` | Prints at most this many runs; `0` prints every match. When it hid runs, stderr says `weft: showing the newest N; --limit 0 lists all`. Negative is exit 2 |
| `--since duration` | — | no bound | A duration back from now (`2h`, `30m`) or an RFC 3339 time; paging stops at the first older run. Anything else is exit 2 |
| `--status status` | — | every status | `running`, `succeeded`, `failed`, `interrupted`, `parked` or `cancelled`; another word is exit 2 |
| `--token string` | `WEFT_STUDIO_TOKEN` | none | The bearer token |
| `--url string` | `WEFT_STUDIO_URL` | the [resolver](#common-flags) | The Studio to talk to |

The columns changed in 0.20.0; scripts read `--json`, which did not. No match prints `weft: no runs match` on stderr and exits 0; with `--json` it prints `[]` on stdout and nothing on stderr.

## weft open

Takes a run id, a public id, a session id or a trace id, tried in that order, checks it exists and prints its page, bare. With no id it prints the Studio root:

```sh
weft open otel-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7
weft open --with-token
```

```text
http://127.0.0.1:7331/runs/otel-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7
http://127.0.0.1:7331/#token=<token>
```

`weft open --with-token` with no id is a terminal's signed-in link: the token in the fragment, never sent to a server. (The Studio line on stderr is left out above.)

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--open` | — | off | Also opens the browser on the link, the token in its fragment, with `weft studio`'s opener; a failure is the line `weft: could not open a browser (<error>); open the link yourself`, never an exit |
| `--token string` | `WEFT_STUDIO_TOKEN` | none | The bearer token |
| `--url string` | `WEFT_STUDIO_URL` | the [resolver](#common-flags) | The Studio to talk to |
| `--with-token` | — | off | Prints the link with `#token=` and the resolved token, signed in. The token may be the panel tokens' signing key: keep it out of logs |

An id that is none of the four is exit 1, naming what was tried. A subagent's id, which carries slashes, is escaped in the link.

## weft export

Writes `GET /api/runs/{id}/export` to stdout, or with `--wefttest <dir>` writes Studio's save-as-test tree into the package directory `<dir>`: `<agent>_replay_test.go` beside `testdata/TestReplay_<run>/*.json`, a test that passes under `go test` there ([Turn a Studio run into a test](https://weftgo.dev/docs/testing/studio-runs-as-tests/#export-fixtures-with-the-cli)). `--fixtures-only` writes the fixtures alone, where [`wefttest.Replay`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/wefttest#Replay) reads them:

```sh
weft export d286bfec55eff7c475a895aa2fae1987 --wefttest ./testdata --fixtures-only --test TestSupportReplay
```

```text
weft: wrote 2 fixtures to testdata/TestSupportReplay; a test named TestSupportReplay replays them with wefttest.Replay(t, "./testdata")
```

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--fixtures-only` | — | off | With `--wefttest`: the fixtures alone under `<dir>/<test>` (a suite's `testdata`), no test file. Before 0.19.0 this was what `--wefttest` did |
| `--force` | — | off | With `--wefttest`: writes over a test file or fixtures already there, the old `*.json` fixtures removed first (replaced, never merged). Without it a target already holding them is exit 1. A symlinked `testdata` or `testdata/<test>` is refused before any write |
| `--format string` | — | `json` | The stdout export: `json`, `jsonl` or `otlp`. `wefttest` and any other value are exit 2; with `--wefttest` it is exit 2 |
| `--test name` | — | the run id | With `--fixtures-only`: the test that replays the fixtures, so the directory `<dir>/<name>`. A subtest `TestX/case` is a nested directory; an absolute name or one that leaves `<dir>` is exit 2. Without `--fixtures-only` it is exit 2: the tree names its test `TestReplay_<run>` |
| `--token string` | `WEFT_STUDIO_TOKEN` | the [resolver](#common-flags) | The bearer token |
| `--url string` | `WEFT_STUDIO_URL` | the [resolver](#common-flags) | The Studio to talk to |
| `--wefttest dir` | — | off | Writes the run's save-as-test tree (the replay test and its `testdata/`) into the package directory `dir` instead of stdout |

`--test`, `--fixtures-only` or `--force` without `--wefttest` is exit 2. Under `--wefttest` the zip's names and declared sizes are checked before the first write, and each refusal is exit 1. The old `*.json` fixtures in the target are then removed, and a size check while reading can still fail partway, after they were removed and some files were written:

| Message | When |
|---|---|
| `the wefttest export is not a zip: …` | The answer does not read as a zip |
| `the wefttest export holds "<name>": want fixture files under one testdata/<test>/` | A malformed `testdata/` entry, or a second test directory |
| `the wefttest export holds "<name>": want fixture files under testdata/<test>/` | A path outside `testdata/` that is not a plain file name (a subdirectory, or a name with `\` or `:`) |
| `the wefttest export mixes flat fixtures ("<name>") with testdata/<test>/` | Top-level fixtures beside a `testdata/<test>/` layout |
| `the wefttest export holds "<name>": want fixture files` | An entry that is not a regular file |
| `the wefttest export holds no fixtures` | Nothing but the `_test.go` skeleton |
| `the wefttest export unzips to more than 536870912 bytes` | The entries together pass 512 MiB, by their headers or as read |

The command has no flag for a run's subagent tree: Studio's `&tree=1` is a browser download ([Export a run](https://weftgo.dev/docs/observe/studio/export/#export-a-run-with-its-subagents)).

## weft doctor

Asks a running Studio's `GET /api/meta` what it is, within 5 s, and prints one line per check: `ok`, `warn` or `FAIL`, a label and the finding. A `FAIL` line exits 1; warnings do not.

```sh
weft doctor
```

```text
ok   studio    reachable at http://127.0.0.1:7331 (weft v0.20.2, studio v0.20.2)
ok   token     accepted
ok   discovery ~/xdg/weft/studio.json -> http://127.0.0.1:7331 (this Studio)
ok   db        sqlite ~/work/other.db (643.8 KiB)
warn content   studio stores content as received; latest run otel-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7: unmarked — the latest run carries no content mark: no events stored, a weft older than the mark, or a non-weft exporter
ok   data      newest run 629h45m0s ago (service py-support) carries no weft version: a non-weft exporter
ok   otlp      open: OTLP at http://127.0.0.1:7331/v1/traces and /v1/logs takes a loopback app's spans with no ingest token
ok   ingest    1 OTLP batches accepted, 0 refused; no app reported lost records (weft.records.dropped on its heartbeats and run brackets)
warn runtimes  none connected
               - WEFT_ENV is unset in this shell: the app opens the runtime link only with WEFT_ENV=dev (or runtime.Enabled(true))
               - WEFT_STUDIO_URL is unset in this shell: the app dials the Studio a running `weft studio` names in its discovery file, else its otel Studio destination; set WEFT_STUDIO_URL=http://127.0.0.1:7331 to pin this one (or runtime.Studio(url, token))
ok   panel     /panel.js matches studio v0.20.2
ok   manifest  none: no weft.json configured (studio.Manifest, or --manifest / WEFT_MANIFEST) and no runtime registered one, nothing to compare
```

That is weft v0.20.2 against the stock-span run above, after the Studio line on stderr.

| Line | Reads | `warn` or `FAIL` when |
|---|---|---|
| `studio` | the response itself, `weft_version`, `studio_version` | Not reachable: that line, a `start one with weft studio` hint, and exit 1; no other check runs |
| `token` | the status, `auth_required` | `FAIL`: a 401 (no token, or the wrong one) or any other non-200 answer |
| `db` | `db.kind`, `db.path`, `db.size` | never |
| `content` | `content` | `warn`: the latest run's content is not `full`, or it could not be read |
| `ingest` | `ingest` | `warn`: a refused OTLP batch in the last hour, or an app that reported dropped records |
| `runtimes` | `runtimes`, `capabilities`, this shell's `WEFT_ENV` and `WEFT_STUDIO_URL` | `warn`: none connected, with hints from the two variables |
| `panel` | `panel_version`, `studio_version` | `FAIL`: `/panel.js` has no version stamp, or not the server's |
| `manifest` | `has_manifest`, `manifest_check` | `warn`: the manifest and the latest runs disagree, or the check failed. Its finding leads with its source: `weft.json: 1 agent, 1 checked against their latest runs: current`, or `runtime registrations (no weft.json): …`. Before 0.20.0 the label was `weft.json` |
| `discovery` | `discovery_file`, this shell's discovery file | `warn`: another Studio's file, two Studios on one database, or no discovery file. `WEFT_DISCOVERY=off` in the shell is `ok`, naming the `WEFT_STUDIO_URL` an app then needs |
| `data` | `content.latest` (`started`, `weft_version`, `service`) | the newest run's age, weft version and service |
| `otlp` | the ingest route | `open`, `walled` or `off` |

The finding each line can print, beyond the sample above (`- ` lines are continuations):

| Line | Finding |
|---|---|
| `studio` | `studio not reachable at <url>: <error>`, then ``- start one with `weft studio`, or point --url (WEFT_STUDIO_URL) at the one you run``; `… api/meta is not JSON: …` |
| `token` | a 401 names `--token "$(cat <db>.token)"` and `weft open --with-token`. A 401 to the token sent: `FAIL refused: it is not this studio's token (WEFT_STUDIO_TOKEN / --token)`. Else `FAIL api/meta answered <code>: <message>`, or `… a redirect to <location>, not followed: point --url at the Studio itself`; `ok not required (no Token configured)` |
| `db` | `<kind> <path> (<size>)`; `<kind> <path>`; `<kind> (no file path served to this caller)`; `<kind> (this studio predates db.path)` |
| `content` | `…; no run stored yet`; `warn …; the latest run could not be read: <error>`; a non-`full` latest run adds `- fix: <fix>` when Studio gives one |
| `ingest` | `<n> service(s) reported records lost on the way here`, with one `- <service>: N records dropped by its destination (last heard <time>)` each. Then `- fix: queue full or exports failing — the app's WARN names which ("weft/otel: destination queue full": raise it with otel.QueueSize(n), or use otel.Blocking() under WEFT_ENV=dev (or otel.DevMode()); "weft/otel: destination dropped records": its err is the export's failure)`. A refusal adds `- last refused at <time>: <error>` and a fix naming Studio's WARN and the ingest token. `ok not served (no ingest.dropped): …` for a Studio older than ingest health or a panel token |
| `runtimes` | `ok N connected`; under `warn none connected`, `- studio has no runtime link: the playground is off (studio.Playground(true))` when the capability is missing, and `WEFT_STUDIO_URL=<x> in this shell, not <url>: the app dials the former` when the variable names another Studio |
| `panel` | `FAIL /panel.js carries no version stamp: this studio's build lacks the panel bundle`; `FAIL /panel.js is <v>, studio is <v>: the embedded bundle is stale (make studio-build)` |
| `manifest` | Each finding leads with its source. `none: no weft.json configured (studio.Manifest, or --manifest / WEFT_MANIFEST) and no runtime registered one, nothing to compare`. `present (weft.json or a runtime's registration); not checked for this caller`. `warn the check failed: <error>`. With a file: `weft.json: N agents; none has a recorded run to compare yet`, `weft.json: N agents, M checked against their latest runs: current`, or `warn weft.json: stale for <agents>: weft.json and the latest runs disagree (…): regenerate weft.json, or redeploy the app if weft.json is newer`. With no file, `runtime registrations (no weft.json): N agents, M checked against their latest runs`, or `warn runtime registrations (no weft.json): … (runs from another build): redeploy the app, or ignore it if those runs are old` with a `- stale: <agents>` line. Before 0.20.0 this line was labelled `weft.json` |

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--token string` | `WEFT_STUDIO_TOKEN` | the [resolver](#common-flags) | The bearer token |
| `--url string` | `WEFT_STUDIO_URL` | the [resolver](#common-flags) | The Studio to check |

A capability that is off names its cause (`--no-playground`: "drop the flag"), and a stale panel or manifest line names the reinstall and the latest run's manifest hash.

A redirect is reported, never followed, by every client command, not only `weft doctor` ([Notes](#notes)).

## weft mcp

A stdio MCP server over a running Studio's read API; stdout is the protocol and every line of its own goes to stderr. It serves until stdin closes, then exits 0. [Let Claude Code or Cursor read your runs](https://weftgo.dev/docs/observe/weft-mcp/) lists the 22 tools.

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--read-only` | — | `true` | The only mode: every tool is a GET. `--read-only=false` is exit 2 |
| `--token string` | `WEFT_STUDIO_TOKEN` | the discovery file's token, when that file names the resolved Studio | The bearer token, sent in the `Authorization` header only and never printed |
| `--url string` | `WEFT_STUDIO_URL` | the discovery file's Studio, else `http://127.0.0.1:7331` | The Studio to read. Without `--url`, each look after a failure re-reads the variable and the file |

A Studio that does not answer at start is one WARN on stderr, and the server serves anyway. A Studio that answers and refuses (a 401 with no token) is exit 1. Every tool takes `max_bytes`: default 65536, at most 4194304.

## weft vacuum

One retention sweep when a retention is given, then the backend's vacuum: `VACUUM` on SQLite, `OPTIMIZE TABLE … FINAL` on the tables deletions mutate on ClickHouse. It touches Studio's tables only.

```sh
weft vacuum --retain 1h
```

```text
vacuum: swept 1 runs last seen before 2026-10-27T11:49:08Z (retention 1h0m0s)
vacuum: other.db 270336 → 270336 bytes (WAL 57712 → 0 bytes)
```

The main file and the WAL are printed apart. On SQLite the vacuum checkpoints the WAL after `VACUUM` (PASSIVE, then TRUNCATE, each under its own 250 ms busy timeout), so the file's size after a vacuum is its size; a WAL a live reader or writer holds is said. On ClickHouse the second line is `vacuum: <db> optimized`.

| Flag | Environment | Default | Effect |
|---|---|---|---|
| `--db url` | `WEFT_DB`, a bare SQLite path | `./.weft/weft.db` | `sqlite://path` or `clickhouse://user:pass@host:9000/db`. A SQLite file that does not exist is exit 1 (`weft: no database at missing.db (nothing to vacuum)`), never created. A URL in `WEFT_DB` is taken as a file name: exit 1 when no such file exists, else that file is vacuumed ([Notes](#notes)) |
| `--retain duration` | `WEFT_RETAIN` | none: no sweep | Sweeps the runs not running and last seen longer ago first. Under `1h` is exit 2 |

[Keep and delete recorded runs](https://weftgo.dev/docs/production/retention/#sweep-and-vacuum-once) covers when to run it.

## weft version

Prints the weft version the binary was built from (its module tag). `weft --version` and `weft -version` are the same; any argument after it, `-h` and `--help` included, is exit 2 (`weft: version takes no arguments (got "-h")`).

```sh
weft version
```

```text
v0.20.2
```

## weft help

`weft help`, `weft -h`, `weft --help` and `weft -help` print the usage text above on stdout and exit 0. `weft` with no command prints it on stderr with `weft: a command is required`, and an unknown command with `weft: unknown command "<name>"`; both exit 2.

## Notes

- **Pass `--url` or set `WEFT_STUDIO_URL` when the discovery file cannot find Studio.** Since 0.20.0 every client, `weft runs`, `open`, `export`, `doctor` and `mcp`, finds a running `weft studio` or `weft dev` through its discovery file before trying 7331, so a Studio the port policy moved to 7332 is found. A Studio elsewhere, another user's, or a shell with `WEFT_DISCOVERY=off` is not. (Source: `cmd/weft/resolve.go:15-22, 45-80`)
- **Point `--url` at the Studio itself, not at a proxy that redirects.** `weft runs`, `open`, `export`, `doctor` and `mcp` never follow a redirect: Go would keep the bearer token on a hop to another port or from https to http. The answer is exit 1, `weft: GET <path>: <code>, a redirect to <location>, not followed: point --url at the Studio itself`. (Source: `cmd/weft/api.go:37-48, 94-100`; `internal/doctor/doctor.go:167-172, 199-205`)
- **Give the clients the token; they have no default.** A `weft studio` on a file always walls its API with `<db>.token`, and a client without one gets `401 the API requires a token`. (Source: `cmd/weft/main.go:874-875`; `cmd/weft/api.go:122-124`)
- **Give ClickHouse to `--db`, never to `WEFT_DB`.** `WEFT_DB` is a SQLite file path, so `WEFT_DB='clickhouse://u:p@host:9000/db' weft studio` starts with no error and serves a new, empty SQLite file at `./clickhouse:/u:p@host:9000/db`, the password in its path and in the banner's `token created in …` line. `--db` takes the URL and masks the password. (Source: `cmd/weft/main.go:886-906, 925-933`; observed with the v0.20.2 binary)
- **`weft vacuum` reads a URL in `WEFT_DB` as a file name too.** Where no such file exists it exits 1 with `weft: no database at clickhouse://u:p@host:9000/db (nothing to vacuum)`. Where `weft studio` already ran with the same variable, it vacuums that stray SQLite file, prints `vacuum: clickhouse://u:p@host:9000/db <before> → <after> bytes (WAL <before> → <after> bytes)`, password included, and exits 0. (Source: `cmd/weft/vacuum.go:129-146, 117`)
- **`--addr` turns the port policy off.** A pinned busy address is exit 1, never a reuse. Leave it unset to reuse a running Studio on the same database. (Source: `internal/listen/listen.go:154-160`)
- **`--status` takes six words; `--failed` is one of them.** `--failed --status succeeded` is exit 2; `--failed --status cancelled` lists cancelled runs. (Source: `cmd/weft/api.go:334-347`)
- **`weft vacuum` needs the file to itself.** SQLite's `VACUUM` and another process's writer wait on each other up to the busy timeout; run it while Studio is stopped or idle. (Source: `cmd/weft/main.go:217-222`)

## See also

- [Use the weft command](https://weftgo.dev/docs/observe/cli/)
- [Develop with weft dev](https://weftgo.dev/docs/observe/weft-dev/)
- [Let Claude Code or Cursor read your runs (weft mcp)](https://weftgo.dev/docs/observe/weft-mcp/)
- [Run Studio](https://weftgo.dev/docs/observe/studio/setup/)
- [Environment variables](https://weftgo.dev/docs/reference/env/)

Symbols used: [`wefttest.Replay`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/wefttest#Replay) · [`studio.New`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#New) · [`studio.Retain`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#Retain)
