Skip to main content
MindStudio
Pricing
Blog About
My Workspace

How to Use Claude Code Dynamic Workflows: Spawning Hundreds of Parallel Sub-Agents

Claude Code's dynamic workflows spawn parallel sub-agents for large tasks like code migrations. Learn how to trigger them, what they cost, and when to use them.

MindStudio Team RSS
How to Use Claude Code Dynamic Workflows: Spawning Hundreds of Parallel Sub-Agents

When One AI Agent Isn’t Enough

Running a single AI agent through a 50,000-line codebase is slow. Running 200 of them in parallel is a different problem entirely — and Claude Code’s dynamic workflows make it possible.

Multi-agent parallelism in Claude Code isn’t a niche feature. It’s becoming a standard approach for teams tackling large-scale tasks: migrating APIs, generating test suites, auditing dependencies, or refactoring legacy code across hundreds of files. The ability to spawn parallel sub-agents means work that would take hours sequentially can finish in minutes.

This guide covers exactly how Claude Code dynamic workflows operate, how to trigger and configure parallel sub-agents, what they actually cost, and where they make sense to deploy.


What Claude Code Dynamic Workflows Actually Are

Claude Code is Anthropic’s agentic coding tool — a command-line agent that can read files, run commands, write code, and call tools. It’s built to operate over long tasks autonomously, not just answer one-off questions.

Dynamic workflows extend this by letting an orchestrating agent — the top-level Claude instance — break a large task into subtasks and spin up independent sub-agents to handle each one. Those sub-agents run concurrently, each with their own context window, tool access, and token budget.

Think of it like this: the orchestrator figures out the plan, delegates chunks of work, collects the results, and synthesizes them. Sub-agents focus entirely on their assigned slice of the problem.

The Orchestrator-Subagent Model

At the core of Claude Code’s multi-agent system is a two-tier structure:

  • Orchestrator — The parent Claude instance that receives the high-level task, decomposes it, spawns sub-agents, monitors progress, and merges outputs.
  • Sub-agents — Independent Claude instances that each receive a focused task, execute it using available tools, and return results to the orchestrator.

Plans first. Then code.

PROJECTYOUR APP
SCREENS12
DB TABLES6
BUILT BYREMY
1280 px · TYP.
yourapp.msagent.ai
A · UI · FRONT END

Remy writes the spec, manages the build, and ships the app.

Each sub-agent is effectively a fresh Claude Code session. It doesn’t share memory or state with other sub-agents unless explicitly passed in the task prompt. This isolation is both a strength (clean context windows, no interference) and a constraint (you have to pass relevant context explicitly).

The mechanism Claude Code uses to spawn sub-agents is the Task tool — a built-in capability that lets the orchestrator create child agents with specific prompts and constraints.


How to Trigger Parallel Sub-Agents

Setting up Claude Code to spawn parallel sub-agents requires a few things: the right prompt structure for the orchestrator, the right use of headless mode, and an understanding of how parallelism actually executes.

Step 1: Run Claude Code in Headless Mode

Standard Claude Code runs interactively. For dynamic workflows, you want non-interactive (headless) operation so it can run unattended.

Use the -p flag:

claude -p "Migrate all API calls from v1 to v2 across the /src directory"

This runs Claude Code as a single command, produces output, and exits when done. Headless mode is what enables orchestrated, programmatic operation.

You can also pipe in context:

cat task_description.txt | claude -p --output-format json

The --output-format json flag is useful when you want structured output from sub-agents that the orchestrator can parse cleanly.

Step 2: Design the Orchestrator Prompt

The orchestrator prompt is where dynamic behavior lives. Your job is to write a prompt that instructs Claude to:

  1. Analyze the scope of the task
  2. Decide how to partition the work
  3. Spawn sub-agents for each partition
  4. Collect and reconcile results

A concrete example for a migration task:

