Dynamic workflows and ultracode: Claude orchestrating hundreds of subagents with a script
TL;DR
A dynamic workflow has Claude write a script that orchestrates dozens to hundreds of subagents for audits, migrations or research, with only the final result in context. Use the ultracode keyword per big task and start small, since it's token-heavy.
Ask Claude to "migrate 300 files from JavaScript to TypeScript" in one conversation and sooner or later the context fills up, Claude forgets which files are done, and the result is patchy. Delegating to subagents still has Claude orchestrating turn by turn, with every result flowing into the main context. Dynamic workflows change the approach: Claude writes a JavaScript script that orchestrates dozens to hundreds of subagents, a runtime runs it in the background, and Claude's context only receives the final result.
How is this different from subagents and agent teams?
| Subagents | Agent teams | Workflows | |
|---|---|---|---|
| Who decides the next step | Claude, turn by turn | The lead agent, turn by turn | The script |
| Intermediate results live in | Claude's context | A shared task list | Script variables |
| Scale | A few tasks per turn | A small long-running group | Dozens to hundreds of agents |
| Repeatable | The worker definition | The team definition | The whole orchestration |
Three ways to start
- A bundled workflow:
/deep-research <question>searches from several angles, cross-checks sources, drops claims that fail verification and returns a cited report. - Ask in your prompt: include the keyword
ultracodeor say "use a workflow". - Let Claude decide:
/effort ultracode, and Claude plans a workflow for every substantial task in the session.
ultracode: audit every API endpoint under src/routes/ for missing auth checks,
and adversarially verify each finding before reporting it
Track progress with /workflows: view each phase and agent, pause (p), stop (x), save the script as a command (s).
Prompt templates by job type
- Bulk audits: one agent per file, then cross-verify the findings.
- Fix until it passes: "run
tsc --noEmitand fix errors until it passes or two rounds in a row make no progress". - Parallel migrations: each file in its own isolated copy so edits don't collide.
- PR reviews: one reviewer per file, one agent that merges and ranks the findings.
What does a script look like?
export const meta = { name: 'audit-routes', description: 'Audit routes for auth' }
const found = await agent('List every .ts file under src/routes/.', { schema: {...} })
const audits = await pipeline(found.files, f => agent(`Audit ${f} for missing auth.`))
return audits.filter(Boolean)
agent() spawns one subagent, pipeline() runs one agent per item, parallel() runs tasks concurrently. Save it to .claude/workflows/ so the team can call it as /audit-routes.
Important limits
- By default at most 16 agents run concurrently; at most 1,000 agents per run.
- The script doesn't read/write files or run shell commands directly; only agents do, and they still go through permissions and the sandbox as usual.
- No input mid-run; if you need sign-off between stages, split them into separate workflows.
- A stopped run can be relaunched in the same session; completed agents return their saved results.
Cost: the point to be most careful about
- One run can use far more tokens than doing the work in conversation. Claude Code warns
Large workflowabove 25 agents or a projected 1.5 million tokens. - Ultracode on for the whole session means each request may become several workflows in a row and hit plan limits sooner. Turn it off with
/effort ultracode offwhen you go back to routine work. - Set a size guideline with
workflowSizeGuideline(small/medium/large) and trial on one folder before running across the whole repo.
How to apply it
- Dev: Use the
ultracodekeyword per big task (audits, migrations) rather than turning ultracode on for the session. - Tech Lead: Save workflows that work well to
.claude/workflows/; review scripts like code. - PM: Use
/deep-researchfor competitor research, asking for cited sources.
Sources & references
- Orchestrate subagents at scale with dynamic workflows — Claude Code Docs