---
title: Export a run
description: 'Download a recorded run from Studio as one JSON document, JSON lines, OTLP/JSON that another Studio re-ingests, or wefttest replay fixtures, with or without its subagent runs: the run page''s export verbs, GET /api/runs/{id}/export and weft export.'
url: https://weftgo.dev/docs/observe/studio/export/
type: how-to
sources:
  - 'W11-auditB2-fix, v0.20.2: weft/studio/web/src/lib/run-actions.ts:83-108 (CURL, curlFor); weft/studio/web/src/components/studio/run-actions.tsx:104-140; weft/CHANGELOG.md:49'
  - 'weft/CHANGELOG.md:229 (0.18.0: the session export, weft.session.export/1, its lines and caps)'
  - 'weft/studio/export.go:30-80 (the four formats, tree=1, the read-scope rule), 82-96 (formats, extensions, media types, weft.run.export/1), 98-164 (serveRunExport: format, tree, wefttest with tree a 400), 166-219 (collectSubtree: breadth first, at most 200, truncated and hidden holes), 221-236 (the tree document), 238-261 (the tree''s jsonl), 263-290 (otlp of several runs), 292-311 (writeDownload: the file name, HEAD), 347-407 (exportFixtures: the zip), 409-418 (409 with its badge), 594-619 (exportDoc, events, transcript)'
  - weft/studio/routes.go:140-143 (capability export)
  - 'weft/studio/fixtures.go:599-626 (fixturesOrConflict: derived 400, stripped/gap/derived 409, no assistant turn 409 without a badge); weft/studio/api.go:1926-1937 (refuseDerived)'
  - 'weft/studio/export.go:884-951 (the jsonl record kinds: run, badge, event, gap, messages, compaction, request, prompt, tools, span)'
  - weft/internal/discovery/discovery.go:121-135, 167-232 (a stale file is ignored; Write removes it; Remove with several Studios)
  - weft/studio/web/src/lib/run-actions.ts:68-76 (a read-scoped token is offered json and jsonl)
  - weft/studio/savetest.go:59-79 (TestReplay_<run>, <agent>_replay_test.go)
  - weft/studio/ingest/ingest.go:91-99 (/v1/traces and /v1/logs take application/json)
  - 'weft/studio/web/src/lib/run-actions.ts:1-20 (the export verbs, a read token gets no otlp), 31-66 (EXPORT_FORMATS, with child runs), 122-127 (saved <file>, export refused: …)'
  - weft/studio/web/src/components/studio/run-actions.tsx:1-5 (fetched with the bearer, saved as a blob), 46-173 (ExportVerbs)
  - weft/studio/web/src/lib/saves.ts:90 (save as test)
  - 'weft/cmd/weft/api.go:560-618 (weft export: --format json|jsonl|otlp, --wefttest, --test, --force, no --tree), 641-851 (unzipFixtures)'
  - 'weft/cmd/weft/resolve.go:15-22 (the one resolver every client shares), 45-80 (resolveStudio: --url, else WEFT_STUDIO_URL, else the discovery file, else http://127.0.0.1:7331; --token, else WEFT_STUDIO_TOKEN, else the discovery file''s when it names the resolved Studio), 106-117 (the stderr line when the user did not name the Studio); weft/internal/discovery/discovery.go:118-138 (Stale: a dead pid, a non-loopback url, 24 h); weft/CHANGELOG.md:84 (0.20.0 Breaking: the clients'' --url default is the resolver''s)'
  - 'weft/studio/requests.go:187-190 (readsPrompts: no panel token, or a playground one)'
  - weft/AGENTS.md:282-287 (runs/{id}/export?format=json|jsonl|otlp|wefttest, capability export, tree=1 ≤ 200, subagent_holes, <run>.tree.<ext>, wefttest refuses tree), 428-430 (weft export)
  - 'weft/CHANGELOG.md:300 (0.17.0: tree=1, subagents and subagent_holes, jsonl subagent_hole lines, otlp re-ingests as the tree, wefttest with tree a 400, with child runs), 573 (a derived run refuses wefttest), 2786 (0.10.0: the export, its four formats, Content-Disposition, HEAD, the read-token rule, 400/404/409)'
  - 'docs-site/examples/studio/export_test.go: TestExportFormats'
  - 'observed: weft studio v0.17.0 over a scratch database (a support-bot run and a lead run with one research subagent); weft export, curl -OJ, and the tree''s OTLP posted to a second weft studio on an empty database (outputs below)'
