Mastering Claude Code — From Zero to 10x — 6. Delegate in parallel: subagents

17 min read min de lecture
Chapter 06

Delegate in parallel: subagents

Chapter 6 of 10 · 60%

Chapter objectives

  • Understand what a subagent is
  • Have the skill publish to all platforms in parallel
  • Grasp why parallelism saves precious time

What is a subagent?

A subagent is a separate process that handles a task independently. It's the closest analogy to an "AI employee": you hand it a well-scoped mission, it works on its own with the context and tools it needs, then brings you back the result. The main agent — the one you're conversing with — becomes a conductor: it splits the work, delegates, and assembles the results.

Your main /post skill will delegate to subagents and collect their results. Since they run in parallel, independent tasks (publishing to 4 platforms) happen simultaneously instead of one at a time. That's this chapter's change of scale: we go from an assistant that does things fast to a system that does several things at the same time.

The real superpower: isolated context

The time saving is the visible benefit, but there's a second one, subtler and just as valuable: each subagent works inside its own context window. Remember chapter 2: noise degrades answers. When a subagent adapts your post for Instagram, it loads the Instagram rules, the Instagram samples, runs its drafts — and none of that volume pollutes the main conversation. The main agent only receives the final, clean result.

Without subagents, publishing to 4 platforms would fill your context window with four times all that intermediate work, and the session would become confused well before the end. With them, your main conversation stays a readable logbook: mission, delegation, results. That's why subagents are useful even for bulky sequential tasks — exploring a big codebase, analyzing ten documents — not just for parallelism.

Splitting rule: a subagent receives a mission that is self-contained and well-scoped ("adapt and publish this post for Instagram"), not a vague one ("handle the socials"). The sharper the mission, the less it needs to come back and ask you anything — and the better the parallelization.

Defining specialized subagents (optional but powerful)

Claude Code can spin up generic subagents on the fly — that's what your skill will do. But you can also define named, specialized subagents, with the /agents command or by creating files in .claude/agents/. Each file describes a role: its name, its description (which Claude uses to know when to call on it), the tools it's allowed, and its system prompt.

text
---
name: instagram-writer
description: Adapts content to the Instagram format (caption + hashtags) in the brand voice. Use for any Instagram publication.
tools: Read, Write, Bash
---

You are the brand's Instagram specialist.
You read brand-voice.md before writing anything.
Format: strong hook, airy caption, 3 to 5 hashtags at the end.
You never publish without an attached media.

The value of specialization: an "Instagram writer" subagent with a precise role and restricted tools is more reliable than a generalist, exactly like in a human team. And restricting its tools (no network access for a proofreader, for example) is a free security measure. For Lea's project, the skill with on-the-fly subagents is enough — but keep this card in mind for your more ambitious systems.

Skill, hook, subagent: who does what?

At this point in the course, you have three extension mechanisms. From a distance they look alike, but each answers a different question — and confusing them is the most common beginner mistake:

SkillWHAT to do. A reusable piece of know-how that you invoke (or Claude invokes): "publish a post." It's your library of procedures.
HookWhat must ALWAYS happen. A deterministic guarantee attached to the lifecycle: "no non-compliant publication ever goes out." It's your law.
SubagentWHO does the work. A worker with its own context, parallelizable: "four writers working at the same time." It's your workforce.

The three combine naturally: the skill describes the procedure, which delegates to subagents, each of whose actions passes under the hooks. That's exactly the architecture of Lea's system.

Taking the skill multi-platform

PROMPT
update the /post skill to support "all":
/post "topic" all

when the platform is "all":
- create the visual only once
- launch one subagent per platform (twitter, linkedin, instagram, facebook)
- each subagent adapts the text to the platform's format, limits, and voice
- all publish in parallel
- log all the results

Note the detail "create the visual only once": that's an architecture choice. Generating the visual is expensive and the result is shared — so it stays in the main agent, before delegation. Only the genuinely independent work (adapting the text, publishing, logging) goes parallel. Identifying what's shared and what's independent is the heart of designing a parallel system.

Then run: /post "our zero-waste commitments" all. Claude creates one visual, writes the variants in your voice, asks for your approval, then launches the subagents. You'll see several task blocks executing simultaneously in the interface — that's your team at work.

