Skip to content

Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.

docs: add Advanced lesson 2, choose an orchestration pattern (#94)

Wesam Abousaid419f1baddda5
diff --git a/README.md b/README.md
index c41b707..462d92c 100644
--- a/README.md
+++ b/README.md
@@ -48,13 +48,13 @@ macOS, Linux and WSL. For Windows and other installers, see the [official setup
**Intermediate Electives:** [Skill patterns](docs/intermediate/electives/skill-patterns.md) · [Claude in Chrome](docs/intermediate/electives/claude-in-chrome.md) · [The status line](docs/intermediate/electives/status-line.md) · [Fast mode](docs/intermediate/electives/fast-mode.md)
-**Advanced** (being rebuilt): [Level index](docs/advanced/README.md) · [Parallel sessions with worktrees](docs/advanced/01-parallel-sessions.md)
+**Advanced** (being rebuilt): [Level index](docs/advanced/README.md) · [Parallel sessions with worktrees](docs/advanced/01-parallel-sessions.md) · [Choose an orchestration pattern](docs/advanced/02-orchestration-patterns.md)
**Topics:** [All topics](docs/topics/README.md) · [Permissions and safety](docs/topics/permissions-and-safety.md) · [Memory and context](docs/topics/memory-and-context.md) · [Models, effort and cost](docs/topics/models-effort-and-cost.md) · [Skills](docs/topics/skills.md) · [Hooks](docs/topics/hooks.md) · [Subagents and parallel work](docs/topics/subagents-and-parallel-work.md) · [MCP](docs/topics/mcp.md) · [Plugins](docs/topics/plugins.md) · [Automation](docs/topics/automation.md)
**Reference:** [Reference index](docs/reference/README.md) · [Models and effort](docs/reference/models.md) · [Commands by level](docs/reference/commands.md) · [Feature map](docs/reference/feature-map.md) · [Further learning](docs/reference/further-reading.md) · [Glossary](docs/reference/glossary.md) · [Changelog](docs/reference/changelog.md)
-**From the previous edition, not yet re-verified:** [Subagents and parallel work](docs/legacy/subagents-and-parallel-work.md) · [Agent teams](docs/agent-teams.md) · [Dynamic workflows](docs/workflows.md)
+**From the previous edition, not yet re-verified:** [Agent teams](docs/agent-teams.md) · [Dynamic workflows](docs/workflows.md)
**Examples:** [How to use the examples](examples/README.md)
@@ -85,7 +85,7 @@ The previous edition's README sections moved. If a link brought you here, find i
- <a id="hooks"></a><a id="setting-up-claude-hooks"></a><a id="setting-up-hooks"></a><a id="hook-events"></a><a id="hook-input"></a><a id="hook-output"></a><a id="security-considerations"></a><a id="hook-execution-details-and-debugging"></a><a id="execution--debugging"></a>Moved to [Enforce a rule with a hook](docs/intermediate/05-hooks.md).
- <a id="ai-agents"></a>Moved to [Subagents and parallel work topic](docs/topics/subagents-and-parallel-work.md).
- <a id="2-general-purpose-subagents--when-one-claude-isnt-enough"></a><a id="3-specialized-subagents--drop-in-role-prompts"></a>Moved to [Delegate to a custom subagent](docs/intermediate/06-subagents.md). The drop-in role prompts were removed in edition v2026.10: see the [CHANGELOG](CHANGELOG.md#removed-listings).
-- <a id="running-agents-in-parallel"></a><a id="subagents--running-agents-in-parallel"></a><a id="orchestrating-specialists-from-the-main-session"></a>Moved to [Subagents and parallel work (previous edition)](docs/legacy/subagents-and-parallel-work.md).
+- <a id="running-agents-in-parallel"></a><a id="subagents--running-agents-in-parallel"></a><a id="orchestrating-specialists-from-the-main-session"></a>Moved to [Choose an orchestration pattern](docs/advanced/02-orchestration-patterns.md).
- <a id="1-git-worktrees--parallel-branches-parallel-sessions"></a>Moved to [Parallel sessions with worktrees](docs/advanced/01-parallel-sessions.md).
- <a id="agent-teams-experimental---2026"></a><a id="agent-teams-experimental"></a><a id="enable-it"></a><a id="the-example-that-justifies-the-cost"></a><a id="staff-a-team-with-the-role-prompts-you-already-have"></a><a id="three-things-that-catch-people-out"></a><a id="monitoring-and-the-naming-trap"></a><a id="best-practices"></a>Moved to [Agent teams (previous edition)](docs/agent-teams.md).
- <a id="dynamic-workflows"></a><a id="try-it-in-2-minutes--no-script-required"></a><a id="starting-your-own"></a>Moved to [Dynamic workflows (previous edition)](docs/workflows.md).
diff --git a/docs/advanced/01-parallel-sessions.md b/docs/advanced/01-parallel-sessions.md
index 36ed6c8..01576b2 100644
--- a/docs/advanced/01-parallel-sessions.md
+++ b/docs/advanced/01-parallel-sessions.md
@@ -127,4 +127,4 @@ If the first item fails, run `git -c core.excludesFile=/dev/null check-ignore -v
<sub>Sources: [Run parallel sessions with worktrees](https://code.claude.com/docs/en/worktrees) · [All settings](https://code.claude.com/docs/en/settings-reference) · [Settings files and precedence](https://code.claude.com/docs/en/settings) · [Configure the sandboxed Bash tool](https://code.claude.com/docs/en/sandboxing) · [Run agents in parallel](https://code.claude.com/docs/en/agents) · [git-worktree](https://git-scm.com/docs/git-worktree) · [git-merge](https://git-scm.com/docs/git-merge) · [git-check-ignore](https://git-scm.com/docs/git-check-ignore) · [gitignore](https://git-scm.com/docs/gitignore) · [git-merge-base](https://git-scm.com/docs/git-merge-base) · [git-branch](https://git-scm.com/docs/git-branch)</sub>
-<sub>← [Advanced index](README.md) · Topic: [Subagents and parallel work](../topics/subagents-and-parallel-work.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=a-1)</sub>
+<sub>← [Advanced index](README.md) · [Choose an orchestration pattern](02-orchestration-patterns.md) → · Topic: [Subagents and parallel work](../topics/subagents-and-parallel-work.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=a-1)</sub>
diff --git a/docs/advanced/02-orchestration-patterns.md b/docs/advanced/02-orchestration-patterns.md
new file mode 100644
index 0000000..0a8e353
--- /dev/null
+++ b/docs/advanced/02-orchestration-patterns.md
@@ -0,0 +1,108 @@
+# Choose an orchestration pattern
+
+<sub>**Advanced** · Lesson 2 of 7 · about 20 minutes · Needs: [Parallel sessions with worktrees](01-parallel-sessions.md) · Verified against Claude Code v2.1.285 (stable) on 2026-10-09</sub>
+
+## Goal
+
+By the end of this lesson you can choose between the main conversation, subagents, a dynamic workflow and an agent team by what a job needs and what it costs, and run a job as parallel subagents.
+
+## You need
+
+- Your repository from [lesson 1](01-parallel-sessions.md), with at least three top-level folders that hold files, and your copy of the practice template with Node.js LTS: the check runs from the copy. Set up the repository's `.practice/` folder as [Beginner lesson 1](../beginner/01-install-and-look-around.md#you-need) describes, if you haven't yet.
+- macOS, Linux or WSL 2, and `jq`: the delegation log in Your turn is a shell command that uses it.
+- Usage: moderate. Each subagent works in its own context window and sends its own requests, which count toward the same usage limits as your main conversation ([Create custom subagents](https://code.claude.com/docs/en/sub-agents)). For a lighter run, use two folders in the Worked example and two files in job 1.
+
+## The idea
+
+Subagents, a dynamic workflow and an agent team all split a job across workers; what differs is who holds the plan ([When to use a workflow](https://code.claude.com/docs/en/workflows#when-to-use-a-workflow)). With subagents, Claude decides turn by turn, and each result comes back into your conversation. A dynamic workflow is a script Claude writes: it holds the loop and the intermediate results, so it can run many agents, cross-check their findings and rerun the same way. In an agent team, a lead supervises teammates who message each other directly ([Choose an approach](https://code.claude.com/docs/en/agents#choose-an-approach)).
+
+Every pattern past one conversation adds usage: each subagent, and each agent a workflow spawns, sends requests of its own ([Why usage climbs](https://code.claude.com/docs/en/costs#why-usage-climbs-in-a-long-session)), and agent teams "use significantly more tokens than a single session" ([When to use agent teams](https://code.claude.com/docs/en/agent-teams#when-to-use-agent-teams)). So pick the cheapest pattern the job needs: ask these questions in order, and stop at the first answer that settles it.
+
+```mermaid
+flowchart TD
+ accTitle: Who holds the plan
+ accDescr: A path for choosing how to split a job. If one conversation can do it without filling up, keep it in the main conversation. Otherwise, if the workers must talk to each other, a lead holds the plan in an agent team, which is experimental. If they need not talk and the job is a few tasks done once, Claude holds the plan and subagents return summaries. If it needs many agents, cross-checked findings or a rerun, a script holds the plan in a dynamic workflow.
+ A["A job"] --> B{"Can one conversation do it without filling up?"}
+ B -- yes --> M["Main conversation"]
+ B -- no --> C{"Must the workers talk to each other?"}
+ C -- yes --> T["Agent team: a lead holds the plan"]
+ C -- no --> D{"Does it need many agents, cross-checked findings or a rerun?"}
+ D -- no --> S["Subagents: Claude holds the plan"]
+ D -- yes --> W["Dynamic workflow: a script holds the plan"]
+```
+
+> [!NOTE]
+> "Agent teams are experimental and disabled by default." ([Orchestrate teams of Claude Code sessions](https://code.claude.com/docs/en/agent-teams)) This lesson names them as one option and doesn't run one.
+
+## Worked example
+
+1. Pick three top-level folders in your repository, such as `src`, `test` and `docs`, and start `claude`.
+2. Ask the chart's questions about one job: a newcomer's summary of each folder. One conversation would fill with file reads it won't need again, so not the main conversation ([Choose between subagents and main conversation](https://code.claude.com/docs/en/sub-agents#choose-between-subagents-and-main-conversation)). The summaries needn't talk to each other, so no team. It's three tasks, done once, so subagents.
+3. Ask for them, with your own folder names, as the docs' parallel research example does ([Run parallel research](https://code.claude.com/docs/en/sub-agents#run-parallel-research)):
+
+ ```text
+ Research the src, test and docs folders in parallel using separate subagents, and give me two sentences on each.
+ ```
+
+ By default, an interactive session runs subagents in the background, so your prompt stays free ([Run subagents in foreground or background](https://code.claude.com/docs/en/sub-agents#run-subagents-in-foreground-or-background)). The panel below the prompt shows a row for each one while it works.
+4. While they work, run `/tasks`. It lists each subagent with its state and the model it runs on; press Enter on a row to open its transcript ([Check on running work](https://code.claude.com/docs/en/agents#check-on-running-work), [Choose a model](https://code.claude.com/docs/en/sub-agents#choose-a-model)). Claude may start [built-in](https://code.claude.com/docs/en/sub-agents#built-in-subagents) `Explore` or `general-purpose` subagents, or forks of your conversation, so your rows will differ. When one finishes successfully, its row leaves the panel and the footer briefly shows `/tasks to see subagents`; the row of one that fails stays for a moment.
+5. When the summaries arrive, run `/usage`. On a Pro, Max, Team or Enterprise plan, its usage breakdown attributes your recent usage to skills, subagents, plugins and MCP servers, and flags behaviors, such as long context, that account for a notable share of it ([Plan usage breakdown](https://code.claude.com/docs/en/costs#plan-usage-breakdown)). Its Session block, intended for API users such as those signed in with a Console account, shows this session's estimated cost ([Using the `/usage` command](https://code.claude.com/docs/en/costs#using-the-%2Fusage-command)). Both are estimates.
+6. Name what would change the answer. The same summary for every folder, cross-checked and rerun before each release, would be a workflow, the next lesson's pattern. Reviewers who must argue a root cause out between themselves would be an agent team.
+
+## Your turn
+
+**Brief:** here are four jobs for your repository. Choose a pattern for each by what it needs and what it costs, write your choices down, then run the one that calls for subagents.
+
+1. Check the three largest source files for errors that are caught and ignored. Reading the files in your conversation would crowd it, and you only need the findings: one reviewer per file, once, and one short list back.
+2. Run the same check on every source file, verify each finding against the code before it's reported, and rerun it before every release.
+3. Fix a typo in one error message.
+4. Three investigators each test a different theory for a flaky test, message each other as they work to challenge each other's findings, and keep going until they agree on a cause.
+
+**Acceptance criteria:**
+
+- `.practice/a-2-choices.md` has one line per job, `<job number>: <pattern> because <reason>`, and each pattern is `main conversation`, `subagents`, `workflow` or `agent team`.
+- `.practice/a-2-hook.json` holds this [`SubagentStart` hook](https://code.claude.com/docs/en/hooks#subagentstart), which appends each subagent's id and type to `.practice/a-2-agents.txt` when it starts, like the delegation log in [Delegate to a custom subagent](../intermediate/06-subagents.md):
+
+ ```json
+ {
+ "hooks": {
+ "SubagentStart": [
+ { "hooks": [ { "type": "command", "command": "jq -r '[.agent_id, .agent_type] | @tsv' >> \"$CLAUDE_PROJECT_DIR/.practice/a-2-agents.txt\"" } ] }
+ ]
+ }
+ }
+ ```
+
+- Job 1 ran as parallel subagents, one per file, in a session you started with `claude --settings .practice/a-2-hook.json` ([CLI reference](https://code.claude.com/docs/en/cli-reference#cli-flags)).
+- Job 1 changed no file: the reviewers only report, and `git status` shows no change from them.
+- Only job 1 ran. The other three are choices.
+
+## Check
+
+You are done when all of these are true:
+
+- [ ] `.practice/a-2-choices.md` picks the cheapest pattern that fits each job.
+- [ ] `.practice/a-2-agents.txt` shows at least two subagents starting for job 1: `cut -f1 .practice/a-2-agents.txt | sort -u` lists two or more ids.
+- [ ] Self-check (not tested): for one real job from your own backlog, you can name its pattern, the question that decided it, and why a cheaper pattern wouldn't do.
+
+Run `npm run check -- a-2 --dir <your repo>` from your practice copy.
+
+If a job's pattern is wrong, ask the chart's questions in order: the check's hint names the question that settles that job. If the log has fewer than two ids, start the session with the hook file and ask for one subagent per file, in parallel. A subagent that Claude resumes logs its id again, so it counts once.
+
+## Watch out
+
+- A background subagent's permission prompts appear in your main session, and an answer that lasts beyond that one tool call, such as a grant for the rest of the session, applies to the whole session, your main conversation included ([Run subagents in foreground or background](https://code.claude.com/docs/en/sub-agents#run-subagents-in-foreground-or-background)). Approve each of those prompts for that one call only, never for the rest of the session, and ask reviewers only to read.
+- Each subagent's result returns to your conversation, and each subagent spends tokens of its own while it runs, so many detailed results crowd your context and add to your usage. Ask for short results ([Run parallel research](https://code.claude.com/docs/en/sub-agents#run-parallel-research)).
+- With agent teams turned on, a subagent that Claude names launches as a teammate, so a team can form when you asked for subagents. The hook also logs a line each time a teammate that runs inside your main terminal handles a new message ([Claude spawns teammates instead of subagents](https://code.claude.com/docs/en/agent-teams#claude-spawns-teammates-instead-of-subagents), [SubagentStart](https://code.claude.com/docs/en/hooks#subagentstart)). If you turned teams on, add `"env": { "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "0" }` to `.practice/a-2-hook.json`, as a top-level key beside `"hooks"`. A `--settings` file overrides your user, project and local settings and a shell export, and only managed settings override it ([Settings precedence](https://code.claude.com/docs/en/settings#settings-precedence)).
+
+## Go further
+
+- [Run agents in parallel](https://code.claude.com/docs/en/agents): the official comparison of the ways Claude Code works on several tasks at once, and how to check on each.
+- [Fork the current conversation](https://code.claude.com/docs/en/sub-agents#fork-the-current-conversation): a subagent that inherits your whole conversation and shares its prompt cache, for a side task that needs the same context.
+- [Agent team token costs](https://code.claude.com/docs/en/costs#agent-team-token-costs): what drives a team's usage, and how to keep it small.
+
+---
+
+<sub>Sources: [Run agents in parallel](https://code.claude.com/docs/en/agents) · [Orchestrate subagents at scale with dynamic workflows](https://code.claude.com/docs/en/workflows) · [Orchestrate teams of Claude Code sessions](https://code.claude.com/docs/en/agent-teams) · [Create custom subagents](https://code.claude.com/docs/en/sub-agents) · [Manage costs effectively](https://code.claude.com/docs/en/costs) · [Hooks reference](https://code.claude.com/docs/en/hooks) · [CLI reference](https://code.claude.com/docs/en/cli-reference) · [Settings files and precedence](https://code.claude.com/docs/en/settings)</sub>
+
+<sub>← [Parallel sessions with worktrees](01-parallel-sessions.md) · [Advanced index](README.md) · Topic: [Subagents and parallel work](../topics/subagents-and-parallel-work.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=a-2)</sub>
diff --git a/docs/advanced/README.md b/docs/advanced/README.md
index 2bd88f4..70265c7 100644
--- a/docs/advanced/README.md
+++ b/docs/advanced/README.md
@@ -28,7 +28,7 @@ git commit -m "Add the Advanced checks"
## Lessons
1. [Parallel sessions with worktrees](01-parallel-sessions.md)
-2. Choose an orchestration pattern
+2. [Choose an orchestration pattern](02-orchestration-patterns.md)
3. Run and save a dynamic workflow
4. Script Claude Code with `claude -p`
5. GitHub Actions
diff --git a/docs/legacy/subagents-and-parallel-work.md b/docs/legacy/subagents-and-parallel-work.md
deleted file mode 100644
index acf9dee..0000000
--- a/docs/legacy/subagents-and-parallel-work.md
+++ /dev/null
@@ -1,32 +0,0 @@
-<a id="ai-agents"></a>
-<a id="running-agents-in-parallel"></a>
-<a id="subagents--running-agents-in-parallel"></a>
-# Subagents and running agents in parallel
-
-> [!NOTE]
-> From the previous edition, not yet re-verified. The guide is being rebuilt as lessons; this page keeps the earlier material reachable until they land.
-
-Claude Code has **four** ways to run agents at once. They're easy to confuse, so start here: the question that separates them is **who coordinates the work**:
-
-| Surface | Who coordinates | Reach for it when… |
-|---|---|---|
-| **[Subagents](../intermediate/06-subagents.md)** | Claude, turn by turn, inside one session | A side task would flood your main conversation with search results, logs, or file contents you'll never reference again |
-| **Agent view**: `claude agents` *(research preview)* | **You**: hand off, check back later | You have several independent tasks and want to dispatch them, glance at status, and step in only when one needs you. Each dispatched session gets **its own worktree automatically** |
-| **[Agent Teams](../../README.md#agent-teams-experimental)** *(experimental)* | A lead agent supervising peer sessions | Workers need to **talk to each other**: share findings, challenge each other, self-claim from a shared task list |
-| **[Dynamic Workflows](../../README.md#dynamic-workflows)** | **A script**, not Claude's judgement | The job outgrows a handful of subagents, or you want findings cross-checked against each other: codebase-wide audits, 500-file migrations |
-
-Two supporting tools that aren't a coordination style of their own:
-
-- **[Git worktrees](../advanced/01-parallel-sessions.md)**: separate checkouts, so parallel sessions each edit their own copy of the files.
-- **`/batch`**: a bundled skill that researches the codebase, splits one large change into **5–30 independent units**, and spawns a background subagent per unit **in its own worktree, each opening a PR**. It's a packaged use of subagents + worktrees, and the fastest way to feel this whole category.
-
-> [!TIP]
-> **Checking on running work** depends on what you started: `/tasks` for anything backgrounded in the current session, `claude agents` for background sessions, `/workflows` for workflow runs. Note `/agents` (removed as a wizard in v2.1.198) is a different thing entirely from `claude agents`.
-
-Worktrees now have their own lesson: [Parallel sessions with worktrees](../advanced/01-parallel-sessions.md).
-
-Subagents now have their own lesson: [Delegate to a custom subagent](../intermediate/06-subagents.md).
-
----
-
-<sub>From the previous edition of [Claude Code: Everything You Need to Know](../../README.md).</sub>
diff --git a/docs/reference/commands.md b/docs/reference/commands.md
index 557d173..b413928 100644
--- a/docs/reference/commands.md
+++ b/docs/reference/commands.md
@@ -40,11 +40,12 @@ Electives: `/statusline` ([The status line](../intermediate/electives/status-lin
## Advanced
- `claude --worktree <name>` (`-w`): start a session in an isolated git worktree at `.claude/worktrees/<name>` ([CLI reference](https://code.claude.com/docs/en/cli-reference#cli-flags)). [Parallel sessions with worktrees](../advanced/01-parallel-sessions.md)
+- `/tasks`: view and manage background work in this session, including subagents that have finished. [Choose an orchestration pattern](../advanced/02-orchestration-patterns.md)
- `/workflows`: watch, pause, resume and save dynamic workflows. *Run and save a dynamic workflow*
- `/install-github-app`: install the Claude GitHub App for a repository, with optional workflow and secret setup. *GitHub Actions*
- `/usage`: the session's cost, your plan's usage limits and activity stats. *Put bounds on autonomous runs*
-Electives: `/background` (agent view) and `/tasks` (background work in this session); `/goal`, `/loop` and `/schedule` (`/goal`, `/loop` and routines).
+Electives: `/background` (agent view); `/goal`, `/loop` and `/schedule` (`/goal`, `/loop` and routines).
<a id="custom-slash-commands-skills"></a>
## Your own commands
diff --git a/docs/topics/subagents-and-parallel-work.md b/docs/topics/subagents-and-parallel-work.md
index 203ccde..6e33c30 100644
--- a/docs/topics/subagents-and-parallel-work.md
+++ b/docs/topics/subagents-and-parallel-work.md
@@ -8,6 +8,7 @@ Ways to split work across contexts and sessions: subagents, worktrees, dynamic w
- Intermediate: [Delegate to a custom subagent](../intermediate/06-subagents.md)
- Advanced: [Parallel sessions with worktrees](../advanced/01-parallel-sessions.md)
+- Advanced: [Choose an orchestration pattern](../advanced/02-orchestration-patterns.md)
More of this topic's lessons and Electives are linked here as they are published.