PTENES
MODULE 3.5 · Track 3 · Model, cost, and orchestration

⚙️ Dynamic workflows

A workflow triggers dozens or hundreds of subagents in parallel— each with its own session, its own context, its own cost. Learning when this power is justified (and when it blows the budget) is what separates those who orchestrates with precision of someone who just calls agents at random.

7
Topics
~30
Minutes
Advanced
Level
Cost
Focus

Imagine you need to process 210 files at once: review code, extract metadata, generate reports. Doing this in sequence would take hours. With a dynamic workflow, the orchestrator launches one subagent per file — all at the same time, each in its own window — and you get the consolidated results in minutes. The diagram below shows what happens under the hood.

Orchestrator Task tool 1 session Subagent 1 arquivo_001.py Subagent 2 arquivo_002.py Subagent N arquivo_210.py ··· + 41 more competitors Result consolidated N reports → 1 up to 210 simultaneous subagents

Detailed content

1

🌐 What a dynamic workflow is

In Claude Code, a dynamic workflow is an orchestration where the the number of subagents isn't fixed in the prompt — it is determined at runtime by the orchestrator. The orchestrator receives the list of items, decides how many agents it will need, and launches them all via Task tool, one for each item.

What it is

An execution structure where the orchestrator dynamically generates N parallel tasks based on the input — whether it’s a list of files, a list of URLs, a list of chapters, or any iterable collection. Each item becomes an independent subagent.

Why learn

Understanding dynamic workflows is what lets you run jobs that would be impossible to complete sequentially within a single session. It’s the difference between processing 5 files and processing 200 — with the same prompting effort. Without this knowledge, you underuse the platform’s most powerful tool.

Key concepts

⚙️
Task tool
triggers an agent
🔀
Fan-out
1 → N
🔗
Dynamic
N = f(input)
📊
Consolidation
N → 1
2

🚀 The trigger: from "workflow" to ultracode

The magic word has changed. For a long time, the standard prompt for activating large-scale orchestration was workflow. With the latest versions of Claude Code, the recommended trigger has become ultracode. The behavior is the same—but the token changed. Knowing this prevents frustration when you follow older tutorials.

What it is

ultracode is an instruction to the orchestrator to use the maximum available parallel capacity. When you include this token in the prompt, the conductor knows it can (and should) launch as many subagents as needed, without artificial constraints.

Why learn

The right token changes the model’s execution strategy. Without it, Claude may choose to process sequentially or with fewer agents. With it, you explicitly declare: "use massive orchestration here." It’s the switch between normal mode and full-scale mode.

Key concepts

✅ New token
ultracode
activates maximum orchestration
⚠️ Old token
workflow
still works in older versions
3

📈 Scale: dozens and hundreds of agents

Claude Code was designed to support orchestration in real scale. We’re not talking about 3 to 5 subagents—we’re talking about dozens to hundreds running in parallel. Each subagent has its own session, uses tokens independently, and can be a different model from the orchestrator.

What it is

The platform doesn’t impose a hard limit on the number of subagents per workflow. The practical limit is your API account (rate limits), the available budget, and your ability to consolidate results without blowing up the orchestrator’s context. Jobs with 40+ simultaneous agents are common in large-scale audit scenarios.

Why learn

Knowing the possible scale changes your prompt architecture. If you don’t know you can launch 100 agents, you’ll keep designing sequential solutions for problems that can be parallelized. Knowing the real ceiling lets you design the right workflows from the start.

Key concepts

2–5 agentscommon use, low cost
10–40 agentsmedium-sized codebase audit
41–100 agentsheavy workflows, high cost
100–210+ agentsedge cases, plan the budget
4

💸 Cost and session limit

Dynamic workflows are expensive by design. Each subagent consumes tokens independently — and the cost of a workflow with 200 agents is approximately 200× the cost of a single agent running the same task. In addition to the financial cost, there's the session limit: the orchestrator still needs enough context to read all the reports.

What it is

The cost of a workflow is the sum of each subagent’s tokens plus the orchestrator’s tokens when consolidating. The orchestrator needs context to receive the reports — if each agent returns 500 tokens and you have 200 agents, that’s 100 000 tokens just for the reports, before any analysis.

Why learn

