To run a lot of subagents in parallel in Claude Code, you ask for a dynamic workflow. Claude writes a JavaScript script that spawns and coordinates the subagents. A runtime executes it in the background and only the final answer comes back to your conversation. Fan-out is the pattern of starting one agent per file or per question and then collecting the results. Workflows have handled it since v2.1.154.
If subagents are new to you, start with how subagents work in Claude Code. For a single side task that needs your current conversation, a fork is enough.
How do I start a workflow in Claude Code?
Put the keyword ultracode in your prompt. Claude Code highlights it, and Claude writes a workflow script for the task instead of working through it turn by turn.
ultracode: audit every API endpoint under src/routes/ for missing auth checks
Asking in plain words, like âuse a workflowâ, counts as the same opt-in. The keyword does nothing in a prompt passed with claude -p.
If youâd rather let Claude decide when a task deserves a workflow, turn on ultracode for the session.
/effort ultracode
/effort ultracode off
Since v2.1.284, ultracode is its own toggle in /effort and stays on at any effort level. One request can then turn into several workflows in a row, so keep it for big sessions. On a Pro plan, turn on the Dynamic workflows row in /config first.
What does the workflow script look like?
You donât write it yourself. The official docs show a small saved one:
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)
agent() spawns one subagent and pipeline() runs one per item in a list. parallel() runs a set of agent tasks at once and waits for all of them. Intermediate results live in script variables, so your context only receives the final answer. A stopped agent resolves to null, which is why the script ends with .filter(Boolean).
How do I watch and stop a run with /workflows?
/workflows lists running and finished runs. Open one to see its progress phase by phase, with the agent count for each.
| Key | Action |
|---|
Enter | Drill into a phase, then into an agentâs detail |
p | Pause or resume the run |
x | Stop the selected agent, or the whole workflow when the run is selected |
s | Save the runâs script as a command |
A saved script lands in .claude/workflows/ (the project) or ~/.claude/workflows/ (all your projects), and runs later as /<name>.
How many agents run at the same time?
Claude aims for an agent count set by a size guideline, which works as advice: small (fewer than 5), medium (fewer than 10), large (fewer than 50) or unrestricted. The default is medium. Since v2.1.271, Pro plans default to small, and medium dropped from 15 to 10 agents.
/config workflowSizeGuideline=small
At run time, a workflow executes up to 16 agents at once, fewer on machines with fewer CPUs. Since v2.1.269 you can set that limit anywhere from 1 to 256:
export CLAUDE_CODE_WORKFLOW_MAX_CONCURRENT_AGENTS=32
A run is capped at 1,000 agents in total. CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS (default 20) only caps subagents spawned through the Agent tool and doesnât apply to workflow agents.
How much does a fan-out cost?
Each agent spends its own tokens, and all of it counts toward your planâs limits. Past 25 agents or a projected 1.5 million tokens, the progress line shows a Large workflow warning. If you picked a size guideline yourself, its agent count replaces the 25-agent threshold, and sessions with ultracode on donât show the warning. Try the workflow on one directory first and watch per-agent token usage in /workflows, where you can stop the run at any time.
Since v2.1.296, CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL runs every workflow agent on one model while your other subagents keep theirs. The prompt cache helps as well. Since v2.1.229, when sibling agents share the same prefix, Claude Code holds back all but the first for up to 5 seconds, until the first oneâs response begins, so the rest read its cache. CLAUDE_CODE_WORKFLOW_PREFIX_STAGGER_MS=0 turns the hold off.
If you hit your usage limit, the run pauses and picks up again on its own once the limit resets (v2.1.271). At a minimum, that needs an interactive session signed in with a claude.ai subscription.
When is a workflow worth it?
Reach for one when the same step has to run across many items, like auditing every route or migrating a folder of components. It also pays off when you want independent agents to check each otherâs findings before anything gets reported.
Skip it for a task that fits in one conversation, since the extra agents only add cost. A run takes no input from you once it starts, so if you need to sign off between stages, run each stage as its own workflow.
How do I turn workflows off?
Switch off the Dynamic workflows row in /config, or add the key to ~/.claude/settings.json. CLAUDE_CODE_DISABLE_WORKFLOWS=1 does the same.
{
"disableWorkflows": true
}
Ultracode then disappears from /effort, and a run already in progress keeps going.
Section 7.9 of module 7, Optimization and pro workflow shows the manual version of a fan-out, a loop of claude -p calls with a budget per session. To run several long sessions side by side, each in its own worktree, see module 14, tmux and agent teams.