Dynamic Workflows: Scripted Fan-Out

One prompt to hundreds of subagents, results out of context

Advanced 16 minBuilder
What you'll be able to do
  • Explain what a dynamic workflow is — a Claude-written JavaScript script executed by a separate runtime — and why intermediate results live in script variables instead of the context window
  • Trigger a workflow three ways: the `ultracode` keyword, a saved /<name> command, or /effort ultracode (auto-decide); and run the bundled /deep-research workflow
  • Describe the conceptual scripting primitives (spawn/agent, parallel, pipeline, phase, log) and the mandatory literal `export const meta` block — and know to READ the generated script rather than memorize an API whose names vary by version
  • State the runtime caps and constraints: 16 concurrent / 1,000 total agents, no mid-run input, no script-level filesystem or shell, no nested workflows, string/JSON data flow only
  • Monitor, pause, resume, stop, and save a run with /workflows, and disable workflows three ways — while respecting that this is a research preview that costs substantially more
At a glance

Dynamic workflows are Claude Code's flagship orchestration feature: instead of coordinating a few subagents turn by turn, Claude WRITES a JavaScript orchestration script that a separate runtime executes — fanning work out to dozens or hundreds of subagents. The defining property is where intermediate results live: in SCRIPT VARIABLES, outside your context window, so only the final verified answer enters your session. This lesson covers what a workflow is and why it requires v2.1.154+ (research preview), the three trigger paths (the `ultracode` keyword, a saved /<name> command, and /effort ultracode), the conceptual scripting primitives and the mandatory literal meta block, the hard runtime caps (16 concurrent, 1,000 total), and how to monitor, pause, resume, and save a run with /workflows.

  1. 1The mental model: move the plan out of the conversation and into a script
  2. 2Where workflows sit among the four multi-agent paradigms
  3. 3Three ways to trigger a workflow (plus the bundled one)
  4. 4The scripting primitives — concepts, not memorized names
  5. 5The mandatory meta block and the string/JSON data flow
  6. 6Runtime caps and constraints — the guardrails
  7. 7Monitor, pause, resume, and save with /workflows

The mental model: move the plan out of the conversation and into a script

The single-subagent lesson covered delegating ONE heavy task to a helper that reports a summary back. This lesson is about coordinating many agents — and dynamic workflows are the flagship feature for it.

With subagents, skills, and agent teams, Claude is the orchestrator: turn by turn, it decides what to spawn next, and every result it gets back lands in a context window. That works for a handful of agents. It does not scale to hundreds — you'd drown the context window in intermediate chatter long before you reached the answer.

A dynamic workflow moves the plan out of the conversation and into code. Claude WRITES a JavaScript orchestration script for the task you describe, and a separate runtime executes that script in the background. The loop, the branching, and — critically — the intermediate results all live inside the script. Your session's context holds only the final answer.

text
WITHOUT a workflow (Claude orchestrates, turn by turn)
  every agent's result  ──►  Claude's context window  (fills up fast)

WITH a workflow (the SCRIPT orchestrates)
  agent 1 result ─┐
  agent 2 result ─┤──►  SCRIPT VARIABLES  ──►  final answer ──► your session
  ... agent 348 ─┘     (outside the context window)