Planning costs before execution prevents surprises. A poorly sized workflow can consume the entire monthly budget in minutes. Understanding the cost structure lets you decide: is it worth using Haiku for subagents? Is it worth asking for ultra-short summaries? Is it worth splitting work into smaller batches?

Key concepts

✅ Cost best practices
  • • Use Haiku for subagents when possible
  • • Ask for a short summary (not a raw dump)
  • • Process in batches of 20–40 at a time
  • • Test with 5 items before scaling up
❌ Cost pitfalls
  • • Ask for long output from each agent
  • • Use Opus for all subagents
  • • Launch 200 agents without testing first
  • • Ignore the consolidation cost
5

🔬 The real case: 41 and 210 subagents

Two numbers became benchmarks in the Claude Code community for real-world workflows at scale: 41 subagents (codebase audit case) and 210 subagents (mass document processing). These aren’t tool limits — they’re documented cases that prove the architecture supports scaling without structural failures.

What it is

41
Codebase audit

Each subagent analyzed a different module. The orchestrator consolidated the findings into a single security report.

210
Document processing

Each subagent processed one section of a large document. Full fan-out in a single call to the orchestrator.

Why learn

These cases prove that dynamic workflows aren't theory—they're practice. They also set a scale threshold: if your problem has fewer than 40 parallel items, you're well within the comfort zone. If it has more than 100, you need explicit cost planning.

Key concepts

41
reference case
210
maximum documented scale.
∞
limit = budget
6

✅ When dynamic workflows are worth using

Not every parallel job needs a dynamic workflow. The rule of thumb: if processing each item is independent, the list has more than 10 items e the context would explode if processed sequentially — that’s when dynamic workflows are the right choice.

What it is

The decision criterion has three dimensions: independence (the items don’t depend on one another), volume (a list long enough to justify the orchestration overhead), and context risk (processing everything in the lead agent would overwhelm the context window).

Why learn

The most common mistake is using a workflow for everything — including small jobs where a sequence would be more efficient and less expensive. Learning the right criteria prevents wasted tokens and unnecessary complexity.

Key concepts

✅ Use a dynamic workflow
  • • Review 20+ code files
  • • Process sections of a long document
  • • Generate a report for N repositories
  • • Analyze N contracts in parallel
  • • Translate N pages simultaneously
❌ Don't use workflow
  • • Job with 2–3 items (a sequence is enough)
  • • Items that depend on one another
  • • When the cost outweighs the time savings
  • • Creative tasks that need coherence
  • • Pipeline with shared state
7

⚠️ Cautions: what can go wrong

Large-scale orchestration brings risks that don't exist with simple jobs. The three most critical: context explosion in the consolidator, unexpected cost e silent failures — a subagent that returns nothing without notifying you.

What it is

Each risk has a specific cause: the orchestrator receives reports that are too large (context explosion); the model has no advance view of the total cost before execution (financial surprise); a subagent freezes or returns a silent error, contaminating the consolidated report without the orchestrator noticing.

Why learn

Workflows that fail silently are the most dangerous—the orchestrator delivers an incomplete report without indicating that 3 of the 40 subagents returned nothing. Understanding the risk lets you add explicit validation instructions to the orchestrator prompt.

Key concepts: mitigations

01
Instruct it to keep the output short
Ask for a 3–5-bullet summary from each subagent, not a full dump
02
Test with a small batch
Run with 5 items first, validate the output, then scale up
03
Validate in the consolidator
Instruct the orchestrator to report how many agents returned empty
04
Calculate before executing
Estimate: N × average cost per agent × consolidation tokens
📄

Conceptual example

Below is the mental model for a workflow to process 15 chapters of a technical book in parallel. Notice that the orchestrator doesn’t need to read all 15 chapters—each agent reads its own and returns only the essentials.

Mental model of the workflow (conceptual) isn't real code
ORQUESTRADOR recebe: lista de 15 capítulos

PARA CADA capítulo em paralelo (ultracode):
  SUBAGENTE recebe: "Leia capitulo_X.md e me traga:
    1. Tese central (1 frase)
    2. Principais conceitos (3 bullets)
    3. Pontos confusos para revisão (máx 2)
    Resposta: máx 100 tokens."

ORQUESTRADOR consolida: 15 resumos → relatório final
  → identifica capítulos com mais pontos confusos
  → sugere ordem de revisão prioritária

