Claude Code Dynamic Workflows: What They Do & Agent Count
In this article
Claude Code dynamic workflows let you define multi-step AI agent processes that run in your terminal, and the number of agents they run depends entirely on how you structure the workflow—typically between 1 and 10 subagents at a time, with no hard cap enforced by the tool itself. You enter a task description, the workflow breaks it into steps, and Claude Code spawns specialized subagents to handle each step, then coordinates their outputs to produce a final result.
sel mode | Workflow mode | Sequential=1, Parallel=2 | 1 in agents | Number of subagents | - | 3 | 1 in steps | Steps per agent | - | 5 | 1 out total | Total agent runs | - | agents * steps | 0 out duration | Est. duration (min) | min | agents * steps * 2 | 0
Formula
The calculator estimates the total number of agent runs and the approximate time a dynamic workflow will take. The core formula is:
Total agent runs = (number of subagents) × (steps per agent)
Estimated duration (minutes) = total agent runs × 2 minutes per run (an average for a typical coding task).
- mode – whether agents run sequentially (one after another) or in parallel (simultaneously).
- agents – how many subagents you configure in the workflow.
- steps – how many discrete actions each subagent performs.
- total – the count of individual agent executions.
- duration – a rough time estimate based on 2 minutes per run.
Worked Example
Using the default values: mode = Sequential, agents = 3, steps = 5.
Total agent runs = 3 × 5 = 15 runs.
Estimated duration = 15 × 2 = 30 minutes.
So a workflow with 3 subagents, each doing 5 steps, would execute 15 agent runs and take roughly 30 minutes in sequential mode. In parallel mode, the wall-clock time would be shorter because agents run simultaneously, but the total runs remain 15.
What Are Dynamic Workflows?
Dynamic workflows in Claude Code are a feature that lets you define a multi-step process using a special .claude-workflow file (or a JSON/YAML configuration). Unlike a static script, the workflow adapts based on the task: it can spawn subagents, delegate subtasks, and change the sequence of steps depending on intermediate results. This is useful for complex coding tasks like refactoring a large codebase, writing tests, or generating documentation across multiple files.
The key difference from a regular Claude Code session is that a workflow explicitly orchestrates multiple agents, each with a focused role (e.g., “code reviewer,” “test writer,” “bug fixer”). The main agent (the coordinator) manages the flow and aggregates results.
How Many Agents Can a Workflow Run?
There is no fixed limit published by Anthropic. The number of agents is determined by your workflow definition. You can set it to run a single agent, or you can define a “swarm” of dozens. However, practical limits come from:
- API rate limits – your Anthropic API key has a requests-per-minute limit.
- Context window – each agent uses tokens; too many agents may exceed the context limit.
- Cost – more agents mean more token usage, so higher cost.
- Performance – running 50 agents in parallel may slow down your machine or hit concurrency caps.
In practice, most users run between 2 and 10 subagents per workflow. Anthropic’s own examples often show 3–5 agents. The tool does not enforce a hard cap, but you should stay within your API tier limits.
How to Choose the Right Number of Agents
Choosing the agent count depends on your task complexity and your API plan. Here are factors to consider:
- Task granularity – If the task can be split into independent subtasks (e.g., “fix bugs in module A” and “write tests for module B”), use more agents in parallel.
- Dependencies – If steps depend on each other (e.g., “refactor code, then update docs”), use sequential mode with fewer agents.
- API limits – Check your plan’s rate limits. If you have a low limit, keep agents low (1–3).
- Budget – Each agent run consumes tokens. Estimate cost using the token count per step.
A good rule of thumb: start with 2–3 agents for a medium task, and scale up only if you need parallel processing.
Common Problems and Misconceptions
One common misconception is that more agents always mean faster results. In reality, coordination overhead can slow things down, especially if agents need to share context. Another issue is that agents may produce conflicting changes if they work on the same files in parallel. To avoid this, use separate file paths or merge carefully.
Another problem: users often forget that dynamic workflows require a well-defined .claude-workflow file. If the file is malformed, the workflow fails silently. Always validate your JSON/YAML syntax.
Finally, some users expect agents to run indefinitely, but each agent has a finite context window. Long workflows may need to checkpoint and resume.
Dynamic Workflows vs. Static Scripts
Static scripts (like a shell script) run the same commands every time. Dynamic workflows adapt: they can decide to skip steps, add new ones, or change the agent’s role based on the task. For example, a static script might always run “lint” then “test,” but a dynamic workflow could detect that the code has no tests and instead generate them first.
This adaptability makes dynamic workflows better for open-ended tasks like “improve code quality” where the exact steps aren’t known upfront.
Cost and Performance Considerations
Each agent run consumes tokens for input and output. The cost depends on the model (e.g., Claude Opus vs. Sonnet) and the length of the context. For a typical refactoring task with 3 agents and 5 steps, you might use around 100k tokens, costing a few dollars. To reduce cost:
- Use a smaller model for simple subtasks.
- Limit the context by giving each agent only the relevant files.
- Use parallel mode to reduce wall-clock time, but note that token usage is the same.
Performance-wise, parallel agents can speed up execution, but they may also hit API concurrency limits. Check your plan’s “requests per minute” and adjust accordingly.
Frequently Asked Questions
Can I run more than 10 agents in a dynamic workflow?
Yes, technically you can define as many agents as you want, but practical limits like API rate limits, context window, and cost will likely cap you well below 100. For most tasks, 2–5 agents are sufficient.
Do agents run in parallel by default?
No, the default is sequential. You must explicitly set parallel: true in your workflow file to run agents concurrently. Parallel mode is faster but may cause file conflicts if agents edit the same files.
How do I define a dynamic workflow?
Create a file named .claude-workflow in your project root. Use YAML or JSON to define the workflow steps, agents, and their roles. For example, you can specify a list of agents with their prompts and the order of execution.
What happens if one agent fails?
By default, the workflow stops and reports the error. You can configure retry logic or set continue_on_error: true to let the workflow proceed with the remaining agents.
Is there a difference between subagents and dynamic workflow agents?
Subagents are a general feature in Claude Code for delegating a single task. Dynamic workflow agents are specifically defined within a workflow file and are orchestrated by the main agent. They are essentially subagents with a defined sequence.
Can I use dynamic workflows for non-coding tasks?
Yes, you can use them for any multi-step task that benefits from AI assistance, such as research, content generation, or data analysis. The workflow file is just a set of instructions for the agents.