Skip to main content

Workflows

A workflow is a short TypeScript script that runs subagents in the order the script sets. The script holds only the control flow: the order of stages, loops, branching. All prompts live in Markdown stage files next to the script.

Why you need it​

  • The script sets the order, not the model. In a multi-stage scenario such as "find → check every finding → compile a report", the model can't skip or forget a step.
  • Validated results. A stage can describe the shape of its answer, and the script branches on validated data rather than free text.
  • Background work and resuming. A run goes in the background, saves every completed agent call and, after a failure, resumes without rerunning what is already done.
  • Running without a UI. You can call a workflow from CI and scripts with explyt --workflow.

A workflow is similar to a skill, but it works differently. A skill is an instruction the model follows at its own discretion. A workflow is a program: the order of steps is fixed, and the model performs only individual stages. If a skill describes a multi-stage process and the model skips steps, rewrite it as a workflow. Stages run as subagents: you can choose a built-in or custom agent and a model profile for them.

Example: auditing routes​

The <project>/.explyt/workflows/audit/ folder:

WORKFLOW.ts
list-route-files.md
audit-file.md

WORKFLOW.ts:

export const meta = {
name: "audit-routes",
description: "Find route handlers without an authorization check",
}

const listing = await stage("list-route-files", { dir: args }) as { files: string[] }
const audits = await forEach(listing.files, (file: string) =>
stage("audit-file", { file }, { label: file, agent: "hawkeye", retries: 1 }),
{ onError: "skip" },
)
return audits

list-route-files.md:

---
name: list-route-files
returns:
files: [string]
---
List every file in {{dir}} that declares HTTP route handlers.

audit-file.md:

---
name: audit-file
returns:
file: string
issues:
- line: integer
severity: high | medium | low
---
Audit {{file}}. Name every handler that reads or writes data without an authorization check.

Running from the chat: /audit-routes src/api. The text after the name reaches the script as args. A full example with finding validation and a final report is at the end of the page.

Where workflows live​

RootApplies to
~/.explyt/workflows/all projects
<project>/.explyt/workflows/the current project only

A workflow is a direct subfolder of a root that contains a WORKFLOW.ts file. Files directly in the root are not workflows, deeper nested folders are not searched, parent directories are not searched, and other directories such as .claude/workflows/ are not read. The folder name doesn't matter: the workflow identifier is meta.name.

You can create the folder yourself or ask the agent: "Make a workflow that runs the tests module by module and compiles a report".

Folder contents​

<root>/<folder>/
WORKFLOW.ts the script, required
<anything>.md a stage, if its frontmatter has name
README.md not a stage, if its frontmatter has no name
.runs/ created by Explyt CLI, one folder per run

The WORKFLOW.ts script​

export const meta = {
name: "audit-routes",
description: "Find route handlers without an authorization check",
}
  • meta is exported exactly in this form, export const meta = { name, description }, and it is the only export.
  • name and description are plain string literals, not template strings or variables, and both are non-empty. meta can't have other keys.
  • name matches ^[a-z0-9]+(-[a-z0-9]+)*$, isn't workflows and doesn't match a built-in command name. It is the command name: audit-routes runs as /audit-routes.
  • You can use TypeScript type annotations in the script; they are removed before running. Syntax that requires transformation, such as enum and namespace, isn't accepted, and neither is any import.
  • Top-level await and return work in the script body. The returned value is the result of the run. It must be JSON (an object, an array, a string, a number, a boolean or null) or nothing.

Every stage(...) call is checked before running, without executing the script: its first argument must be a string literal with the name of a stage file from the same folder.

Globals​

Apart from the built-in language features, only these objects are available in the script:

ObjectShapeWhat it does
argsstringthe launch text, an empty string if there is none
stage(name, inputs?, options?) => Promise<object | string>runs one stage as one subagent
forEach(items, fn, { onError? }?) => Promise<array>passes the items through fn concurrently
parallel(thunks) => Promise<array>runs functions concurrently and rejects the same way as Promise.all
phase(title) => voidstarts a named group of the following stage calls
log(message) => voidadds a line to the run log

