Open History to see the last commit
1# Workflows
2
3Workflows (Labs) are durable TypeScript scripts that chain agents, code steps, schedules, webhooks, issue/PR triggers, and human approvals into multi-stage runs that survive server restarts. Each completed step is checkpointed so restarts resume where they left off.
4
5Use a **scheduled task** for a single prompt on a timer or webhook; use a **workflow** for multi-stage pipelines (e.g., triage → fix → approval → release).
6
7## Enable workflows
8
9Turn on **Settings → Labs → Workflows** on the server that will run them (or set `"workflowsEnabled": true` in `~/.t3/userdata/settings.json` on headless servers). Existing runs pause while disabled and resume when re-enabled.
10
11## Create a workflow
12
13Place `.ts` files in `~/.t3/workflows/` (or the path in `T3CODE_WORKFLOWS`). The server watches the folder and hot-reloads valid edits.
14
15- **With an agent (recommended)**: Copy the [`t3-workflows` skill](https://github.com/pingdotgg/t3code/blob/main/skills/t3-workflows/SKILL.md) into your agent's skills folder (e.g. `~/.claude/skills/` or `~/.agents/skills/`) and describe what you want.
16- **Directly**: Edit files in `~/.t3/workflows/` or use **Definitions** on the Workflows page (**Open workflows** in the command palette; saving/deleting in the app requires terminal access).
17
18Example (`~/.t3/workflows/release.ts`):
19
20```ts
21const { workflow, step, ask, stop, title } = T3;
22
23export default workflow(
24 "release",
25 { version: 1, payload: Schema.Struct({ name: Schema.String }) },
26 Effect.fn(function* (payload) {
27 yield* title(`Release ${payload.name}`);
28 const notes = yield* step("notes", { returns: Schema.String }, Effect.succeed("3 fixes"));
29 const answer = yield* ask("ship", {
30 title: `Ship ${payload.name}? ${notes}`,
31 choices: ["Ship", "Hold"],
32 });
33 if (Option.isNone(answer) || answer.value.choice !== "Ship") return yield* stop("held back");
34 return { shipped: payload.name };
35 }),
36);
37```
38
39- `T3`, `Effect`, `Schema`, and `Option` are globals—no imports needed.
40- Filenames may use letters, digits, `-`, `_`, and `.`. Dot-files and subfolders are ignored (put shared helpers in a subfolder; restart the server after editing imported helpers).
41- **Versioning**: Keep older workflow versions defined while they have unfinished runs; bump `version` to deploy new steps alongside active runs.
42
43## CLI commands
44
45```sh
46t3 workflow start <name> --input '<json>' --key <key>
47t3 workflow list [--status paused] [--tag <tag>] [--subject <url or id>]
48t3 workflow show <run>
49t3 workflow resume <run>
50t3 workflow cancel <run> [--reason '<why>']
51t3 workflow questions [--kind <kind>]
52t3 workflow signal '{"choice":"yes"}' --run <run> --wait <name>
53t3 workflow signal '<json>' --workflow <name> --channel <channel>
54t3 workflow withdraw --run <run> --wait <name> [--reason '<why>']
55t3 workflow hooks
56t3 workflow store list
57t3 workflow store set <key> '<json>'
58```
59
60- `--key` deduplicates starts across retries and version bumps.
61- `signal` answers an open question or wakes a channel wait (signals sent before a channel wait are buffered for 7 days by default).
62- `withdraw` cancels an open question so `ask` returns `None`.
63- `store` reads/writes shared state persisted between runs.
64
65## Questions, tags, and subjects
66
67- **Question kinds & tags**: Declare `asks: { kindKey: "Label" }` in workflow options and pass `kind` to `ask(...)` to filter open questions under **Needs you** (and `t3 workflow questions --kind <kind>`). Use `tags([...])` to label runs for filtering.
68- **Rich choices & links**: Pass `links: [{ label, url }]` and choice objects `{ value, description, requireReason }` to require an explanation before answering. Answers record `answeredAt` and `answeredBy`.
69- **Subjects**: Call `subject(issueOrPrOrThreadOrUrl)` (or pass `{ subject }` to `start(...)`) to display and link the target item in run lists, issue/PR views, and `t3 workflow list --subject <url>`.
70
71## Concurrency limits
72
73- **Whole-workflow cap**: Set `concurrency: 4` in workflow options.
74- **Step pools**: Wrap a section in `within("builders", { limit: 4 }, ...)` (`limit: 1` acts as a lock). Waiting runs show as **Queued** in FIFO order; resumed runs re-acquire their pools first.
75- Avoid nesting `within` on the same pool name (or a workflow's own concurrency pool), and avoid holding a lock across `invoke` if the child needs the same pool. Step names starting with `@pool:` are reserved.
76
77## Triggers
78
79- **Schedules**: `every` runs on an interval; `daily` runs at a local time of day (skipped if missed by >10 minutes while offline).
80- **Webhooks**: Run `t3 workflow hooks` to get each hook's secret path (prepend your server URL). Deduplicates retries by delivery header (e.g. `X-GitHub-Delivery`), rejects bodies >1 MiB, and rate-limits to 60 runs/min (`429`). Blocked if managed policy disables webhooks.
81- **Issues & PRs**: Triggers automatically on new issues or PRs via **Settings → Source control & issues** (polled ~every minute; only items opened after the workflow first loads).
82
83## Follow runs, agent threads, and failures
84
85Open **Open workflows** from the command palette (web/desktop) to filter **Needs you**, **Running**, or **All**, inspect agent threads, answer questions, resume, or cancel runs.
86
87- **Agent steps**: Each `agent` step runs in a regular thread (hidden from sidebar lists) that you can open live from the run. Supports custom `workspace`, `runtimeMode`, `interactionMode`, `title`, typed `returns`, and [linked environments](./remote-access.md#link-another-environment).
88- **Retries & pausing**: Failed code steps auto-retry after 5, 20, and 80 minutes (or immediately on **Resume**). Failed or timed-out agent steps pause for manual resume (offline-start failures auto-retry). Cancelling stops active agent turns and child runs permanently.
89- **Skipped runs**: Up to 500 skipped top-level runs are kept per workflow (configurable via **Settings → Labs → Skipped runs kept** or `"workflowSkippedRunsKept"` in `settings.json`).
90- **Always-on requirement**: Runs only advance while the server that started them is online.