Skip to content

Claude Code Dynamic Workflows: Orchestrate Many Subagents

Core Concept LearningAugust 18, 202614 min readUpdated October 17, 2026

Some tasks are bigger than one conversation can coordinate: audit every route handler for missing auth checks, migrate 500 files, cross-check a research question against many sources. Claude Code's dynamic workflows handle these by moving the plan into code. Claude writes a JavaScript script that spawns and coordinates subagents; a runtime executes it in the background while your session stays responsive; and you get one result at the end instead of a long turn-by-turn transcript. Because the orchestration is a script, you can read it, rerun it, and save it as a command.

Workflows are available on all paid plans, with Anthropic API access, and on Bedrock, Google Cloud, and Foundry (on Pro, turn them on in /config). This guide follows Anthropic's workflows documentation: when a workflow fits better than subagents or agent teams, running the bundled /deep-research, asking Claude for a workflow or turning on ultracode, approval and permissions, the script format, the runtime's limits, resuming, and cost. For the worker primitive underneath, see Claude Code Workflows for everyday subagent use, and Agent View for parallel full sessions.

Who holds the plan: Claude decides turn by turn for subagents and agent teams, while a workflow script holds the loop and results itself
Who holds the plan: Claude decides turn by turn for subagents and agent teams, while a workflow script holds the loop and results itself

When a workflow beats subagents or agent teams

Subagents, skills, agent teams, and workflows can all run multi-step tasks. The difference is who holds the plan:

  • With subagents and skills, Claude decides turn by turn what to spawn next, and every result lands in its context window. Good for a few delegated tasks per turn.
  • With agent teams, a lead agent supervises a handful of long-running peer sessions through a shared task list.
  • With a workflow, the script holds the loop, the branching, and the intermediate results in variables. Claude's context receives only the final answer. It scales to dozens or hundreds of agents per run, and a run can be resumed within the same session.

Putting the plan in code also lets a workflow apply a quality pattern, not just more agents: independent agents can adversarially review each other's findings before anything is reported, or a plan can be drafted from several angles and compared. Typical fits are codebase-wide audits, large migrations, research that needs sources cross-checked, and keep-fixing-until-the-check-passes loops.

Quick reference

  • If the task fits comfortably in one session's context, a workflow mostly adds cost. Use one when the number of items, not the difficulty, is the problem.
  • Workflows cannot take user input mid-run; for sign-off between stages, run each stage as its own workflow.
  • Agent teams are experimental and off by default; workflows are generally available on paid plans.

Remember this

Use a workflow when the work is many similar items or needs cross-checking, so the script, not Claude's context, carries the plan.

Run one: /deep-research, a request, or ultracode

The quickest way to see one is the bundled workflow:

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

It fans web searches out across several angles, fetches and cross-checks sources, votes on each claim, and returns a cited report with claims that did not survive cross-checking removed; claims the verifiers could not check are listed as unverified rather than refuted.

For your own task, ask in your own words or include the keyword ultracode:

1ultracode: audit every API endpoint under src/routes/ for missing auth checks2use a workflow to run npx tsc --noEmit and keep fixing the reported errors until3the type check passes or two rounds in a row make no progress

The keyword only starts a workflow from a prompt you type yourself; a prompt from -p, a scheduled task, or a relayed webhook or PR comment does not trigger it. To have Claude plan a workflow for every substantive task in a session, run /effort ultracode (or start with claude --effort ultracode). That uses noticeably more tokens per request, so turn it off with /effort ultracode off for routine work.

Runs execute in the background. /workflows opens the progress view: each phase with its agent counts, drill-down into each agent's prompt, tool calls, and result, and keys to pause (p), stop (x), restart an agent (r), or save the script (s).

A workflow run: ask for a workflow, approve the planned phases, watch it in /workflows, read one report, and save it as a command
A workflow run: ask for a workflow, approve the planned phases, watch it in /workflows, read one report, and save it as a command

Quick reference

  • Press Option+W (macOS) or Alt+W to dismiss an accidental ultracode highlight, or turn the keyword trigger off in /config.
  • A one-line progress summary also appears in the task panel below the input box.
  • /deep-research needs the WebSearch tool to be available.

Remember this

Try /deep-research first, then ask for a workflow by name or ultracode; watch and control it in /workflows.

Approval and permissions