The script has no access to require, import(), process, the file system or the network. Any side effect is performed by a stage agent.

Determinism​

When a run resumes, the script runs again from the start, and stage calls that already completed get their answer from the journal. So the script must take the same path every time. Date.now(), Math.random() and new Date() without arguments throw an error in the script, while new Date(value) with an argument works. Anything that changes from run to run must come in a stage result: it is recorded in the journal.

Stage files​

A stage is a *.md file directly in the workflow folder whose frontmatter has name. The file body after the frontmatter is the prompt.

KeyRequiredValue
nameyesa non-empty string, unique in the folder; the stage identifier
returnsnothe result shape in the format described below

A stage's frontmatter can't have other keys. A Markdown file without name is not a stage and isn't checked.

Substitutions​

A substitution is written as {{key}}, where the key matches ^[A-Za-z_][A-Za-z0-9_]*$. Any other text inside double curly braces, including spaces ({{ file }}), makes the workflow invalid. Every substitution needs an input with the same key, and every input needs a substitution; otherwise the stage call fails before the agent starts. An input with the value undefined counts as missing.

Input valueHow it is substituted
stringas is
object or arrayJSON indented with two spaces
number, boolean, nullthe JSON text of the value

Result shape: returns​

returns is YAML whose root is a non-empty mapping. It becomes the schema of the agent's report_result tool, so the result is validated before the script sees it.

NotationMeaning
string, number, integer, booleanthat scalar type
key: <type> in a mappingan object, all keys required
key?: <type>an optional key
[<type>], a one-item sequencean array of that type
high | medium | lowa string, one of the listed values. An element can't be a scalar type name
returns:
file: string
issues:
- line: integer
severity: high | medium | low
evidence?: string

There are no field descriptions and no raw JSON Schema: { type: string } is read as an object with a type key. Simple values can be coerced to the type before validation, for example "3" to 3.

If returns is set, stage() returns the validated object. Without returns, the agent reports plain text, and stage() returns a string.

Stage call options​

stage(name, inputs, options) accepts these options:

OptionTypeDefaultWhat it does
agentstringnonethe helper agent, like the agent argument of subagent. See Subagents
modelProfilestringnonethe model profile, like model_profile of subagent
timeoutMspositive integerno limitstops an attempt that takes longer
retriesinteger from 00how many attempts to make after a failed one
labelnon-empty string<stage name> #<n>the agent name, only in progress views

The stage file doesn't choose the agent and the profile; the call in the script does:

stage("audit-file", { file, methods }, { label: file, agent: "hawkeye", retries: 1 })

