PTENES
Skip to content
MODULE 4.2

🤖 True Parallelism

Put the theory into practice: launch multiple agents, use worktrees, collect results, and handle partial failures. This module is hands-on with parallel invocation patterns.

6
Topics
~45
Minutes
4.1
Prerequisite
Practical
Type
Progress:0%0 of 6
1

Launching multiple agents

To launch multiple agents, just ask Claude: "Execute these three tasks in parallel using subagents". It will invoke the Task tool multiple times simultaneously. The key is to phrase each task as a self-contained instruction.

prompt-para-paralelo.txt
Execute em paralelo usando subagentes:
1. Rode todos os testes e reporte quais falharam
2. Analise o arquivo src/auth.ts e sugira melhorias de seguranca
3. Atualize o README com as novas funcionalidades
Cada tarefa e independente. Use worktrees se precisar editar arquivos.

In one sentence: Ask Claude to run tasks in parallel, and it automatically creates subagents.

2

Independence vs. dependency

The golden rule: only parallelize tasks that don't depend on each other. If task B needs the result of task A, they should run sequentially. But if A, B, and C are independent (e.g., tests, lint, and docs), launch them all at once.

A useful rule of thumb: if you can explain each task without mentioning the others, they're independent. If you need to say "after X is finished," it's dependent and should be sequential.

In one sentence: Parallelize what doesn't depend on anything else; sequence what needs a prior result.

3

Worktrees in practice

Claude Code can use the command git worktree add to create isolated workspaces. Each worktree is a copy of the repository with its own branch, where the subagent edits freely without interfering with others.

worktree-commands.sh
# Criar worktree para um subagente
git worktree add .claude/worktrees/agent-testes -b agent/testes

# Listar worktrees ativos
git worktree list

# Remover apos o merge
git worktree remove .claude/worktrees/agent-testes

In one sentence: git worktree add creates an isolated space for each agent; after the merge, the worktree is removed.

4

Background tasks

Some tasks take time: running an entire test suite, building, or analyzing a large codebase. Instead of waiting around, the main agent launches the task in the background and keeps working. When the result is ready, it incorporates it. This is especially useful with the run_in_background from the Bash tool.

In one sentence: long-running tasks run in the background while the main agent keeps producing.

5

Collecting results

When all subagents finish, the parent agent receives the text results from each one. The parent is responsible for synthesizing them: combining the findings, resolving any conflicts, and producing the final output. Think of it as a manager who receives reports from the team and puts together the consolidated report.

In one sentence: the parent gathers the results from all subagents and synthesizes the final output.

6

Parallel error handling

When a subagent fails, the parent has three options: retry (try again with an adjusted prompt), skip (ignore them and continue with the successful ones) or abort (stop everything). The strategy depends on the task's criticality. Tests failing? Retry with more context. Outdated docs? Skip for now. Security bug? Abort and investigate.

Caution

Don't silently ignore failures. Always log or report which subagent failed and why. Silent failures become future bugs.

In one sentence: subagent failed? Retry, skip, or abort depending on criticality.

🧾 Module Summary

✓
Parallelize independent tasks — ask Claude and it creates subagents automatically.
✓
Worktrees isolate the filesystem — each agent edits without conflicts.
✓
Background for long-running tasks — don't block the main agent.
✓
Handle failures explicitly — retry, skip, or abort as appropriate.

Next module:

4.3 — Multi-Agent Patterns: Fan-Out/In, Pipelines, and Specialist Agents.