Zum Inhalt springen

Delegation Strategies

Knowledge

When to Delegate?

Not every task needs a Subagent. The fundamental question is: Can the result be summarized in 2-3 sentences? If yes, a Subagent makes sense -- because you save context, since only the summary comes back instead of all intermediate steps.

Here are the most common delegation scenarios:

Research Tasks -- Explore Subagent

"Find out how error handling is implemented in this project"

The Explore agent (Haiku, read-only) searches the codebase and delivers a structured summary. Cost: minimal. Context consumption in the main agent: one paragraph instead of 50 files.

Code Review -- Custom Agent with Restricted Tools

@"reviewer (agent)" check the changes in the last commit

A Custom Agent with only read tools (Read, Grep, Glob) cannot modify files -- perfect for safe, independent review.

Complex Features -- General-purpose with Opus

For demanding implementations that require deep understanding -- for example, a new authentication system -- you delegate to a General-purpose agent that inherits the full model and all tools.

Parallel Tasks -- Multiple Subagents Simultaneously

The true strength of delegation shows with parallelism:

"Start three Subagents:
1. Analyze the test coverage in src/auth/
2. Check the API endpoints for missing validation
3. Find all TODO comments in the project"

Three Subagents work simultaneously, each with their own context. You get three compact results back.

*The 2-3 Sentence Rule of Thumb

Before delegating, ask yourself: "Can the result be summarized in 2-3 sentences?" If yes, a Subagent is ideal. If you need the complete result in context (e.g., to build on it), direct processing is better.

Cost Optimization Through Model Selection

The choice of model directly impacts costs and quality:

ModelStrengthTypical TasksRelative Cost
HaikuFast, cheapSearch, simple analysis, summariesLow
SonnetBalancedCode review, test creation, refactoringMedium
OpusHighest qualityArchitecture decisions, complex featuresHigh

Rule of thumb for model selection:

  • Does the agent only need to read and summarize? -- Haiku
  • Does the agent need to write or analyze code? -- Sonnet
  • Is it about complex architecture or difficult bugs? -- Opus

!Keep Costs in Mind

An Opus Subagent with 50 tool calls can quickly get expensive. Use Opus only when the task truly requires the highest model quality. For most tasks, Sonnet is sufficient -- for pure research, even Haiku.

Subagents vs. Agent Teams

Claude Code offers two delegation mechanisms: Subagents (this module) and Agent Teams (Module 8). Here's the comparison:

PropertySubagentsAgent Teams
ContextOwn window, result goes back to main agentCompletely independent agents with their own conversations
CommunicationOnly with the main agent (one-way)Agents communicate directly with each other
Can spawn SubagentsNo (no nesting)Yes (the lead agent can delegate)
Token costsLower (one agent per task)Higher (multiple agents with their own context)
OrchestrationSimple (main agent delegates and waits)Complex (coordination, messaging, shared tasks)
Ideal forIndividual, self-contained subtasksLarge projects with multiple interconnected tasks

You have a project with 3 microservices that need to be updated simultaneously and depend on each other. What is better suited?

Understand

Describe task: You give Claude Code a task, e.g., 'Find all TODO comments in the project'
Step 1 of 6

Decision Tree for Delegation

When facing a task, this decision process helps:

1. Is the task self-contained?

  • Yes --> Subagent
  • No (tasks are interconnected) --> Agent Team

2. Does the agent need to write code?

  • No (research only) --> Explore (Haiku)
  • Yes, moderate scope --> Custom Agent (Sonnet)
  • Yes, complex --> General-purpose (Opus)

3. Can it run in parallel?

  • Yes --> Background tasks or multiple Subagents
  • No --> Sequential in the main agent

4. Is there conflict potential with your current work?

  • Yes --> isolation: worktree
  • No --> Standard isolation is sufficient

You want to know which npm packages in your project are outdated. Which delegation is optimal?

Apply

Practical Example: Feature Development with Subagents

Imagine you're building a new comment system. An efficient workflow might look like this:

Step 1: Research (Explore, Haiku)
"How is the existing data model for posts structured?"
--> Result: "Posts use Prisma with id, title, content, authorId..."

Step 2: Review existing patterns (Custom Agent, Sonnet)
@"pattern-analyzer (agent)" "What patterns do the existing CRUD operations use?"
--> Result: "Service Layer Pattern with Repository, Validation via Zod..."

Step 3: Implementation (General-purpose, inherits model)
"Implement the Comment model and service following the existing patterns"
--> Agent implements based on the results from Steps 1 and 2

Each step uses the appropriate agent type: cheap for research, medium for analysis, full for implementation.

Reflect

Effective delegation is a core competency for working with Claude Code. The right choice between Explore, Custom Agent, and General-purpose saves tokens, costs, and context. And the rule of thumb stays simple: If the result fits in 2-3 sentences, delegate it to a Subagent.