The Workflow Tool: Scripted Multi-Agent Orchestration
Use Claude Code dynamic workflows to put repeatable JavaScript control flow around many subagents, with approval, progress, limits, and same-session resume.
What You’ll Learn
A dynamic workflow is a JavaScript script that coordinates subagents while a dedicated runtime handles the control flow in the background. Use it when the loop, branching, or fan-out should be readable and repeatable instead of living only in the model’s conversation context.
By the end, you’ll know:
- When to use a workflow instead of a subagent, skill, or agent team
- How to launch, inspect, approve, save, and rerun a workflow
- The documented shape of
meta,agent(),pipeline(),parallel(),phase(), andargs - The runtime’s real limits and its resume rules
- Which failure and budget assumptions should stay out of your scripts
Choose the Right Coordination Layer
| Mechanism | Who holds the next step? | Best fit |
|---|---|---|
| Subagent | Claude, turn by turn | A few delegated tasks whose results return to one context |
| Skill | Claude following stored instructions | A reusable method or domain procedure |
| Agent team | A lead supervising long-running peers | Teammates that share tasks and message one another |
| Workflow | The script runtime | Large, repeatable loops, fan-out, branching, and cross-checking |
Workflows are not automatically better. For a single lookup or a tightly coupled edit, one agent has less overhead. Reach for a workflow when code is genuinely better at the bookkeeping.
Dynamic workflows require Claude Code 2.1.154 or later. They are available on all paid plans, with Anthropic API access, and on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry. They are on by default except on Pro, where you turn them on in the Dynamic workflows row of /config (it writes the enableWorkflows setting). An organization can turn them off with disableWorkflows, and CLAUDE_CODE_DISABLE_WORKFLOWS=1 turns them off for one session.
Three Ways to Run One
Start with the bundled workflow
/deep-research What changed in the Node.js permission model between v20 and v22?
/deep-research fans out research, cross-checks claims, and returns one cited report.
Ask for a workflow
use a workflow to audit every route handler under src/routes/ for missing authentication checks, then adversarially verify each finding
Including the keyword ultracode in a prompt is another explicit one-task trigger; it does not change the session’s effort level. The keyword counts only in a prompt you type yourself, not in a -p prompt, a scheduled task prompt, or a relayed webhook payload or pull request comment. To type the word without starting a workflow, turn off Ultracode keyword trigger in /config (workflowKeywordTriggerEnabled: false).
Let ultracode decide
/effort ultracode
Ultracode is a Claude Code setting, not an effort level: with it on, Claude plans a workflow for each substantive task at whichever effort level the session runs at. Since 2.1.284 it is a separate toggle: /effort ultracode turns it on for the session, /effort ultracode off turns it off, Tab flips it in the /effort slider, and "ultracode": true in settings starts every session with it on. Only claude --effort ultracode also sets the effort level to xhigh; before 2.1.284, turning ultracode on always forced xhigh. It requires dynamic workflows and a model that supports xhigh, and it makes every substantive request use more tokens. See Session 26 for how it relates to effort levels.
What the Saved Script Looks Like
Claude normally writes the script for you. A small saved workflow has this documented shape:
export const meta = {
name: 'audit-routes',
description: 'Audit every route handler for missing auth checks',
}
const found = await agent('List every .ts file under src/routes/.', {
schema: {
type: 'object',
required: ['files'],
properties: {
files: { type: 'array', items: { type: 'string' } },
},
},
})
const audits = await pipeline(found.files, file =>
agent(`Audit ${file} for missing authentication checks.`, { label: file }),
)
return audits.filter(Boolean)
The script starts with a literal meta export and uses plain JavaScript with top-level await. Keep export const meta as the first statement and a plain object literal with a name and a description.
agent()starts one subagent.pipeline()runs work for each item in a list.parallel()runs independent functions concurrently and waits for the group.phase()groups the agents that follow under a title in the progress view; ifmeta.phaseslists titles, each must match thephase()title exactly.argscontains structured input passed to a saved workflow; it isundefinedwhen omitted.
A few result contracts are documented, and the example depends on one of them. An agent() call resolves to null if you stop it mid-run or it hits an unrecoverable API error. Inside pipeline() or parallel(), an agent that stalls on every attempt also leaves null; awaited directly, it ends the run with an error. pipeline() keeps those null slots, hence .filter(Boolean). With a schema, the agent returns JSON, and a call whose output still fails validation after five attempts fails. Inside the script, Date.now(), Math.random(), and a no-argument new Date() throw, and import() is rejected, so a relaunched run repeats the same agent() calls. For the Workflow tool’s own inputs and outputs, the Agent SDK reference is the source of truth. Do not invent a budget or exception contract beyond what the docs state.
Approval and Permissions
Before an interactive run, Claude Code can show the planned phases and these choices:
- Yes, run it: start the run;
- Yes, and don’t ask again: skip this prompt for that workflow in this project from now on, offered only when you run a bundled, saved, or plugin workflow by name, not for a script Claude just wrote;
- View raw script: read the script first; or
- No: cancel.
Whether you see the prompt depends on permission mode. Auto mode asks only on the first launch, and not at all while ultracode is on. Manual and accept-edits modes ask on every run unless you chose don’t ask again. Bypass permissions mode starts the run immediately. claude -p and the Agent SDK never show the prompt; they evaluate the Workflow call like any other tool call, so allow it with a Workflow or Workflow(<name>) rule, auto mode, a PreToolUse hook, or your host’s approval.
The agents a workflow spawns use your permission rules and pick their permission mode the same way other subagents do; by default, that is the main conversation’s mode. Calls outside your allow rules can still prompt during a run, so add the tools the agents need before a long one. A workflow cannot stop mid-run to ask an ordinary business question; split human sign-off points into separate workflows.
Watch, Pause, and Save
Run /workflows to inspect active and completed runs. The view shows each phase with its agent counts, elapsed time, and per-agent token usage, and an agent’s detail shows its prompt, recent tool calls, and result. In the view, p pauses or resumes the run, x stops the selected agent or the whole run, r restarts a running agent, and s saves the script.
Saved locations become slash commands:
.claude/workflows/for a project workflow shared through the repository~/.claude/workflows/for a personal workflow available across projects
A saved script reads invocation input from args, so one orchestration can work on different paths, issues, or research questions without editing its source.
To change a saved script by hand, first run the bundled /workflow-authoring skill (2.1.248+) so Claude loads the script-writing reference it works from. After editing, run /reload-skills and invoke /<name> again to use the new version.
Runtime Boundaries
The documented constraints are intentionally concrete:
| Boundary | Current behavior |
|---|---|
| Script access | No direct filesystem or shell access and no module loading (import() fails); agents use tools |
| Mid-run input | No ordinary user input; a run pauses only for agent permission prompts and, from 2.1.271, a usage-limit wait |
| Concurrency | Up to 16 agents by default, fewer on limited CPUs; CLAUDE_CODE_WORKFLOW_MAX_CONCURRENT_AGENTS (1–256, 2.1.269+) changes the cap |
| Fan-out size | Up to 4,096 items in one parallel() or pipeline() call |
| Total workers | 1,000 agents per run |
| Leaving the session | Backgrounding the session carries the run along; after a normal exit, a session resumed with claude --resume can replay saved results; a fresh session starts over |
Resume a paused run with p in /workflows; for a stopped run, ask Claude to relaunch it. A relaunch replays agents in start order: completed agents return their saved results, agents that were still running start over, and a failed agent, or the first agent whose prompt changed because you edited the script, runs again together with every agent started after it. (Before 2.1.305, completed pipeline() and parallel() agents could also rerun.) A smaller-grained fan-out therefore preserves more useful progress than one very long worker.
Cost and Scale
Workflows can consume substantially more tokens than a single conversation. Before a large run:
- rehearse on one directory or a small sample;
- watch token use in
/workflows; - stop the run if its evidence is no longer improving; and
- choose a size guideline if you want Claude to aim smaller:
small(fewer than 5 agents),medium(fewer than 10),large(fewer than 50), orunrestricted, from the Dynamic workflow size row in/configor theworkflowSizeGuidelinesetting.
The guideline is advice to Claude, not enforcement. It defaults to medium, or small on Pro from 2.1.271. Separately, when a run schedules more than 25 agents (or the agent count of a guideline you chose) or its projected tokens pass 1.5 million, its progress line shows a Large workflow warning. That warning is also advisory and is suppressed when ultracode is on because the session already opted into large runs. Workflow agents pick their model the same way subagents do, so check /model before a large run or ask for a smaller model on routine stages.
Practical Design Rules
- Fan out only work that is truly independent.
- Put cross-item deduplication or ranking after the relevant results exist.
- Ask agents for compact, structured evidence rather than full transcripts.
- State a stop condition in the task: a passing check, two dry rounds, or no further progress.
- Log sampling, skipped work, and unresolved claims in the final report.
- Use separate stages when a human decision is required between them.
Key Insight
A workflow moves coordination state out of the conversation and into code. The model still supplies judgment inside each agent, but loops, fan-out, and intermediate values become inspectable and reusable. That makes orchestration easier to audit without pretending every internal behavior is a guaranteed API contract.
Next Session
Session 28 turns these mechanics into orchestration quality patterns: independent search, adversarial verification, explicit stopping, and auditable evidence.