---

# Export a run

Studio exports a whole recorded run as one download: `GET /api/runs/{id}/export?format=json|jsonl|otlp|wefttest`. `json` is one document, `jsonl` the same records one per line, `otlp` the run's records and spans as OTLP/JSON that another Studio re-ingests, and `wefttest` a zip of replay fixtures. Add `&tree=1` to export every subagent run under it too. On a run's page the header's **export** verbs download the first three; **save as test** downloads the fourth. From a terminal, `weft export <run id>` writes the export to stdout.

```sh
weft export c17b44940f21af67c33a6b68daa3c40d --format jsonl | jq -r .record | uniq -c
```

```text
      1 run
      8 event
      4 messages
      2 request
      1 tools
      4 span
```

`weft export` talks to `--url`, else `$WEFT_STUDIO_URL`, else the Studio the discovery file of a running `weft studio` or `weft dev` names, else `http://127.0.0.1:7331`, with `--token`, else `$WEFT_STUDIO_TOKEN`, else the discovery file's token when that file names the same Studio. An export is data: it reads Studio's database and never writes or runs your agent.

## Export from the run page

The run header shows **export** with **json**, **jsonl** and **otlp** (json and jsonl only for a read-scoped panel token), and, on a run with child runs, a **with child runs** checkbox that adds `&tree=1`. Each button fetches the export with the bearer in the `Authorization` header, never a token in a URL, and saves it under the server's file name. A toast says `saved <file>`, or `export refused: <reason>`. **save as test** beside them downloads the `wefttest` zip ([Turn a Studio run into a test](https://weftgo.dev/docs/testing/studio-runs-as-tests/)). Without the `export` capability the verbs are not drawn.

**copy as curl** (0.20.0) opens one button per format; each copies a command that downloads that export, `&tree=1` included when the checkbox is on. Where Studio requires a token the command carries `-H "Authorization: Bearer $WEFT_STUDIO_TOKEN"`, naming the variable, never the token. The toast says `copied a curl command`, or `the browser refused the clipboard`.

```sh
curl -fsSL -OJ -H "Authorization: Bearer $WEFT_STUDIO_TOKEN" 'http://127.0.0.1:7331/api/runs/<run>/export?format=jsonl'
```

## Formats

| `format` | File | Content-Type | Holds |
|---|---|---|---|
| `json` | `<run>.json` | `application/json; charset=utf-8` | One `weft.run.export/1` document: `run` (as `/api/runs/{id}` serves it), `events` (with `gaps`), `transcript` (the messages batches), `compactions`, `requests` (the request records, plus the `prompts` and `catalogs` they name, keyed by hash), `spans` and `holes` |
| `jsonl` | `<run>.jsonl` | `application/x-ndjson` | The same records, one `{"record": <kind>, …}` per line, in a stable order: the run (with its holes), the block badges, events by position, then `gap` lines for missing positions, messages by index, compactions, requests by index, prompts, catalogs (`tools` records), spans |
| `otlp` | `<run>.otlp.json` | `application/json; charset=utf-8` | `{"logs": ExportLogsServiceRequest, "traces": ExportTraceServiceRequest}` in OTLP/JSON, ids as hex. `POST /v1/logs` and `/v1/traces` read each half back into the same run |
| `wefttest` | `<run>.zip` | `application/zip` | A generated `<agent>_replay_test.go` beside the run's model calls as fixtures under `testdata/TestReplay_<run>/`; unzipped into a package directory, `go test` replays the run |

A whole conversation exports too (since 0.18.0): the session page's **export jsonl**, or `GET /api/sessions/{id}/export?format=jsonl`, downloads `<session>.session.jsonl`, format `weft.session.export/1`, streamed one turn at a time. It holds a `session` line, every turn's run export in turn order (at most 200 turns), the state log's `session_mark` lines (at most 2,000), `session_hole` lines and a closing `session_end` line `{turns_exported, marks_exported, bytes}`. Past 64 MiB it stops with a `truncated` hole, cause `response_cap` ([the route](https://weftgo.dev/docs/reference/studio-api/#get-api-sessions-id-export)).