Before a run starts, the CLI shows the planned phases with options to run it, run it and stop asking for that saved workflow in this project, view the raw script, or cancel. Ctrl+G opens the script in your editor. When you are prompted depends on the permission mode:

  • Auto: first launch only; consent is recorded in your user settings. Skipped entirely with ultracode on.
  • Manual, accept edits: every run, unless you chose "don't ask again" for that workflow.
  • Bypass permissions: no prompt.
  • claude -p and the Agent SDK: no prompt; the launch goes through normal permission evaluation, so you need an allow rule (Workflow for all, or Workflow(<name>) for one saved workflow), auto mode, bypass mode, a PreToolUse hook that returns allow, or a host approval callback.

The agents a workflow spawns get the same permission checks and sandboxing as any other tool call in the session; the script is coordination, not elevated access. To avoid a long run stalling on prompts, add the tools the agents need to your allow rules before starting. In auto mode, the prompt the script passes to agent() does not count as a request from you when the classifier reviews that subagent's actions, because Claude Code marks it as computed text.

Quick reference

  • Read the raw script on the first run of anything that edits files; it shows exactly how many agents will start and what each is told.
  • Claude can start a workflow only from a script file the session is allowed to read; add the directory with /add-dir if it lives elsewhere.
  • Organisations can disable workflows with disableWorkflows: true in managed settings or the admin toggle.

Remember this

Approve with the script in view, and pre-allow the tools agents need; the workflow never bypasses permissions.

What the script looks like, and saving it

A saved workflow is a .js file with a meta block and a plain JavaScript body using top-level await:

1export const meta = {2  name: 'audit-routes',3  description: 'Audit every route handler for missing auth checks',4}5 6const found = await agent('List every .ts file under src/routes/.', {7  schema: { type: 'object', required: ['files'],8            properties: { files: { type: 'array', items: { type: 'string' } } } },9})10 11const audits = await pipeline(found.files, file =>12  agent(`Audit ${file} for missing authentication checks.`, { label: file }),13)14 15return audits.filter(Boolean)

agent() spawns one subagent; with a schema, it returns JSON of that shape instead of prose (retried up to five times if validation fails). pipeline() runs one agent per item; parallel() runs a set of agent tasks at once. phase() groups agents under a title in the progress view, log() shows a message, and a saved workflow reads its input from the global args. An agent() call resolves to null if stopped or hit by an unrecoverable error, which is why the example filters the results.

To keep a run, open /workflows, select it, and press s. Save to .claude/workflows/ to share it with the repository, or ~/.claude/workflows/ for yourself; either way it runs as /<name>, for example Run /triage-issues on issues 1024, 1025, and 1030. Plugins can ship workflows too, namespaced as /plugin-name:workflow-name.

Quick reference

  • Keep export const meta the first statement and a plain object literal, or the command drops out of / autocomplete.
  • Run the /workflow-authoring skill before editing a saved script, then /reload-skills to pick up changes.
  • Every run also writes its script under the session's directory in ~/.claude/projects/, so you can read or diff what Claude wrote.

Remember this

A workflow is readable JavaScript over agent(), pipeline(), and parallel(); save good runs as /name commands.

Runtime rules, limits, and resuming

The script runs in an isolated environment with deterministic replay in mind: Date.now(), Math.random(), and argument-less new Date() throw inside it, so a relaunched run repeats the same agent() calls. Pass timestamps in through args instead.

That determinism is what makes runs resumable within the session. Pause and resume with p in /workflows; for a stopped run, ask Claude to relaunch it. On relaunch, completed agents return their saved results, but the first agent whose prompt differs (because you edited the script or an earlier result changed), any agent that failed, and every agent that started after either of those, run again. So a failure in the middle of a fan-out re-runs work that had finished after it.

Agents whose output stops arriving restart automatically from the same prompt, up to five times. If you hit your claude.ai usage limit, an interactive run pauses until the limit resets (when autoContinueAtUsageLimit is on and the reset is within 24 hours) rather than failing those agents.

Workflow runtime constraints from the docs
ConstraintValueWhy
Concurrent agents16 by default (fewer on small CPUs), 1-256 via CLAUDE_CODE_WORKFLOW_MAX_CONCURRENT_AGENTSBounds local resource use
Agents per run1,000Prevents runaway loops
Items per parallel() or pipeline()4,096; longer lists are rejectedNo silent truncation
User input mid-runNone; pauses only for permission prompts and usage-limit waitsRun stages as separate workflows
Filesystem or shell from the scriptNone; agents do the workThe script only coordinates
Module loadingimport() fails before the run startsPut library work in an agent's task
Runtime limits and cost controls for dynamic workflows
Runtime limits and cost controls for dynamic workflows