flowchart TD
  M["/post topic all"] --> V["Visual created only once"]
  V --> S1["Twitter subagent"]
  V --> S2["LinkedIn subagent"]
  V --> S3["Instagram subagent"]
  V --> S4["Facebook subagent"]
  S1 --> J["Log + URLs"]
  S2 --> J
  S3 --> J
  S4 --> J
4 publications in parallel = one single wait instead of four.

Why not sequentially?

Each publication is asynchronous: Claude sends the post then polls the API every few seconds until the status reads "published" (5 to 30s depending on the platform). 4 posts in series = up to 2 minutes of cumulative waiting, during which nothing useful happens. 4 subagents in parallel = one single wait, the slowest one's.

Each subagent manages its own async cycle: send, poll, process the response, log. Writing the variants and the approval, however, stay in the main agent — you approve once, then everything goes out in parallel. And if one subagent fails (API down, quota exceeded), the other three finish normally: you only retry the failed platform, not the whole batch.

Each subagent inherits your hooks: the previous chapter's quality gate therefore applies everywhere, automatically. That's the combination that makes parallelism stress-free — you don't multiply the workers without first laying down the law.

The limits of parallelism

The "parallelize everything" reflex would be a mistake. Parallelism has a cost: each subagent consumes its own tokens, and orchestration carries its own complexity. It's only worth it if the tasks are genuinely independent (none needs another's result) and long enough for the cumulative waiting to matter. Adapting four posts: perfect. Three steps where each depends on the previous one (research → write → publish): no parallelization possible, it's a chain.

The good test: draw your flow like the diagram above. Branches that leave the same node and never touch again are parallelizable; anything chained vertically isn't. Two minutes of sketching saves hours of needlessly complex architecture.

🛠️ Your turn

Context

Lea is launching a -20% flash sale this weekend and wants to announce it on her 4 networks immediately — every minute counts, so waiting 2 minutes of serial publications is out of the question. It's also the first real test of the complete architecture: skill + voice + quality gate + subagents. You'll observe the system end to end, including how it behaves when a subagent runs into a problem.

Instructions

  1. Update the /post skill to handle "all" with the prompt provided.
  2. Reread the updated SKILL.md: spot what stays in the main agent (visual, approval) and what goes to subagents.
  3. Run /post "flash sale -20% this weekend" all.
  4. Approve the plan once and watch the subagents execute in parallel in the interface.
  5. Check the log: 4 publications, 4 URLs, a single waiting time.
  6. Verify that the quality gate applied to every subagent (the posts respect limits and banned words).
  7. Ask Claude: "if the Instagram subagent had failed, what would have happened?" and verify that the retry would only concern that platform.
Hint — If a subagent fails, it doesn't block the others: they're independent. You only relaunch the failed platform.

In summary

  • A subagent is an independent process, like an "AI employee" you hand a well-scoped mission to.
  • Double benefit: parallelism (time saved) and isolated context (the main conversation stays clean).
  • The main skill delegates to subagents and collects their results; shared work (the visual) stays upstream.
  • Named, specialized subagents can be defined in .claude/agents/ (role, restricted tools, prompt).
  • Skill = what to do, hook = what must always happen, subagent = who does the work: three complementary mechanisms.
  • Parallelism turns several async waits into one — but only for genuinely independent tasks.
  • Subagents inherit the hooks: the quality gate applies everywhere, and an isolated failure doesn't block the rest.

Quiz — check your understanding

1. What's the main benefit of running subagents in parallel?

Publishing in parallel replaces the sum of the waits (up to 2 min) with a single wait.

2. What do subagents inherit from your configuration?

The quality gate applies to every subagent automatically.

3. What's the second benefit of subagents, beyond the time saved?

Intermediate work (drafts, large volumes read) stays in the subagent's context; the main agent only receives the final result.

4. Why is the visual created BEFORE delegating to the subagents?

Only genuinely independent work goes parallel; what's shared stays in the main agent. That's the heart of parallel design.

5. Which tasks are good candidates for parallelization?

A chain (research → write → publish) can't be parallelized; independent branches (4 platforms) can.

Auteur(s)

R

REHOUMA Haythem

Haythem Rehouma est un ingénieur et architecte IA et cloud, formateur et enseignant technique, avec un profil orienté IA médicale, AWS, MLOps, LLM/RAG et vision par ordinateur.