That single shift — intermediate state in script variables, not the context window — is the whole point. It is what lets one prompt fan out to hundreds of subagents and still return a clean, single result. Two consequences follow: the orchestration is now a script you can read, save, and rerun, and it can apply a repeatable quality pattern (e.g. have independent agents adversarially review each other's findings before any are reported) rather than just running more agents.

Watch out

Research preview — verify against your version

Dynamic workflows are in research preview and require Claude Code v2.1.154+ (check with claude --version). They are available on Pro / Team / Enterprise plans, with Anthropic API access, and on Bedrock / Vertex AI / Foundry. Behavior, caps, and the scripting-API surface change frequently — always defer to /help and the live docs for your installed version. On Pro you turn them on from the Dynamic workflows row in /config.

Where workflows sit among the four multi-agent paradigms

Learners conflate Claude Code's multi-agent modes constantly. The honest way to tell them apart is to ask who holds the plan and where intermediate results live.

SubagentsSkillsAgent teamsWorkflows
What it isA worker Claude spawnsInstructions Claude followsA lead supervising peer sessionsA script the runtime executes
Who decides what runs nextClaude, turn by turnClaude, per the promptThe lead, turn by turnThe script
Where intermediate results liveClaude's contextClaude's contextA shared task listScript variables
ScaleA few per turnSame as subagentsA handful of peersDozens to hundreds per run
StatusGAGAExperimental (off by default)Research preview (v2.1.154+)

The decisive rows are the last three. Workflows are the only paradigm where the plan lives in code and intermediate results stay out of the context window — which is exactly why they're the one that scales to hundreds of agents.

Decision rule of thumb:

  • Need deterministic, repeatable, large-scale fan-out (audit 500 files, cross-checked research, a big migration)? → workflow.
  • Need agents to talk to each other and divide a fuzzy problem (debate, parallel feature work with handoffs)? → agent team (a different feature, experimental).
  • Just need context isolation for one heavy read? → a subagent (the previous lesson).

Key insight

"Codified orchestration" is the upgrade

A subagent is repeatable in the sense that its definition is reusable. A workflow makes the orchestration itself repeatable — the whole fan-out, cross-check, and vote pattern becomes a script you can save as a /<name> command and rerun on every branch or every release. You're not just running more agents; you're capturing the plan as a durable, readable artifact.

Three ways to trigger a workflow (plus the bundled one)

There are three trigger paths. The first is the quickest; the third hands the decision to Claude.

1. The ultracode keyword in a prompt. Include ultracode anywhere in a prompt and Claude writes a workflow for that one task instead of working through it turn by turn. Saying it in plain language ("use a workflow", "run a workflow") works too — Claude treats a direct request as the same opt-in.

text
ultracode: audit every API endpoint under src/routes/ for missing auth checks

Claude Code highlights the keyword in your input. If you didn't mean to start a workflow, press Option+W (macOS) or Alt+W (Windows/Linux) to dismiss the highlight for that prompt. To stop the keyword triggering at all, turn off Ultracode keyword trigger in /config.

2. A saved /<name> command. Once a run does what you wanted, you can save its script (see the monitoring section). It then runs as /<name> in future sessions — a reusable orchestration primitive.

3. /effort ultracode (auto-decide). Ultracode is a Claude Code setting that combines xhigh reasoning effort with automatic workflow orchestration. With it on, Claude decides on its own when a substantive task warrants a workflow and deploys one — a single request can even spawn several workflows in a row (understand the code, make the change, verify it). It lasts the session and resets on a new one; drop back with /effort high for routine work.

text
/effort ultracode

The bundled workflow: /deep-research. The fastest way to see a workflow in action is the one Claude Code ships with. /deep-research <question> fans out web searches across several angles, fetches and cross-checks the sources, votes on each claim, and returns a cited report with claims that didn't survive cross-checking already filtered out. (It requires the WebSearch tool to be available.)

text
/deep-research What changed in the Node.js permission model between v20 and v22?

Note

`ultracode` is current; mind the version note

ultracode (workflows) and ultrathink (deeper reasoning for one prompt) are current keywords, not deprecated. One version caveat: before v2.1.160 the literal trigger keyword was workflow rather than ultracode — but natural-language requests like "use a workflow" work in both versions, which is the safe phrasing to teach.

The scripting primitives — concepts, not memorized names

Claude writes the script; you read it, you don't write it from scratch. That framing matters because the exact API surface names differ by version and by source. The official workflows.md describes dispatching subagents with spawn(definition, prompt, args); third-party writeups describe higher-level helpers agent(), parallel(), pipeline(), phase(), log(). Rather than memorize names that drift, learn the concepts and then read the script Claude generates for your version.

The conceptual primitives:

Primitive (conceptual)What it doesKey property
spawn(def, prompt, args) / agent(prompt, opts?)Spawn ONE subagentReturns a STRING result. Each call counts toward the 1,000 cap
parallel(thunks)Run several agents concurrentlyA barrier — ALL must finish before the script proceeds
pipeline(items, ...stages)Push batches through stagesNo per-stage barrier — a slow agent blocks only later items, not the whole stage
phase(title)Organize the progress displayGroups agents into the phases you see in /workflows
log(msg)Emit a status messageSurfaces progress as the run goes

The single most important fact: an agent call returns a STRING. There is no shared memory and no agent-to-agent channel. The script feeds one agent's string output into the next agent's prompt, and if structured output is needed, the script parses it — the agents do not talk to each other.

The official docs note you can ask for the script's path (every run writes its script under your session's directory in ~/.claude/projects/), open it to read the orchestration Claude wrote, diff it against a previous run, or even edit it and ask Claude to relaunch from the edited version.

Tip

Read the raw script before you approve

