Phase 1: Task Analysis and Decomposition
Before spawning any subagents, analyze the task:
- Estimate context requirements
- Count files/sources to process
- Estimate tokens (~4 bytes per token)
- If <50K tokens total, consider direct execution
- Identify partition boundaries
- Find natural divisions (files, sections, topics)
- Ensure partitions are independent (no cross-dependencies)
- Aim for 3-7 partitions per batch (Claude Code limit: ~10 concurrent)
- Define aggregation strategy
- How will partition results combine?
- What format should subagent outputs use?
- What information must propagate between batches?
Phase 2: Subagent Dispatch
For each batch of partitions:
- Prepare subagent prompts using the template in
references/subagent-prompt-template.md
- Spawn subagents in parallel using the Task tool:
```
Task(subagent_type="general-purpose", description="[partition description]", prompt="...")
Task(subagent_type="Explore", description="[research partition]", prompt="...")
```
- Use appropriate subagent types:
- Explore - For read-only research, file discovery
- general-purpose - For tasks requiring code changes
- Plan - For architecture/design work
- Run in background when appropriate:
- Set run_in_background=true for long-running tasks
- Check results via TaskOutput or Read on output file
Phase 3: Result Aggregation
When subagents complete:
- Collect all results - Read summaries from each subagent
- Validate completeness - Check for error indicators:
- "could not find", "unable to", "failed to"
- Missing expected outputs
- Incomplete coverage of partition
- Merge results using appropriate strategy:
- Union: Combine all findings (research tasks)
- Synthesis: Create unified narrative (analysis tasks)
- Reduce: Aggregate metrics (measurement tasks)
- Identify gaps - What wasn't covered? What needs follow-up?
Phase 4: Iteration (if needed)
If gaps exist:
- Create follow-up partitions for uncovered areas
- Include previous batch context in new subagent prompts
- Spawn next batch with refined focus
- Repeat until complete or max iterations reached