Split & Merge Pattern (Claude Code)¶
The Split & Merge Pattern (Pattern 3) is an agent workflow architecture within Claude Code where the system automatically breaks down a complex task into subtasks to be executed in parallel by multiple subagents^[001-TODO__Claude_Code_5种Agent模式_-从顺序流到自主工作流.md]. This pattern is designed to improve efficiency for complex tasks that can be divided into independent units without requiring inter-agent communication^[001-TODO__Claude_Code_5种Agent模式-_从顺序流到自主工作流.md].
Architecture & Workflow¶
The Split & Merge Pattern operates on a Hub-and-Spoke model^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
- Split Phase: The user provides a single task to the Main Agent. The Main Agent analyzes the task and automatically determines the optimal strategy to split it.
- Parallel Execution: The Main Agent spawns multiple subagents (up to 10 simultaneously)^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md]. Each subagent works on its assigned subtask within an independent context window.
- Merge Phase: Once the subagents complete their work, the Main Agent aggregates their outputs.
- Synthesis: The Main Agent synthesizes the results into a unified, comprehensive answer for the user^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
A key constraint of this pattern is that subagents cannot communicate directly with each other; they must route any information through the Main Agent^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
Custom Subagents¶
Users can define custom subagents by creating markdown files in the .claude/agents/ directory^[001-TODO__Claude_Code_5种Agent模式_-从顺序流 to 自主工作流.md]. Claude Code reads the names and descriptions of these agents to automatically match them to relevant parts of a task, though users can also manually specify which agent to use^[001-TODO__Claude_Code_5种Agent模式-_从顺序流 to 自主工作流.md].
# Directory Structure
.claude/agents/
├── advisor-researcher.md
├── code-reviewer.md
└── test-writer.md
Builder-Validator Chain¶
A common implementation of the Split & Merge pattern is the Builder-Validator Chain^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
- Sub 1 (Builder): Responsible for generating code or content.
- Sub 2 (Validator): Responsible for reviewing and auditing the output from the Builder.
- Main Agent: Facilitates the loop, receiving the code from the Builder and passing it to the Validator, then iterating if necessary^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
This creates an automated loop for construction and quality assurance within a single session^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
Comparison to Other Patterns¶
The Split & Merge pattern fits between the manual coordination of the [[Operator Pattern]] and the full autonomous team collaboration of [[Agent Teams Pattern]]^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
- Vs. Agent Teams: Unlike Agent Teams, Split & Merge agents cannot communicate directly with each other and rely on a shared task list^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
- Token Consumption: It generally consumes fewer tokens than Agent Teams but more than a simple sequential flow^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md].
Sources¶
001-TODO__Claude_Code_5种Agent模式_-_从顺序流 to 自主工作流.md
Related Concepts¶
- [[Claude Code]]
- [[Agent Teams Pattern]]
- [[Operator Pattern]]
- [[Sequential Flow]]
- [[Headless Pattern]]
- [[Hub-and-Spoke Model]]
- [[Parallel Computing]]