Learn Claude Code: Autonomous Workflows Dynamic Workflows: Scripted Multi-Agent Orchestration

Dynamic Workflows: Scripted Multi-Agent Orchestration

Intermediate 🕐 14 min Lesson 9 of 13
What you'll learn
  • Explain when a Dynamic Workflow is the right choice compared to subagents, skills, and agent teams
  • Trigger a workflow using the ultracode keyword and monitor its progress in the /workflows view
  • Apply the key constraints of the workflow runtime — agent counts, concurrency limits, and resumability — to plan cost-effective large-scale tasks

The Context Window Problem at Scale

Subagents solve the delegation problem for tasks a single agent can hold in context. But some tasks are inherently larger than any context window. Auditing 500 route handlers for missing authentication checks. Migrating every component from one CSS library to another. Running a research question across dozens of independent sources and cross-checking the findings. These tasks don't just need delegation — they need a plan that lives outside of any single conversation.

Dynamic Workflows are Claude Code's solution. Instead of Claude holding the orchestration plan in its context, a JavaScript script holds the plan. The script runs in a background runtime, fires off subagents, collects their results in script variables, and produces a final output. Claude's context window sees only the question and the answer — not the hundreds of intermediate steps in between.

Workflows vs Other Multi-Agent Tools

Claude Code has four tools for multi-step work. Understanding what each one is designed for makes the choice clear:

Subagents
Skills
Agent teams
Workflows
Who holds the plan
Claude, turn by turn
Claude, following the prompt
The lead agent
The script
Where results live
Claude's context
Claude's context
Shared task list
Script variables
Scale
A few tasks per turn
Same as subagents
A handful of peers
Hundreds of agents per run
Interruption
Restarts the turn
Restarts the turn
Teammates keep running
Resumable in same session

Use a workflow when the task needs more agents than one conversation can coordinate, when you want the orchestration codified as a script you can read and rerun, or when a repeatable quality pattern — like adversarial cross-checking — needs to be built into the orchestration rather than trusted to Claude's judgment each time.

The Bundled /deep-research Workflow

Claude Code ships with /deep-research as a built-in workflow. It's the fastest way to see what workflows do:

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

/deep-research fans out web searches across several angles of the question, fetches and cross-checks the sources it finds, votes on each claim, and returns a cited report with claims that didn't survive cross-checking filtered out. The session stays responsive while agents work in the background. When the run finishes, the report lands in your conversation with sources cited.

This pattern — fan out, cross-check, synthesize — is the template for most research workflows. You can have Claude write a narrower version for any specific research question, then save and reuse it.

Triggering a Workflow

To trigger a workflow for your own task without changing your session's effort level, include the keyword ultracode anywhere in your prompt:

ultracode: audit every route handler under src/routes/ for missing auth checks

You can also use natural language: "use a workflow to..." or "run a workflow for..." both trigger Claude to write a workflow script instead of working through the task conversationally. Claude Code highlights the trigger keyword in your input. Press Option+W (macOS) or Alt+W (Windows/Linux) to dismiss the highlight if you didn't intend a workflow.

Before the run starts, Claude Code asks whether to allow the workflow. You'll see the planned phases and can choose to proceed, view the raw script first, or cancel. Select Yes, and don't ask again for <name> in <path> to skip this prompt for that workflow in this project on future runs.

The /workflows Progress View

Workflows run in the background. Run /workflows at any time to list running and completed workflows, then select one and press Enter to open its progress view. The view shows each phase with agent counts, token totals, and elapsed time.

Keyboard controls in the progress view:

  • ↑ / ↓ — select a phase or agent
  • Enter or → — drill into the selected phase, then into an agent to read its prompt, recent tool calls, and result
  • Esc — back out one level
  • p — pause or resume the run
  • x — stop the selected agent, or stop the whole workflow when focus is on the run
  • r — restart the selected running agent
  • s — save the run's script as a named command
  • f — filter the agent list by status

A one-line progress summary also appears in the task panel below the input box. Press the down arrow to focus it, then Enter to expand without running /workflows.

Capabilities and Constraints

The workflow runtime enforces a few key limits:

  • Up to 16 agents run concurrently, fewer on machines with limited CPU cores. This bounds local resource use — the runtime doesn't spin up 500 agents simultaneously even for a 500-file migration.
  • Up to 1,000 agents total per run. Prevents runaway loops. Plan your workflow to stay under this ceiling.
  • No direct filesystem or shell access from the workflow script itself. The script coordinates agents; the agents do the reading, writing, and running. The script just holds variables and calls agent() and pipeline().
  • No mid-run user input. Only permission prompts can pause a run. For sign-off between stages, design each stage as its own workflow rather than one long pipeline.

Workflows are resumable within the same session. If you stop a run, completed agents return their cached results and only the remaining phases run live. Exiting Claude Code while a workflow runs starts it fresh in the next session.

Key takeaways
  • Dynamic Workflows move the orchestration plan into code — unlike subagents where Claude decides turn by turn, the workflow script holds the loop and branching so thousands of intermediate results stay in variables, not in Claude's context window
  • /deep-research is the fastest entry point — run it on any question to see the fan-out, cross-checking, and cited synthesis that workflows enable, and use the /workflows view to understand its phase structure
  • The ultracode keyword triggers workflow generation — including it in any prompt asks Claude to write a script for the task instead of working through it conversationally, without changing the session's overall effort level
  • Up to 16 agents run concurrently with a hard cap of 1,000 per run — the /workflows progress view shows token spend per phase in real time so you can stop a run before it overruns your budget
  • Workflows are resumable within the same session — stopped runs retain completed agent results and only re-run the remaining phases, which makes it safe to pause and inspect large runs without losing work