A block the run does not have is badged, never left silently empty: `not_recorded` for a run written before the request record, `stripped` for a content-off run's prompts and catalogs, `gap` for records a destination dropped ([Badges and holes](https://weftgo.dev/docs/reference/badges/)). The `otlp` records are rebuilt from what Studio stored: each carries the run's identity and metadata, and one heartbeat at the run's last-seen time keeps its status. Their resource carries only `service.name`; the spans keep their own resource.

The `json` document's top-level keys, from the same run:

```sh
weft export c17b44940f21af67c33a6b68daa3c40d | jq -c 'keys, .format, .holes'
```

```text
["compactions","events","format","holes","requests","run","spans","transcript"]
"weft.run.export/1"
[]
```

The file name is the run id plus the extension, sent as `Content-Disposition: attachment`. A child run's slashes, quotes, backslashes, control and non-ASCII characters are spelled `_` in the quoted name, and a non-ASCII id adds RFC 6266's `filename*`. `HEAD` answers the headers alone. `curl -OJ` saves under that name:

```sh
curl -sOJ -H "Authorization: Bearer $TOKEN" \
  'http://127.0.0.1:7331/api/runs/c17b44940f21af67c33a6b68daa3c40d/export?format=otlp'
ls
```

```text
c17b44940f21af67c33a6b68daa3c40d.otlp.json
```

## Export a run with its subagents

With `&tree=1`, the `json`, `jsonl` and `otlp` exports carry the run and then every subagent run under it, breadth first, at most 200, each its own export. The file is `<run>.tree.<ext>`.

