Skip to content

Custom Claude Code Agents

Custom Claude Code Agents are specialized subagents defined by users within the .claude/agents/ directory^[001-TODO__Claude_Code_5种Agent模式_-从顺序流到自主工作流.md]. By creating distinct markdown files for specific roles (such as advisor-researcher.md or code-reviewer.md), users can extend Claude Code's capabilities beyond the default subagents^[001-TODO__Claude_Code_5种Agent模式-_从顺序流到自主工作流.md].

When custom agents are available, Claude Code reads their names and descriptions to automatically match them to relevant tasks, or they can be manually specified for granular control^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

Context and Workflow Patterns

Custom agents are typically utilized within the Split & Merge workflow pattern^[001-TODO__Claude_Code_5种Agent模式_-从顺序流到自主工作流.md]. In this mode, a main agent acts as a hub, splitting a large task into smaller subtasks that are distributed to multiple subagents (spokes)^[001-TODO__Claude_Code_5种Agent模式-_从顺序流到自主工作流.md].

These subagents execute in parallel with isolated context windows, ensuring their work does not interfere with one another^[001-TODO__Claude_Code_5种Agent模式_-从顺序流到自主工作流.md]. Once the subagents complete their specific objectives, the main agent aggregates and synthesizes their outputs into a final result^[001-TODO__Claude_Code_5种Agent模式-_从顺序流到自主工作流.md].

Advanced Patterns: Builder-Validator

Custom agents are instrumental in establishing automated quality control loops, such as the Builder-Validator Chain^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md]. In this setup:

  1. Subagent 1 (Builder): Constructs the code or solution^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  2. Subagent 2 (Validator): Reviews the output against specific standards^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

Communication flows through the main agent, allowing for continuous iteration where the validator's feedback is used to refine the builder's output until quality criteria are met^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

Comparison with Agent Teams

While custom agents define roles, Agent Teams define communication protocols^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

  • Split & Merge (Custom Agents): Subagents cannot communicate directly and must go through the main agent (Hub-and-Spoke model)^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Agent Teams: Agents can communicate directly via a shared task board, though this feature is currently experimental and significantly more resource-intensive^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

Sources

  • 001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md