Skip to content

Claude Code Agent Patterns

Claude Code Agent Patterns refers to a spectrum of five distinct workflow patterns for utilizing Claude Code, ranging from manual single-terminal control to fully autonomous multi-agent systems^[001-TODO__Claude_Code_5种Agent模式_-从顺序流到自主工作流.md]. These patterns allow users to scale complexity from simple sequential tasks to sophisticated, team-based collaboration or fully automated background processes^[001-TODO__Claude_Code_5种Agent模式-_从顺序流到自主工作流.md].

Background: Built-in Subagents

Claude Code utilizes built-in subagents automatically to manage context and cost efficiency^[001-TODO__Claude_Code_5种Agent模式_-从顺序流到自主工作流.md]. Even in basic conversations, the system may route tasks to specialized subagents, each with its own independent context window to prevent pollution of the main session^[001-TODO__Claude_Code_5种Agent模式-_从顺序流到自主工作流.md].

Subagent Model Role Trigger
Explore Haiku Read-only: File searching, directory structure Auto-detected
Plan Haiku Read-only: Codebase research and planning /plan or Shift+Tab x2
General Purpose Sonnet Full Read/Write: Complex multi-step tasks Auto-detected

The 5 Patterns

The patterns are organized by increasing levels of complexity and autonomy^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

1. Sequential Flow

The foundational pattern where tasks are executed one after another in a single terminal^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

  • Structure: Task 1 → Task 2 → Task 3 (Context accumulates continuously).
  • Constraint: Susceptible to "Context Rot" as the token limit approaches, causing the model to lose track of earlier information^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Management: Mitigated using skills, /compact (summarization), and /clear (reset).
  • Best For: Tasks with linear dependencies where step N relies on the output of step N-1.

2. Operator (Manual Orchestration)

A parallelization pattern where the human operator manages multiple isolated terminal instances^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

  • Structure: Multiple independent terminals (e.g., "Feature A", "Bug Fix B") coordinated manually by the user.
  • Mechanism: Uses claude -w "task name" to create isolated git worktrees and branches for each stream^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Best For: Independent parallel tasks (e.g., fixing a bug while redesigning a settings page) where the user requires maximum control.
  • Limit: Becomes difficult to manage beyond 4–5 terminals^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

3. Split & Merge

A pattern allowing a single Claude Code session to distribute work to multiple subagents concurrently^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

  • Structure: Hub-and-Spoke model. The Main Agent splits a task into sub-tasks assigned to up to 10 subagents (or more, per internal comments). Results are merged back into the main context^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Communication: Subagents cannot communicate directly; they interact only via the Main Agent.
  • Variations:
    • Custom Agents: Users can define specific agent behaviors (e.g., code-reviewer.md, test-writer.md) in the .claude/agents/ directory^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
    • Builder-Validator Chain: A loop where one subagent builds code and a second validates it, mediated by the main agent^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Best For: Complex tasks that can be broken down into independent components requiring synthesis.

4. Agent Teams

An experimental pattern where multiple full Claude Code instances collaborate directly via a shared task board^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

  • Structure: A Team Lead coordinates with agents (e.g., Frontend, Backend, Test) who share a unified task list but maintain independent context windows^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Communication: Agents can communicate directly, or users can bypass the Team Lead to message specific agents using navigation commands (e.g., Shift+Up/Down)^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Enabling: Requires enabling claudeCodeExperimentalAgentTeams in settings.json^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Warning: Token consumption is significantly higher (4–7x a normal session).
  • Best For: Complex cross-domain projects (e.g., full-stack features) requiring tight inter-role collaboration.

5. Headless (Autonomous Workflow)

A fully automated pattern where Claude executes tasks without a human-in-the-loop interface^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].

  • Mechanism: Uses the -p flag to pass a prompt directly to the CLI without opening an interactive session^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Scheduling: Can be combined with system tools like cron for recurring tasks (e.g., automated daily reports)[^001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Safety: Recommended only for tasks where outputs are easily verifiable or reversible. Permission flags (e.g., --allowed-tools) can restrict capabilities to read-only operations^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md].
  • Best For: Routine maintenance, content generation pipelines, or scheduled batch processing.

Decision Guide

Selecting the appropriate pattern depends on task dependencies and complexity^[001-TODO__Claude_Code_5种Agent模式_-_从顺序流到自主工作流.md]:

  1. Are there dependencies?
    • Yes: Start with Pattern 1 (Sequential). If context fills up, move to Pattern 2 (Operator).
    • No: Can the task be split?
  2. Can it be split?
    • Yes, independent parts: Use Pattern 3 (Split & Merge).
    • Yes, needs collaboration: Use Pattern 4 (Agent Teams).
    • No: Can it run unattended? Use Pattern 5 (Headless).
  • [[AI Agent]]
  • 20/80 Learning Principle: Applicable here; users need only master a subset of these patterns (the 20%) to handle 80% of workflows.
  • [[Prompt Engineering]]

Sources

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