Failures, retries and limits​

  • If a stage agent ended with an error, was cancelled or lost the connection, stage() rejects and never returns null. An uncaught rejection ends the run as failed.
  • forEach(items, fn) rejects if any call rejects. With { onError: "skip" } it returns the successful results in item order, and every skipped failure is recorded in the run.
  • retries starts a new agent for every attempt and covers any failure except a stop by the user. Only a successful attempt enters the journal.
  • A run keeps at most 8 stage agents running at once; other calls wait in call order. Stage agents also count toward subagents.maxConcurrency (see Settings): while the pool is full, a stage call waits instead of failing.
  • A run starts at most 200 stage agents, retries included. Calls replayed from the journal don't count. The call that would need agent 201 ends the run as failed.
  • A run ends in one of three states: done (the script returned a result), failed (the script threw, hit the limit or returned something that isn't JSON), stopped (the user stopped it or the session ended).

Running​

WhoHow
You in the chat/audit-routes src/api, only handlers that change data. The text after the name is args
The modelthe run_workflow tool by name or by path
CI, without a UIexplyt --workflow audit-routes src/api

run_workflow accepts name (a discovered workflow) or path (a workflow folder, relative to the session folder or absolute), but not both, plus optional args and resume. The tool returns right after the start with the run ID, and the outcome comes later as a separate message. There is no need to poll it. A subagent can't run a workflow.

The /workflows command shows all workflows with their status (● on, ○ off (project), ○ off (global), ✗ invalid, ✗ duplicate name) and the reason, the runs in the current project, and a Temporary group for workflows launched by path. Enter on a workflow turns it on and off, Enter on a run opens its timeline, and r resumes a run that can be resumed.

The launch question and permissions​

In the default and paranoid modes, every launch from the terminal asks a question first. In the bypassPermissions and afk modes, the launch goes without a question. The question shows the workflow name, the full path to its folder, the list of stages, and a warning that its agents work without permission checks.

  • Declining starts nothing.
  • An unanswered question is declined automatically after 5 minutes, and the launch fails with was not answered within 5 minutes. Launch the workflow again when you are back.
  • All stage agents run in bypassPermissions mode regardless of the session mode: you confirmed this by answering the question, or the session mode doesn't require it.
  • A launch without a UI asks nothing.
  • If the agent runs explyt --workflow … through bash, the permission policy asks you before the command in the default and paranoid modes. To launch a workflow from a session, the agent must call run_workflow.
warning

Stage agents run any commands without confirmation. Read the list of stages in the question and launch only workflows you trust.

Running without a UI​

explyt --workflow <name> [--resume [<run-id>]] [<text>...]

Only the result of the run goes to stdout: JSON for an object or an array, plain text for a string, empty output if there is no result. So, for example, explyt --workflow audit-routes src/api | jq .confirmed works. Progress, log lines and failure reasons go to stderr. A folder path is not accepted instead of a name.

Exit codeWhen
0the run ended done
1the run ended failed
2the launch failed before any agent started: an unknown, unavailable or invalid workflow, nothing to resume, invalid arguments
130the run ended stopped after an interrupt

Running explyt -p and the general CI rules are described on the Running in CI and scripts page.

Resuming a run​

A plain launch always starts a new run. Resuming continues a run in the failed or stopped state under the same ID and with the same args it started with:

  • /audit-routes --resume or --resume <run-id>; text after the flag is ignored with a notice.
  • run_workflow with resume: true (the latest resumable run of this workflow in the project) or resume: "<run-id>".
  • explyt --workflow audit-routes --resume [<run-id>].

Resume only when you ask for it: a run you stopped yourself stays stopped. While one session resumes a run, resuming the same run from another session fails until the first one finishes.

The script runs again from the start. A stage call whose stage name, filled-in prompt, returns schema, agent and profile match a journal entry gets the saved result without starting an agent. The N-th of several identical calls is matched with the N-th result in the journal. So editing a stage prompt reruns that stage's calls, while the rest are replayed from the journal. The label option doesn't take part in matching.

The run folder​

Every run is stored in <workflow folder>/.runs/<run-id>/:

.runs/.gitignore                ignores everything inside .runs/
.runs/<run-id>/run.json name, folder, project path, args, start and end time, state,
result or failure reason, phases, agents and log lines
.runs/<run-id>/journal.jsonl completed stage calls with their keys and results

The run records the absolute project path: resuming and /workflows consider only the runs of the current project. Explyt CLI doesn't delete runs itself; delete an unneeded .runs/<run-id>/ folder by hand. A launch by path also appends a line to <project>/.explyt/workflows/.temporary-runs.jsonl, which git ignores.

Disabling a workflow​

The workflows.disabledWorkflows key in settings.json (see Settings) holds exact, case-sensitive workflow names. It works at both levels:

{
"workflows": {
"disabledWorkflows": ["audit-routes"]
}
}

A disabled workflow has no command, isn't visible to the model and can't be launched by name. A launch by path ignores this setting. You can also turn workflows on and off in the /workflows window.

Unavailable and invalid workflows​

  • Two workflows with the same meta.name are both unavailable, whichever roots they are in.
  • A workflow and a skill with the same name are both unavailable.
  • A workflow is invalid if any check fails: meta, a stage call, a stage file, two stage files with the same name, a returns value, a substitution or forbidden syntax. The reason names the field, file or line. An invalid workflow can't be launched either by name or by path.

Checking before running​

After writing or editing a workflow, before run_workflow, call the check_workflow tool with name (a discovered workflow) or path (a workflow folder). It doesn't execute the script, asks nothing and starts nothing, and a subagent can call it too. It lists all problems at once, one per line:

WORKFLOW.ts:3 — stage "clasify" has no stage file. Fix: create clasify.md with "name: clasify" in its frontmatter, or use the existing stage "classify".

Fix them and call it again until the answer is OK. For a valid workflow the answer lists the stages with their returns fields and substitutions, the root it lives in, and whether it runs with the /name command. By name, the answer also explains why not: a duplicate name (with all paths) or workflows.disabledWorkflows (with the settings file to edit).

Temporary workflows written by the agent​

If the agent needs to drive several subagents through a fixed procedure, for example "find → check every finding → summarize" or the same action over a list, it can write a temporary workflow itself:

  1. It creates a <project>/.explyt/tmp-workflows/<name>/ folder with WORKFLOW.ts and the stage files. It doesn't put them directly in .explyt/workflows/: there it would become a discovered workflow with a /name command.
  2. It calls check_workflow with path and fixes the problems until the answer is OK.
  3. It calls run_workflow with the same path. You are not asked anything in advance: the launch question is asked before the agents start.

The first launch from .explyt/tmp-workflows/ creates a .gitignore there that ignores everything, so temporary workflows and their runs don't get into git. Explyt CLI deletes nothing from there. All launches by path are visible in the Temporary group of the /workflows window.

A temporary workflow runs only by path: it has no /name command and isn't visible to the model in the catalog. If you need the scenario permanently, move it to a workflow root. For a one-off task, for exploration where the next step depends on what is found, and for work that needs your answer midway, the agent uses regular subagents.

Full example​

<project>/.explyt/workflows/audit/WORKFLOW.ts:

export const meta = {
name: "audit-routes",
description: "Find route handlers without an authorization check and verify every finding",
}

phase("Discover")
const request = await stage("parse-request", { text: args }) as { dir: string; methods: string[] }
const listing = await stage("list-route-files", { dir: request.dir }, { agent: "retriever", modelProfile: "cheap" }) as { files: string[] }
log(`route files found: ${listing.files.length}`)

phase("Audit")
const audits = await forEach(listing.files, (file: string) =>
stage("audit-file", { file, methods: request.methods }, { label: file, agent: "hawkeye", retries: 1 }),
{ onError: "skip" },
) as { file: string; issues: { line: number; severity: string; evidence?: string }[] }[]

phase("Verify")
const findings = audits.flatMap((audit) => audit.issues.map((issue) => ({ file: audit.file, ...issue })))
const verdicts = await forEach(findings, (finding) => stage("verify-finding", { finding })) as { real: boolean; reason: string }[]
const confirmed = findings.filter((_, index) => verdicts[index].real)

phase("Summarize")
const report = await stage("write-report", { findings: confirmed })
return { confirmed, report }

parse-request.md:

---
name: parse-request
returns:
dir: string
methods: [string]
---
Read the request and extract the directory to audit and the HTTP methods to check
(all methods if none is named): {{text}}

list-route-files.md:

---
name: list-route-files
returns:
files: [string]
---
List every file in {{dir}} that declares HTTP route handlers.

audit-file.md:

---
name: audit-file
returns:
file: string
issues:
- line: integer
severity: high | medium | low
evidence?: string
---
Audit {{file}}. For every handler of these methods: {{methods}}, name the ones that
read or write data without an authorization check.

verify-finding.md:

---
name: verify-finding
returns:
real: boolean
reason: string
---
Check whether this finding is real by reading the code around it: {{finding}}

write-report.md has no returns, so stage() returns its text:

---
name: write-report
---
Write a short report on these confirmed findings, grouped by file: {{findings}}