At the approval prompt you can choose View raw script (or Ctrl+G to open it in your editor) and Tab to adjust the prompt before the run starts. For any substantial or expensive run, read the script first — it's the ground truth for what will actually execute on your machine, and it sidesteps the whole "which API name is current" question.

The mandatory meta block and the string/JSON data flow

Every workflow script carries a literal export const meta block. "Literal" is the whole rule: no function calls, no variables, no dynamic construction, no parsing tricks — any deviation breaks parsing. It must be a plain object the runtime can read statically.

js
export const meta = {
  name: 'audit-auth',
  description: 'Audit every route for missing auth checks',
  phases: [{ title: 'Scan routes' }, { title: 'Cross-check findings' }], // optional
  inputSchema: { /* JSON Schema */ }                                       // optional
};
  • name and description are required; phases and inputSchema are optional.
  • A saved workflow can accept input through an args parameter — the script reads it as a global named args. If you call the saved command with structured data ("run /triage-issues on issues 1024, 1025, 1030"), the script can call array/object methods on args directly; if args is omitted, the global is undefined.

Data flow is string concatenation / JSON serialization — nothing more. There is no message bus, no shared state, no agent-to-agent communication. Each agent receives a prompt string and returns a string; the SCRIPT concatenates outputs into the next input and parses anything it needs. This is deliberately the opposite of agent teams (which DO have a shared mailbox and task list). In a workflow, the script is the only coordinator.

Watch out

Don't try to be clever with the meta block

Because the runtime reads meta statically (before running anything), it must be a literal object. Building name from a variable, calling a helper to assemble phases, or wrapping it in a conditional will break parsing. If Claude's generated script ever does this, that's a bug to fix in the script — keep meta a plain, literal object.

Runtime caps and constraints — the guardrails

The runtime executes the script in an isolated environment, separate from your conversation, and enforces hard limits. Teach these as guardrails:

ConstraintWhy it exists
16 concurrent agents (fewer on low-core machines)Bounds local resource use
1,000 agents total per runPrevents runaway loops from spinning forever
No mid-run user inputOnly agent permission prompts can pause a run. For sign-off between stages, run each stage as its own workflow
No script-level filesystem or shell accessThe script coordinates; agents do all the reading, writing, and command-running. Delegate I/O to agent calls
No nested workflowsA workflow can't spawn another workflow

Two permission facts worth flagging. First, the subagents a workflow spawns always run in acceptEdits mode and inherit your tool allowlist, regardless of your session's permission mode — file edits are auto-approved. Second, shell commands, web fetches, and MCP tools that aren't on your allowlist can still prompt you mid-run; to avoid interruptions on a long run, add the commands the agents need to your allowlist before starting.

Watch out

Workflow subagents auto-approve file edits

Even if your session is in default or plan mode, agents spawned by a workflow run in acceptEdits — their file edits are approved automatically. That's by design (no human is watching each of 300 agents), but it means a workflow that writes files will write them without per-edit confirmation. Scope the task carefully, and test on one directory before pointing it at the whole repo.

Monitor, pause, resume, and save with /workflows

Workflows run in the background, so your session stays responsive while agents work. /workflows lists running and completed runs; select one and press Enter to open its progress view, which shows each phase with its agent counts, token totals, and elapsed time. Drill into a phase, then an agent, to read its prompt, recent tool calls, and result.

KeyAction
/ Select a phase or agent
Enter / Drill into the selection
EscBack out one level
j / kScroll within an agent's detail
pPause / resume the run
xStop the selected agent, or the whole workflow when focus is on the run
rRestart the selected running agent
sSave the run's script as a reusable command