Quick reference

  • Backgrounding the session, or choosing Move to background and exit with agent view on, carries a running workflow over; exiting otherwise stops it.
  • In cloud sessions, completed agent results survive VM reclamation and are reused on relaunch.
  • Agents in a fan-out that share a model, tools, and working directory reuse each other's prompt cache, which lowers cost.

Remember this

Scripts are deterministic so runs can resume; edits and failures re-run everything that started after them.

Cost: test small, then scale

A workflow spawns many agents, so one run can use far more tokens than working through the task in conversation, and it counts toward your plan's usage and rate limits like everything else.

The docs' advice: run on a small slice first, such as one directory instead of the whole repository or a narrow question instead of a broad one, and watch per-agent token use in /workflows. You can stop a run there at any time, usually without losing completed work. Claude Code flags a run with more than 25 agents, or a projected total over 1.5 million tokens, with a Large workflow warning in the task panel; the warning is advisory and does not pause the run.

Two settings shape cost directly. The size guideline in /config (small under 5 agents, medium under 10, large under 50, or unrestricted) tells Claude how many agents to aim for; it defaults to medium, or small on Pro. And models: workflow agents run on your session's model unless the script names one, so check /model before a large run and ask Claude to use a smaller model for stages that do not need the strongest.

Quick reference

  • The size guideline is advice to Claude, not a cap; the runtime limits still apply regardless.
  • With ultracode on, the large-run warning does not appear, because turning it on already opts you in to big runs.
  • A workflow agent's prompt cache holds for five minutes by default; subagentPromptCacheTtl: "1h" keeps it longer at a higher write price.

Remember this

Pilot on a slice, set a size guideline, and use cheaper models for simple stages before running a workflow repo-wide.

Hands-on: an audit workflow on one directory

Use a repository with a test or lint command.

1. Run /deep-research on a question about a library you use, and read how the report marks verified and unverified claims. 2. Ask: "use a workflow to audit every file under src/<one-directory>/ for <one specific issue>, and adversarially verify each finding before reporting it". 3. At the approval prompt, choose View raw script and read how many agents it will start. 4. Run it and open /workflows; drill into one agent to see its prompt and result. Note the token use. 5. Press s and save it to .claude/workflows/. 6. Run the saved /<name> on a second directory.

Pass criterion: the audit's findings were verified before reporting, you know what one run cost, and the saved command reran the same orchestration elsewhere.

Quick reference

  • If the run stalls on permission prompts, add the needed tools to your allow rules and relaunch.
  • If the findings include false positives, ask Claude to tighten the verification stage in the script rather than the prompt.
  • Commit the saved workflow so teammates run the same audit.

Remember this

Read the script, run it small, measure cost, then save it as a command.

Key takeaway

Dynamic workflows let Claude Code coordinate dozens or hundreds of subagents by putting the plan in a JavaScript script instead of Claude's context: agent(), pipeline(), and parallel() fan out work, results live in variables, and you get one answer at the end. Start one with /deep-research, a request for a workflow, the ultracode keyword, or /effort ultracode; approve it with the script in view; watch and control it in /workflows; and save good runs as /name commands.

The rules are deliberate: no mid-run input, no shell access from the script itself, deterministic replay so runs resume, agents with the same permissions as any tool call, and caps of 16 concurrent and 1,000 total agents. Cost is the main risk, so pilot on a slice and set a size guideline. For how subagent usage counts against your plan, see Claude Code Costs.

Practice (40 min): complete the six steps above on one directory of your repository.

Share:

References

  1. Claude Code docs: Orchestrate subagents at scale with dynamic workflows — checked Oct 17, 2026
  2. Claude Code docs: Subagents — checked Oct 17, 2026
  3. Claude Code docs: Manage costs effectively — checked Oct 17, 2026
SH

Shoaib Hossain

Lead Author & Systems Architect

Software engineer and distributed systems architect specializing in backend scalability, cloud-native infrastructure, databases, and AI engineering workflows. Author and maintainer of Core Concept Learning.

Human-Engineered & Fact-CheckedOriginal Visual DiagramsEditorial Standards →Send Feedback

Related Articles

Timeline slides about Claude Code usually stack five gold dates and call it a rise. Dates are useful only when you ask w…

Read

A checkout timeout bug lands on your desk. Do you approve every agent edit, write a spec and verify, let the model YOLO …

Read

Claude Code has a dense vocabulary because it is more than a chat box beside your editor. The important terms describe w…

Read

Explore this topic

Keep learning

Follow a structured path or browse all courses to go deeper.