- **json** adds `subagents` (each child's document; its `run` block names its `parent_run_id`) and `subagent_holes`, `[]` when the tree is whole.
- **jsonl** writes each run's lines in turn, each starting with its own `run` record, then one `subagent_hole` line per hole.
- **otlp** puts every run in the same two requests, so a re-ingest restores the tree.

`subagent_holes` holds `truncated` (cause `response_cap`) when the tree has more than 200 subagent runs, and `hidden` with a `count` for the runs a panel token's public id does not reach, left out with their subtrees. `format=wefttest&tree=1` is a 400: a replay of the run substitutes its subagents' recorded answers, so it needs only the run's own calls. `weft export` has no tree flag; use the route.

The lead run here delegated once, to a research agent:

```sh
curl -s -H "Authorization: Bearer $TOKEN" \
  'http://127.0.0.1:7331/api/runs/93155b4ade161db6f7e80ee9b2ce01cb/export?format=jsonl&tree=1' \
  | jq -c 'select(.record=="run") | {record, id: .run.id, parent: .run.parent_run_id}'
```

```text
{"record":"run","id":"93155b4ade161db6f7e80ee9b2ce01cb","parent":""}
{"record":"run","id":"93155b4ade161db6f7e80ee9b2ce01cb/0/d1","parent":"93155b4ade161db6f7e80ee9b2ce01cb"}
```

## Move a run to another Studio

Post the two halves of an `otlp` export to the other Studio's OTLP ingest. Here the tree goes to a second `weft studio` on an empty database, at `127.0.0.1:7333`, which takes OTLP from loopback without a token:

```sh
curl -sOJ -H "Authorization: Bearer $TOKEN" \
  'http://127.0.0.1:7331/api/runs/93155b4ade161db6f7e80ee9b2ce01cb/export?format=otlp&tree=1'
jq .logs 93155b4ade161db6f7e80ee9b2ce01cb.tree.otlp.json \
  | curl -s -w ' %{http_code}\n' -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:7333/v1/logs
jq .traces 93155b4ade161db6f7e80ee9b2ce01cb.tree.otlp.json \
  | curl -s -w ' %{http_code}\n' -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:7333/v1/traces
```

```text
{} 200
{} 200
```

The second Studio then lists both runs (`GET /api/runs?all=1` with its own token):

```text
{"id":"93155b4ade161db6f7e80ee9b2ce01cb/0/d1","agent":"research","status":"succeeded","steps":1}
{"id":"93155b4ade161db6f7e80ee9b2ce01cb","agent":"lead","status":"succeeded","steps":2}
```

A Studio built with `studio.IngestToken` needs `Authorization: Bearer <ingest token>` on both posts ([Run Studio](https://weftgo.dev/docs/observe/studio/setup/#host-studio-behind-a-token)).

## Write a run's fixtures into your tests

`weft export <run id> --wefttest <dir>` fetches the `wefttest` zip and writes its fixtures under `<dir>/<test>`, where `wefttest.Replay` reads them. `--test` names the test; pass a `TestXxx` name, since the default (the run id) is not a valid Go test name. Without `--force` a target directory that is not empty is an error (exit 1, `weft: <dir> is not empty: --force writes into it`); with it, the `*.json` fixtures already there are replaced, never merged. It does not write the generated test file: the Studio download carries that.

```sh
weft export c17b44940f21af67c33a6b68daa3c40d --wefttest ./testdata --test TestSupportReplay
```

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

`--format wefttest` is a usage error (exit 2): `weft: --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/) covers the zip and the replay.

## Who may export what

| Request | Answer |
|---|---|
| The dev token, setup A's loopback, or a playground panel token (for the runs of its public id) | Every format |
| A read-scoped panel token, `json` or `jsonl` | 200, with the request block replaced by `{"badge": "hidden"}`: no system prompts or tool catalogs |
| A read-scoped panel token, `otlp` or `wefttest` | 403 with the `hidden` badge: both carry the request records |
| An unknown `format` | 400 `format must be json, jsonl, otlp or wefttest` |
| An unknown run | 404 |
| `wefttest` for a [derived run](https://weftgo.dev/docs/reference/glossary/#derived-run) (built from stock spans) | 400 with the `derived` badge |
| `wefttest` for a run whose records cannot be fixtured | 409 with its badge: `stripped` (content off), `gap` (no transcript, or a step whose request record was dropped), or `derived` (a transcript that does not fixture) |
| `wefttest` for a run that recorded no assistant turn | 409 with no badge: nothing is missing, there is nothing to replay |

`TestExportFormats` in `docs-site/examples/studio/export_test.go` records a run into a temporary database and checks each format's answer, the `tree=1` file name, and the two 400s. Run it from `docs-site/examples`:

```sh
go test -v -run 'Export' ./studio
```

```text
--- PASS: TestExportFormats (0.02s)
PASS
ok  	weftgo.dev/docs/examples/studio	0.049s
```

## Best practices & gotchas

- **Export the tree to move a delegation.** A plain export holds one run; re-ingested alone, a parent's subagent runs are missing. (Source: `studio/export.go:67-73`; CHANGELOG.md:300)
- **Treat an export as the transcript.** With content on it holds prompts, tool arguments and results; share it as you would the database. (Source: `studio/export.go:38-44`)
- **An `otlp` export is not the original records.** Studio rebuilds them from what it stored, and the log records' resource keeps only `service.name`. (Source: CHANGELOG.md:2786-2818)
- **Name the Studio when several run.** With no `--url` or `WEFT_STUDIO_URL`, `weft export` takes the Studio the discovery file names and says so in one stderr line, `weft: Studio <url> (discovery file …)`. A file naming a stopped Studio is ignored (its pid is not running), and the export falls back to `http://127.0.0.1:7331`. Point `--url` at the Studio that holds the run. (Source: `cmd/weft/resolve.go:45-80, 106-117`; `internal/discovery/discovery.go:118-138`)

## See also

- [Turn a Studio run into a test](https://weftgo.dev/docs/testing/studio-runs-as-tests/)
- [Read a run in Studio](https://weftgo.dev/docs/observe/studio/run-page/)
- [Use the weft command](https://weftgo.dev/docs/observe/cli/)
- [Badges and holes](https://weftgo.dev/docs/reference/badges/)
- [Studio HTTP API](https://weftgo.dev/docs/reference/studio-api/)