You are orchestrating a large-scale migration of all fetch() calls to use the 
internal APIClient class. The codebase is in /src.

Steps:
1. List all files in /src that contain fetch( calls.
2. For each file, spawn a sub-agent tasked with rewriting only that file's 
   fetch() calls to use APIClient. Pass the full file path to each sub-agent.
3. Wait for all sub-agents to complete.
4. Verify no remaining fetch() calls exist in the modified files.
5. Report any files that could not be migrated and why.

The orchestrator reads this, discovers the files, then uses the Task tool to spawn individual agents per file — potentially dozens or hundreds of them.

Step 3: Configure Sub-Agent Scope

Each sub-agent inherits the tools available to Claude Code (file read/write, bash execution, etc.) but starts with a fresh context. You need to give it everything it needs in its task prompt.

A well-structured sub-agent prompt for the migration example above:

Migrate all fetch() calls in /src/services/userService.ts to use the 
APIClient class imported from @/lib/api-client.

Rules:
- Do not change any other code in the file.
- Preserve all existing error handling.
- If a fetch() call cannot be cleanly migrated, add a TODO comment and 
  explain why.
- Return a summary: total fetch() calls found, migrated, and skipped.

Scoped, explicit prompts produce far better results than vague ones. Sub-agents don’t have context from the broader task unless you include it.

Step 4: Control Concurrency

Claude Code doesn’t have a built-in GUI for controlling how many sub-agents run simultaneously — but you can manage concurrency in a few ways:

A free 1-hour Hermes workshop
The free Hermes Agent crash courseReserve your spot

Let the Task tool handle it. When the orchestrator spawns sub-agents using the Task tool, Claude manages concurrent execution internally. This works well for most use cases.

Use shell-level parallelism for more control. If you’re scripting orchestration externally:

# Run 10 sub-agents in parallel using xargs
ls src/services/*.ts | xargs -P 10 -I {} claude -p "Migrate fetch() calls in {}"

The -P 10 flag limits to 10 concurrent processes. Adjust based on your API rate limits and task complexity.

Use --max-turns to cap how long each sub-agent runs:

claude -p "Refactor auth logic in /src/auth/session.ts" --max-turns 20

This prevents runaway agents from consuming excessive tokens on a single file.


Real-World Use Cases for Parallel Sub-Agents

Dynamic workflows are overkill for small tasks. But for anything that involves processing many similar units of work — files, endpoints, modules, records — parallelism pays off significantly.

Large-Scale Code Migrations

This is the canonical use case. Moving from one framework, library, or API version to another means touching potentially hundreds of files. A single sequential agent works through them one by one. An orchestrator with parallel sub-agents assigns one agent per file (or per module), runs them all simultaneously, then reconciles conflicts.

Common migration tasks well-suited for this:

  • Converting CommonJS to ES modules
  • Upgrading from REST to GraphQL endpoints
  • Replacing a deprecated library with a modern alternative
  • Switching test frameworks (e.g., Jest to Vitest)

Parallel Test Generation

A sub-agent per service or module generates unit tests independently. Each agent focuses only on its assigned scope, which keeps context windows manageable and reduces cross-contamination between unrelated tests.

Codebase Auditing

Spawn agents to audit different sections of a codebase simultaneously — one per directory, one per feature domain, or one per file type. Useful for security audits, accessibility checks, or dependency analysis.

Documentation Generation

One sub-agent per module or component generates documentation independently. The orchestrator collects outputs and assembles them into a unified structure.

Data Processing at Scale

Claude Code agents can interact with databases, APIs, and file systems. For batch data transformation tasks — reformatting records, validating data, enriching entries — parallel sub-agents can each handle a chunk of the dataset.


What Parallel Sub-Agents Actually Cost

This is where teams often get surprised. Running 200 sub-agents in parallel doesn’t cost the same as running one agent 200 times in terms of real time, but it does cost the same in terms of tokens.

Token Costs Scale Linearly With Agents

Each sub-agent consumes tokens independently. If a single agent processing one file uses 10,000 input tokens and 2,000 output tokens, 100 agents processing 100 files will use roughly 1,000,000 input tokens and 200,000 output tokens.

At Claude’s current pricing (which varies by model tier), a large parallel workflow can easily cost $10–$50 for a substantial codebase. For very large codebases with hundreds of files, costs can run higher.

Factors That Drive Cost Up

  • Long context windows per agent — Agents processing large files consume more input tokens.
  • High tool call volume — Each bash command, file read, or file write is part of the token count.
  • Multi-turn agent sessions — If sub-agents run many turns to complete their tasks, token use multiplies.
  • Redundant context in prompts — Passing large shared context to every sub-agent is expensive. Pass only what each agent needs.

Strategies to Reduce Cost

Use the right model tier. Claude Haiku is significantly cheaper than Claude Opus or Sonnet and works well for structured, well-defined sub-tasks like file migrations. Reserve higher-tier models for the orchestrator.

Chunk intelligently. Instead of one agent per file, group related files together. Ten agents handling 10 files each is cheaper than 100 agents handling 1 file each, because you amortize orchestration overhead.

Set --max-turns limits. Unbounded agents on complex tasks can spiral. Cap turn counts to prevent runaway sessions.

Filter scope before spawning. Have the orchestrator filter relevant files first. Spawning 200 agents only to have 150 of them find no relevant code is wasteful.

Cache shared context externally. If every sub-agent needs the same large reference document (e.g., API spec), write it to a file once and have agents read it, rather than embedding it in every prompt.


Common Mistakes and Limitations

Forgetting That Sub-Agents Are Stateless

Sub-agents don’t share memory. If agent A discovers something important about the codebase, agent B won’t know unless you explicitly pass that information. Design orchestrator prompts to surface and redistribute findings.

Prompts That Are Too Vague

A sub-agent told to “improve” a file will interpret that broadly and expensively. Sub-agent prompts should specify exactly what to change, what not to change, and what output to return.

Race Conditions on Shared Files

If two sub-agents write to the same file, you’ll have a conflict. Partition work so each agent owns distinct files or distinct sections. The orchestrator should enforce this partitioning before spawning.

Ignoring Rate Limits

Spawning 500 agents simultaneously will hit API rate limits. If you’re scripting external parallelism, throttle concurrency to stay within your tier’s limits. The Task tool handles this more gracefully when used natively.

No Error Handling Strategy

Sub-agents fail. Files may be too complex, edge cases may arise, or token limits may be hit. Your orchestrator needs to collect failures, not just successes, and decide whether to retry, skip, or escalate.

Treating This as a Free Speedup

Parallel sub-agents reduce wall-clock time but don’t reduce cost. If budget is a concern, parallel execution doesn’t help — and may actually increase costs due to orchestration overhead. Sequential execution is cheaper when speed isn’t the priority.


Where MindStudio Fits Into Multi-Agent Orchestration

If you’re building on top of Claude Code’s sub-agent capabilities, there’s an infrastructure layer that gets complicated fast: managing retries, handling errors gracefully, passing results between agents, triggering workflows on completion, and integrating outputs with downstream systems (Slack notifications, database writes, GitHub PRs, etc.).

This is where MindStudio’s Agent Skills Plugin makes a practical difference for teams already using Claude Code.

The plugin (@mindstudio-ai/agent) is an npm SDK that lets Claude Code agents — or any custom agent — call 120+ typed capabilities as simple method calls. Instead of writing custom glue code to send a Slack message when an orchestration job completes, or to write results to a Google Sheet, or to trigger a downstream process, your agent calls agent.sendSlackMessage() or agent.runWorkflow() directly.

In 60 minutes, you'll know Hermes
The free Hermes Agent crash courseReserve your spot

For parallel sub-agent workflows specifically, this matters at the boundary between code and business process. The sub-agents do the technical work. The integration layer handles what happens after:

  • Sending a summary report to a Slack channel when all sub-agents finish
  • Creating a GitHub issue for any files that couldn’t be migrated
  • Logging results to a database for tracking
  • Triggering a code review workflow in a connected tool

The plugin handles auth, rate limiting, and retries so the agent logic stays focused on reasoning, not plumbing. You can try it at mindstudio.ai.

If you’re not running Claude Code directly but want similar multi-step, multi-agent capabilities without managing the CLI and infrastructure yourself, MindStudio’s visual no-code builder lets you build equivalent orchestration workflows with 1,000+ pre-built integrations and 200+ AI models — including Claude — without writing code.


FAQ

How many sub-agents can Claude Code spawn in parallel?

There’s no hard limit imposed by Claude Code itself on how many sub-agents an orchestrator can spawn. Practical limits come from API rate limits (which vary by tier), system memory, and the cost of running large numbers of concurrent agents. Most teams working on substantial codebases operate in the range of 10–100 concurrent agents. Spawning hundreds simultaneously is possible but requires careful rate limit management.

Do sub-agents share memory or context with each other?

No. Each sub-agent runs as an independent session with its own context window. Sub-agents can’t see what other sub-agents are doing or have done unless the orchestrator explicitly passes that information in their prompts. This means the orchestrator is responsible for aggregating results and redistributing relevant findings.

Can sub-agents call other sub-agents (nested orchestration)?

Yes. A sub-agent can itself act as an orchestrator and spawn its own child agents. This enables hierarchical task decomposition where a top-level orchestrator delegates to mid-level coordinators, which delegate to leaf-level workers. Nested orchestration increases flexibility but also increases complexity and cost. Use it when tasks have natural hierarchical structure.

What’s the difference between Claude Code’s Task tool and running shell-level parallelism?

The Task tool is Claude Code’s native mechanism for spawning sub-agents from within an orchestrator agent. It’s managed by Claude and works seamlessly within an agentic session. Shell-level parallelism (using xargs, parallel, or similar) runs independent Claude Code processes externally, which gives you more control over concurrency but requires more scripting. For most use cases, the Task tool is simpler. Shell-level parallelism is useful when you’re orchestrating from outside Claude Code itself.

How do I handle sub-agent failures?

Design your orchestrator to collect both successes and failures. Each sub-agent should return a structured status (e.g., “migrated,” “skipped,” “failed”) along with its results. The orchestrator aggregates these, retries failed agents if appropriate, and surfaces a final report. Using --output-format json makes parsing sub-agent outputs programmatically much easier.

Is there a cost-effective way to test dynamic workflows before running them at full scale?

Yes. Start with a small subset of the target work — say, 5–10 files instead of 500. Verify the orchestrator decomposes the task correctly, that sub-agent prompts produce the expected outputs, and that error handling works. Once the workflow behaves correctly at small scale, expand. Running test batches first prevents expensive failures on large jobs.


Key Takeaways

  • Claude Code dynamic workflows use an orchestrator-subagent model where a parent agent decomposes tasks and spawns independent child agents to handle each piece in parallel.
  • Sub-agents run via the Task tool, each with their own context window and tool access — but no shared state between agents.
  • Headless mode (claude -p), scoped prompts, and --max-turns limits are the primary controls for configuring parallel workflows.
  • Token costs scale linearly with the number of sub-agents. Choosing the right model tier per task and filtering scope before spawning are the most effective cost controls.
  • The biggest failure modes are vague sub-agent prompts, race conditions on shared files, and no error handling strategy.
  • For teams who want similar orchestration without managing the infrastructure, or who need to connect multi-agent outputs to business tools, MindStudio offers a faster path — either through the Agent Skills Plugin for Claude Code or through its visual workflow builder.

Presented by MindStudio

No spam. Unsubscribe anytime.