Resume is cheap: completed agents return their cached results and only the remaining agents run live. But resume works only within the same Claude Code session — exit Claude Code and the next session starts the workflow fresh (there's no cross-session checkpoint).

Save for reuse: from /workflows, press s, then Tab toggles the save location — .claude/workflows/ (project, shared via git) or ~/.claude/workflows/ (personal). Saved workflows appear as /<name> commands and accept input via the args parameter, so they become reusable orchestration primitives (usable in CI via claude -p and the Agent SDK). If a project and a personal workflow share a name, the project one wins.

Cost discipline. A run spawns many agents, so it can use meaningfully more tokens than the same task in conversation, and it counts toward your plan's usage and rate limits. Test on a small slice first — one directory, a narrow question — watch per-phase tokens in /workflows, and stop at any time without losing completed work.

Disabling. Turn workflows off three ways, all of which remove /deep-research, the ultracode keyword trigger, and ultracode from the /effort menu:

  • Toggle Dynamic workflows off in /config.
  • Set "disableWorkflows": true in ~/.claude/settings.json (or managed settings, org-wide).
  • Set CLAUDE_CODE_DISABLE_WORKFLOWS=1.

Tip

Save the winners; they become /commands

The payoff of all this is reuse. Once a run produces the result you want — say a per-branch security sweep with adversarial cross-checking — press s to save it. From then on it's a /<name> command you can run on every branch or wire into CI, and it executes the same orchestration each time. That's the difference between a one-off fan-out and a durable team capability.

Try it: Run, watch, and save your first workflow

Practice the full workflow loop on a small, cheap slice. Prerequisites: Claude Code v2.1.154+ (claude --version), a Pro/Team/Enterprise plan (or Bedrock/Vertex/Foundry), and Dynamic workflows enabled (the Dynamic workflows row in /config). This is a research preview — if a command or key differs from what's below, defer to /help and the live docs for your version.

  1. Bundled workflow: run /deep-research <a narrow question you can fact-check>. Approve at the prompt — but first choose View raw script (or Ctrl+G) and skim the orchestration Claude wrote. Note that it fans out searches, cross-checks, and votes before reporting.
  2. Watch a run: while it runs, open /workflows, select the run, and press Enter. Drill into a phase, then an agent (Enter/), and read its prompt and result. Note the per-phase token totals — this is your cost gauge.
  3. Control it: press p to pause, then p again to resume (finished agents return cached results). Try x to stop a single agent. Observe that resume only works in this same session.
  4. Your own task, small slice: trigger a workflow on ONE directory with the keyword — e.g. ultracode: list every TODO comment under src/utils/ and group them by file. (If you didn't mean to trigger it, press Option+W / Alt+W.) Approve, then read the raw script and find the export const meta block — confirm it's a literal object.
  5. Save it: from /workflows, press s, Tab to pick .claude/workflows/ (project) vs ~/.claude/workflows/ (personal), and save it as a /<name>. Run it again next session to confirm it reruns the same orchestration.
  6. Reflect on caps: in the saved script, identify where agents are spawned and reason about how many the run could spawn — could it approach the 1,000 cap? Where's the 16-concurrent barrier (parallel) vs. a pipeline?

Deliverable: a short note answering (a) where the intermediate results lived in your runs and why that matters; (b) one observation from reading the raw script that you couldn't have gotten by memorizing an API; and (c) the smallest realistic task in YOUR codebase that would justify a workflow over plain subagents — and why.

Key takeaways

  1. 1A dynamic workflow is a JavaScript orchestration script that CLAUDE writes and a SEPARATE runtime executes in the background; intermediate results live in script variables, so only the final verified answer enters your session. Research preview, requires v2.1.154+.
  2. 2Among the four paradigms, workflows are the only one where the plan lives in code and intermediate state stays out of the context window — which is why they scale to dozens-to-hundreds of agents (vs. agent teams' shared mailbox or a subagent's single summary).
  3. 3Trigger three ways: the `ultracode` keyword (Option+W / Alt+W dismisses the highlight), a saved /<name> command, or /effort ultracode (auto-decide). /deep-research is the bundled fan-out-search, cross-check, vote, cited-report workflow.
  4. 4The scripting-API names vary by version (spawn vs agent/parallel/pipeline) — learn the concepts and READ the generated script. An agent call returns a STRING; the literal `export const meta = {...}` block must have no function calls, variables, or dynamic construction.
  5. 5Data flow is string concatenation / JSON only — no message bus, no shared state, no agent-to-agent talk; the script parses outputs. Caps: 16 concurrent, 1,000 total; no mid-run input; no script-level filesystem/shell; no nested workflows.
  6. 6Monitor and control with /workflows (p=pause/resume, x=stop, r=restart agent, s=save). Resume only within the same session. Cost is substantial — test on one directory first; disable via /config, disableWorkflows, or CLAUDE_CODE_DISABLE_WORKFLOWS=1.

Quiz

Lock in what you learned

Check your understanding

0 / 4 answered

1.What is the single defining property of a dynamic workflow that lets one prompt fan out to hundreds of subagents without overwhelming your session?

2.Which statement about the workflow scripting primitives and the meta block is accurate?

3.A teammate wants Claude to auto-decide when a task is big enough to warrant a workflow, for every substantive task this session. Which trigger fits, and what's a true constraint to warn them about?

4.You started an expensive workflow run, paused it with `p` in /workflows, then quit Claude Code for the day. You reopen Claude Code the next morning. What happens, and what's the right cost-discipline habit?

Go deeper

Hand-picked sources to keep learning