Design key: each subagent returns a maximum of 100 tokens. With 15 agents, the orchestrator receives ~1 500 tokens of input — manageable. Without this limit, 15 long chapters could return 50 000 tokens and blow up the context.

⌨️

Ready-made prompts (copy and paste)

Three prompts to activate dynamic workflows with cost controls. In each one, notice the pattern: state the volume, limit each agent's output e request validation in the consolidated version.

Prompt 1 — file audit workflow with cost control
Use ultracode para auditar os arquivos em src/.
Para cada arquivo, abra um subagente com Haiku.
Cada subagente deve retornar APENAS:
- Arquivo: nome
- Problemas: lista de até 3 items
- Severidade: baixa/média/alta
Máximo 80 tokens por resposta.
Ao final, consolide quantos arquivos retornaram
vazio e liste os de severidade alta primeiro.
Prompt 2 — workflow with an explicit cost caveat asks for an estimate before running
Tenho 80 contratos em /docs/contratos/.
ANTES de rodar, estime quantos subagentes serão
criados e o custo aproximado se cada agente usar
~2 000 tokens.
Se aprovado, use ultracode: abra um subagente por
contrato, extraia só: partes, valor total, cláusula
de rescisão. Resposta máx 60 tokens cada.
Relatório final: tabela resumida.
Prompt 3 — batched workflow (cost controlled) for very large lists
Tenho 200 URLs em urls.txt. Processe em LOTES
de 20 URLs por vez (não todas de uma vez).
Cada lote: use ultracode, abra 20 subagentes em
paralelo, cada um faz: título + resumo em 2 linhas.
Após cada lote, mostre progresso (lote X/10 concluído).
Ao final, consolide tudo em uma lista numerada.
🖥️

Simulated screen: workflow running 6 subagents

This is what an audit workflow looks like in the Claude Code terminal: the orchestrator launched 6 agents simultaneously, each in its own session. The orchestrator's status line shows only ~8% of context used — the heavy work stayed with the subagents.

claude — ~/projetos/auditoria — ultracode workflow ORCHESTRATOR
# orchestrator started a dynamic workflow
✦ Detected 6 files in src/modules/ → launching 6 subagents in parallel
# active subagents
⊕ auth.py
92% Haiku · 1.8k tok
⊕ db_models.py
74% Haiku · 2.1k tok
⊕ api_routes.py
61% Haiku · 1.4k tok
⊕ utils.py
45% Haiku · 0.9k tok
⊕ middleware.py
33% Haiku · 0.7k tok
⊕ tests.py
18% Haiku · 0.3k tok
Orchestrator · context
8% used
illustrative recreation — not a real screenshot
🏋️

Exercise: workflow or sequence?

For each scenario below, decide: dynamic workflow or sequential processing? Justify your answer based on the three criteria: independence, volume, and context risk.

A

Review 3 configuration files to check whether environment variables are exposed.

Tip: think about the volume and orchestration overhead.

B

Generate a summary of 50 scientific papers for a literature survey. Each paper is ~10,000 words.

Tip: what happens to the context if you process in sequence?

C

Refactor a large module in stages: first extract classes, then rename variables, then add tests.

Tip: think about the dependency between the steps.

Evaluation criterion

A — Sequential: only 3 files; workflow overhead isn't justified. The cost and complexity outweigh the benefits of parallelism.

B — Dynamic workflow: 50 independent articles, each with 10k words. Processing them sequentially would blow up the context. Fanning out to 50 agents with short summaries is the right solution.

C — Sequential: the steps are dependent (you can't rename before extracting). Parallelism doesn't apply to pipelines with state dependencies.

✅ Module summary

  • ▸ Dynamic workflow = an orchestrator launches N subagents based on the input—N is determined at runtime.
  • ▸ The current trigger token is ultracode (it was "workflow" in older versions).
  • ▸ The platform supports dozens to hundreds of simultaneous agents—the practical limit is the budget.
  • ▸ Cost = total tokens from all subagents + consolidation. Calculate before running.
  • ▸ Reference cases: 41 agents (audit) and 210 agents (document processing).
  • ▸ Use when: independent items + high volume + risk from sequential context.
  • ▸ Mitigations: short output per agent, test with a small batch, validation by the consolidator.