---
title: Use the weft command
description: Run Studio with weft studio, then list, open and export its runs and check its health from a terminal with weft runs, weft open, weft export and weft doctor.
url: https://weftgo.dev/docs/observe/cli/
type: how-to
sources:
  - 'observed: the release candidate''s weft binary (go build ./cmd/weft at ../weft-rc020, version still v0.19.0) in a scratch directory: weft studio''s banner, a second start on the same file, weft runs (the stock-span run of docs-site/examples/otherlang/stock-spans.json), --status bogus, --limit 1, WEFT_DISCOVERY=off with no token, weft open, weft doctor'
  - weft/cmd/weft/resolve.go:1-120 (the one resolver, the token rule, the stderr line)
  - 'weft/CHANGELOG.md:43 (0.20.0: the resolver, open''s ids, runs'' columns, doctor''s lines, the banner''s sign-in line), 57 (usage errors, vacuum), 83-85, 93 (breaking: the lock; the lock file left on exit, non-regular files refused — v0.20.2; the --url default, the runs columns, the manifest label), 159 (0.19.0 breaking: export --wefttest writes the tree)'
  - weft/cmd/weft/main.go:1-29 (every subcommand is a convenience over studio.New or one API route; flags mirror variables), 104-161 (runs, open, export, doctor), 233-237 (version, exit codes), 569-577 (--url, else WEFT_STUDIO_URL, else http://127.0.0.1:7331; --token, else WEFT_STUDIO_TOKEN), 823-862 (the banner's token lines), 874-875 (newServer always passes studio.Token)
  - 'weft/cmd/weft/api.go:26-28 (each request is one documented route), 37-50 (2 min timeout; redirects never followed), 85 (the not-reachable error), 122-124 (the 401 hint), 163-451 (weft runs: columns, paging, --since, --limit, --json), 475-512 (weft open), 568-637 (weft export)'
  - 'weft/cmd/weft/token.go:17-30 (the dev token is <db>.token, never printed), 52 (printable: only a generated token)'
  - 'weft/internal/doctor/doctor.go:1-12 (one line per check from /api/meta), 31 (5 s), 43-55 (Lines), 153-230 (Run: FAIL exits 1, warnings do not)'
  - weft/README.md:379-410 (The weft command), 412-426 (the dev token)
  - 'weft/cmd/weft/main.go:522-550 (manifestOptions: the manifest line, does not parse)'
  - 'weft/cmd/weft/main.go:886-906 (newServer: only --db is a URL), 925-933 (dbFile: WEFT_DB as a plain path)'
  - 'observed: WEFT_DB=''clickhouse://u:fakepw@127.0.0.1:1/db'' weft studio (v0.17.0) started and served an empty SQLite file at ./clickhouse:/u:fakepw@127.0.0.1:1/db, its token file beside it'
  - 'weft/cmd/weft/browser.go:39-45 (openBrowser: could not open a browser, never an exit)'
  - 'weft/cmd/weft/discovery.go:48-60 (announce: no discovery file)'
  - weft/studio/README.md:121-138 (the API over a terminal)
  - 'weft/AGENTS.md:415-446 (block 7, setup B: flags, the dev token, the API over a terminal, weft version)'
  - 'weft/CHANGELOG.md:2423-2446 (0.11.0: the weft command)'
  - weft/obsdb/db.go (StatusWords, the six status words)
  - 'observed: weft v0.17.0 built from the worktree; weft studio and weft dev on scratch databases (XDG_RUNTIME_DIR and XDG_CACHE_HOME in a scratch directory), seeded by docs-site/examples/cli; every command on this page run against them'
  - '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/cmd/weft/api.go:571-576 (export''s flags: --test with --fixtures-only, the run id by default), 588-591, 609-612 (--test without --fixtures-only is a usage error)'
---

# Use the weft command

The `weft` binary serves Studio and talks to it from a terminal. [`weft studio`](https://weftgo.dev/docs/reference/cli/#weft-studio) serves the UI, OTLP ingest and the playground over one database; `weft runs`, `weft open`, `weft export` and `weft doctor` each call one route of that Studio's JSON API, so a script or CI job reads the same runs the UI shows. The clients find the running Studio and its token through the discovery file it writes, so in the directory you ran it in they need no flags.

```sh
go install github.com/weftgo/weft/cmd/weft@latest
weft studio
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 a stock OpenTelemetry agent's, posted from [Inspect agents written in other languages](https://weftgo.dev/docs/observe/other-languages/#check-it-with-an-otlpjson-body), so it records no prompt and no stop. A Go app run from the same directory joins this Studio through the same file: its `otel.Install()` logs `INFO weft/otel: joined the running Studio url=http://127.0.0.1:7331 …`. In the outputs below, `~/work` and `~/xdg` stand for the scratch directories the commands ran in.

## What each command does

Every subcommand is a convenience over something an app or a script can do itself: `weft studio` is [`studio.New`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#New) with setup B's options, and the clients are thin wrappers of documented routes. A team that skips the CLI loses nothing.

| Command | What it does |
|---|---|
| `weft studio` | Setup B: the UI, OTLP ingest, the playground and a dev token stable per database, on `127.0.0.1:7331`, else the next free port in 7331–7340. One Studio per SQLite file: a second start on a file another Studio serves is refused |
| `weft dev` | `weft studio` in-process plus your app, restarted on a `.go` save; it reuses a Studio already serving the same database. One line per start: `studio http://127.0.0.1:7331/ · app pid … · runtime rt_… registered` |
| `weft runs` | One row per top-level run, newest first, from `GET /api/runs`. `--limit` defaults to 50 and says so on stderr when it hid runs; `--json` for scripts |
| `weft open [id]` | Prints the page of a run, public id, session or trace, bare; with no id the Studio root. `--with-token` adds the `#token=` fragment, `--open` hands the browser the link |
| `weft export <run id>` | `GET /api/runs/{id}/export` to stdout (`--format json`, `jsonl` or `otlp`), or with `--wefttest <dir>` the run's replay test written into a package directory |
| `weft doctor` | One line per check of a running Studio, each read from `GET /api/meta` |
| `weft mcp` | A read-only MCP server over stdio, so a coding agent reads runs while you debug |
| `weft vacuum` | One retention sweep, then `VACUUM` (SQLite) or `OPTIMIZE TABLE … FINAL` (ClickHouse) |
| `weft version` | The weft version the binary was built from |

Every connection flag mirrors an environment variable, and the flag wins: `--addr` is `WEFT_STUDIO_ADDR`, `--db` `WEFT_DB` (a bare SQLite path, where `--db` takes a `sqlite://` or `clickhouse://` URL), `--token` `WEFT_STUDIO_TOKEN`, `--manifest` `WEFT_MANIFEST`, `--url` `WEFT_STUDIO_URL`, `--retain` `WEFT_RETAIN`, `--pricing` `WEFT_PRICING`, `--log-level` `WEFT_LOG_LEVEL` and `--log-format` `WEFT_LOG_FORMAT` ([Common flags](https://weftgo.dev/docs/reference/cli/#common-flags)). `weft dev`'s `--watch` and `--no-watch`, `--open`, `--no-playground` and the action `--rotate-token` have no mirror. `-h` spells every flag with two dashes. The exit codes are 0 on success, 1 on a failure (one `weft: …` line on stderr) and 2 on a usage error, which names its arguments in words (`weft: export needs exactly one run id (got none)`). [weft CLI reference](https://weftgo.dev/docs/reference/cli/) lists every flag.

## Run Studio

`weft studio` with no flags serves `$WEFT_DB`, else `./.weft/weft.db` (the file an app's `otel.Install` writes by default), and prints where everything is:

```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 flags you reach for, with [Run Studio](https://weftgo.dev/docs/observe/studio/setup/#run-the-weft-studio-binary) covering the rest:

- `--db sqlite://path` serves another file; `--db clickhouse://user:pass@host:9000/db` serves the hosted backend.
- `--addr` pins the listen address. Without it, anything else on 7331 moves Studio to the next free port in 7331–7340 ([the port policy](https://weftgo.dev/docs/observe/weft-dev/#the-port-policy)).
- `--manifest weft.json` (or `WEFT_MANIFEST`) serves your `weft.json`; without it Studio looks for the nearest one upward, and one line says which file it loaded, by its absolute path: `studio: manifest /home/you/support/weft.json (found upward)`, or `(--manifest)` / `(WEFT_MANIFEST)`. A file that does not parse stops the start: `weft: manifest <path>: does not parse: …`, exit 1.
- `--open` opens the browser with the token in the URL fragment. It is on when stdout is a terminal; `--open=false` turns it off, and the banner's last line then says how to sign in. On a box with no browser opener the start goes on with one line, `weft: could not open a browser (…); open the link yourself`.
- `--no-playground` turns the playground off.

**One Studio per database.** `weft studio` takes a lock on `<db>.lock` beside a SQLite file while it serves, released when the process ends, a crash included. The file itself stays on disk after exit; leave it. A symlink, a directory or another non-regular file at that path, or on unix a hard link, is refused at start with `dblock: the lock file is not a regular file` ([One Studio per database](https://weftgo.dev/docs/reference/cli/#one-studio-per-database)). A second `weft studio` on the same file, from any directory and on any port, is refused with exit 1:

```text
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
```

`weft dev` reuses that Studio instead. Before 0.20.0 a second `weft studio` said `…, reusing` and exited 0. ClickHouse takes no lock.

When the discovery file cannot be written, the banner says `studio: no discovery file (<error>); apps need WEFT_STUDIO_URL=http://127.0.0.1:7331` and Studio serves anyway.

**The token.** The first start on a SQLite file writes a dev token beside it, `<db>.token` (mode 0600), and every later start serves the same one, so a restart keeps the browser tab and the app's `WEFT_STUDIO_TOKEN` valid. It is never printed; the banner names the file. `--rotate-token` writes a new one, and panel tokens signed with the old one stop verifying. `--token` or `WEFT_STUDIO_TOKEN` fixes the token instead and leaves the file alone. Only a database with no file (`sqlite://:memory:`, ClickHouse) gets a token printed at start. [The dev token](https://weftgo.dev/docs/observe/weft-dev/#the-dev-token) has the details.

## The API over a terminal

The clients are a terminal over Studio's JSON API, one route each: `weft runs` reads `GET /api/runs`, `weft open` checks the id it is given, `weft export` reads `GET /api/runs/{id}/export`, and `weft doctor` reads `GET /api/meta`. They compute nothing Studio does not serve.

All five clients, `weft mcp` included, find Studio the same way: `--url`, else `WEFT_STUDIO_URL`, else the discovery file a running `weft studio` or `weft dev` wrote (the trust rules `otel.Install` uses; `WEFT_DISCOVERY=off` skips it), 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. When you named no Studio, the first stderr line says which was taken and why: `weft: Studio http://127.0.0.1:7331 (discovery file …)`. Without a token, a Studio on a file answers 401:

```sh
WEFT_DISCOVERY=off weft runs
```

```text
weft: Studio http://127.0.0.1:7331 (the default address; WEFT_DISCOVERY=off)
weft: GET /api/runs: 401 the API requires a token: Authorization: Bearer <token> (--token or WEFT_STUDIO_TOKEN)
```

A Studio that does not answer reads `studio not reachable at <url>: …` with the fix. A redirect is an error, never followed: point `--url` at the Studio itself. Each request has a two-minute timeout.

## List and open runs

`weft runs` prints the newest top-level runs, 50 by default. Filters go to the server: `--agent`, `--failed`, and `--status` with one of `running`, `succeeded`, `failed`, `interrupted`, `parked` or `cancelled`. `--since` takes a duration back from now or an RFC 3339 time. The columns are the run's id, agent, status, start (local time with its zone), steps, duration, cost (own plus delegated), its public id when a row has one, the prompt's first line, what stopped it and, for a failed run, its error kind and why, cut to 60 characters. After the table, a line on stderr names the next step.

```sh
weft runs --status bogus
```

```text
weft: --status: status must be running, succeeded, failed, interrupted, parked or cancelled ("bogus" given)
```

That is exit 2. `--limit 0` lists every match; a limit that hid runs says so on stderr, which keeps stdout clean for a pipe:

```sh
weft runs --limit 1
```

```text
weft: showing the newest 1; --limit 0 lists all
```

`--json` prints the rows as Studio serves them, a JSON array with every field of the [runs list](https://weftgo.dev/docs/observe/studio/runs/) (`status`, `err`, `stopped_by`, `usage`, `cost_usd`, `prompt_preview` and the rest); its shape did not change when the table's columns did in 0.20.0. `PROMPT` reads `-` for a run with no prompt preview, and every cell prints control characters as spaces, since prompts and agent names are untrusted text.

`weft open` takes a run id, a public id, a session id or a trace id, tried in that order, and prints its page. With no id it prints the Studio root:

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

```text
http://127.0.0.1:7331/runs/otel-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7
```

The link is bare: the token may be the panel tokens' signing key, so it stays out of logs. `--with-token` prints `#token=<token>` after it, the resolved token; `weft open --with-token` with no id is how a terminal signs a browser in. `--open` hands the browser the link with the token in the fragment, which never reaches a server.

## Export a run

`weft export` writes the run's export to stdout, `json` by default, or `jsonl` and `otlp` with `--format`. From a 0.18.3 run, cut to 80 characters:

```sh
weft export c343127c37a733a7d1d88d897b7817dc --format jsonl | cut -c1-80
```

```text
{"record":"run","format":"weft.run.export/1","run":{"id":"c343127c37a733a7d1d88d
{"record":"event","pos":0,"time":"2026-10-18T10:42:16.532125457Z","event":{"type
{"record":"event","pos":1,"time":"2026-10-18T10:42:16.532154322Z","event":{"type
{"record":"event","pos":2,"time":"2026-10-18T10:42:16.532201922Z","event":{"type
{"record":"event","pos":3,"time":"2026-10-18T10:42:16.532220517Z","event":{"type
{"record":"event","pos":4,"time":"2026-10-18T10:42:16.532238692Z","event":{"type
{"record":"messages","index":0,"step":0,"input":true,"messages":[{"role":"user",
{"record":"messages","index":1,"step":0,"input":false,"messages":[{"role":"assis
{"record":"messages","index":2,"step":0,"input":false,"messages":[{"role":"tool"
{"record":"request","index":0,"step":0,"attempt":1,"time":"2026-10-18T10:42:16.5
{"record":"tools","hash":"d90d08d79c38775c5a61ba7037f26bb5e9f84ef466c82dae2a056c
{"record":"span","trace_id":"0793339c79b2442e7f091bcc3304c2be","span_id":"85cac7
{"record":"span","trace_id":"0793339c79b2442e7f091bcc3304c2be","span_id":"1cb8b9
{"record":"span","trace_id":"0793339c79b2442e7f091bcc3304c2be","span_id":"ab5844
```

[Export a run](https://weftgo.dev/docs/observe/studio/export/#formats) describes each format. With `--wefttest <dir>` it writes Studio's save-as-test tree into the package directory `<dir>`: a replay test and its `testdata/` that pass under `go test` there. `--fixtures-only` writes the fixtures alone under `<dir>/<test>`, for a test of your own. `--test <name>` names that test and so its directory (the run id by default); it goes only with `--fixtures-only`. A second export into the same place is refused, exit 1, until you pass `--force`. `--format wefttest` is exit 2 (`--format wefttest is a zip of fixtures: use --wefttest <dir>`). [Turn a Studio run into a test](https://weftgo.dev/docs/testing/studio-runs-as-tests/#export-fixtures-with-the-cli) has both forms.

## Check a Studio

`weft doctor` reads `GET /api/meta` within 5 s and prints one line per check:

```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. It checks that Studio is reachable and takes your token, and which discovery file this shell reads and whether it names this Studio. It reports the database's path and size, the content the latest run stored, and the newest run's age, weft version and service. It says whether OTLP ingest is open, walled or off, and counts the batches accepted and refused. It lists the connected runtimes and the panel bundle's version, and checks whether the manifest matches the latest runs. The `manifest` line names its source first: `weft.json`, or the runtimes' registrations when none is configured; before 0.20.0 it was labelled `weft.json`. A 401 names `--token "$(cat <db>.token)"` and `weft open --with-token`, and a capability that is off names its cause (`--no-playground`: "drop the flag"). A failed check exits 1, and an unreachable Studio is the first of them: one line and a hint, and no other check runs.

The [reference](https://weftgo.dev/docs/reference/cli/#weft-doctor) lists which field each line reads and when it warns or fails.

## Read runs from a coding agent

`weft mcp` serves Studio's read routes as 22 MCP tools over stdio, so Claude Code or Cursor answers "why did run X fail" from your Studio. [Let Claude Code or Cursor read your runs](https://weftgo.dev/docs/observe/weft-mcp/) sets it up.

## Best practices & gotchas

- **Run the clients where Studio runs, or name it.** With no `--url` they read the discovery file; a Studio elsewhere, or a shell with `WEFT_DISCOVERY=off`, needs `--url` and `--token`. (Source: `cmd/weft/resolve.go`)
- **Pass a database URL as `--db`, never as `WEFT_DB`.** `WEFT_DB` is a SQLite file path: `WEFT_DB='clickhouse://u:p@host:9000/db' weft studio` starts with no error and serves a new, empty SQLite file under a directory named after the URL, password included, which the banner's token line prints. (Source: `cmd/weft/main.go` (the WEFT_DB fallback); observed with the v0.20.2 binary)
- **Stop the running Studio before you start another on its file.** A second `weft studio` on one SQLite file is refused; use `weft dev`, which reuses it, or sign in to it with `weft open --with-token`. (Source: CHANGELOG.md:83)
- **Keep `--with-token` output out of logs.** The dev token is the panel tokens' signing key; the bare link is enough when the browser already holds the token. (Source: `weft open -h`; `cmd/weft/token.go`)
- **Read the limit note on stderr.** `weft runs` caps at 50 rows unless you pass `--limit 0`, and only stderr says it cut. (Source: `cmd/weft/api.go`)
- **Script against `--json`, not the table.** The table's columns changed in 0.20.0; the JSON did not. (Source: CHANGELOG.md:84)

## See also

- [Develop with weft dev](https://weftgo.dev/docs/observe/weft-dev/)
- [weft CLI reference](https://weftgo.dev/docs/reference/cli/)
- [Run Studio](https://weftgo.dev/docs/observe/studio/setup/)
- [Export a run](https://weftgo.dev/docs/observe/studio/export/)
- [Keep and delete recorded runs](https://weftgo.dev/docs/production/retention/)

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