Skip to content

AI Design Patterns

Last updated:

Developers already share a vocabulary for structure: Observer, Chain of Responsibility, Circuit Breaker, Saga. This page maps that vocabulary onto agent harnesses, names the Claude Code mechanism behind each mapping, and states where the mapping fails.

Status: No standard crosswalk exists. Published mappings agree on some pairs and disagree on others, and none of the sources read for this page maps classic patterns to Claude Code mechanisms except for hooks and CLAUDE.md. Every other Claude Code column entry is this guide’s mapping, marked Our mapping. Mechanisms are checked against the official documentation (last verified 2026-10-27).

Use this page for: explaining an agent design to developers in terms they know, and checking a design against the failure modes each pattern carries. For the components of a harness, see Agent Harness Engineering. For loop and graph contracts, see Loop & Graph Engineering. For patterns inside a single skill, see Skill Design Patterns.

The tables on this page are generated from machine-readable/ai-design-patterns.json by scripts/build-ai-design-patterns.py. Edit the dataset, not the tables.

  1. TL;DR
  2. Lineage
  3. How to read
  4. Crosswalk
  5. Pattern cards
  6. Where the analogy breaks
  7. Native agent patterns
  8. Choose a pattern
  9. Anti-patterns
  10. Classic side
  11. Further reading
  12. Sources

  • The classic patterns in this table still describe agent systems, but the component in the middle is now a model that decides at runtime. A pattern that relied on a fixed order or a guaranteed call needs a deterministic check next to it.
  • In Claude Code, the mappings with the clearest documented mechanism are Observer to hooks, Memento to checkpoints, Mediator to the main conversation coordinating subagents, Bulkhead to subagent context and worktree isolation, and Circuit Breaker to turn and budget limits. Only Observer and Facade are named by a source; the others are this guide’s mapping.
  • Two common assumptions are wrong in detail. Hooks for the same event run in parallel, so they do not form a chain. Checkpoints track Claude’s file edits only, so rewind does not undo shell commands or remote effects.
  • Each pattern card ends with a check you can run.

Three generations of design patterns: objects in 1994 (Observer, Strategy, Command, decided at design time), services in 2003 (Router, Scatter-Gather, Circuit Breaker, Saga, decided at deployment time), and agents in 2024 (Orchestrator-workers, Evaluator-optimizer, Context isolation, decided at runtime by the model).

Three generations of patterns solve the same kind of problem at different scales:

  • Object patterns (Gamma, Helm, Johnson, Vlissides, 1994) describe how objects collaborate inside one program. The structure is fixed when the code is written.
  • Integration and distributed patterns (Hohpe and Woolf’s Enterprise Integration Patterns, 2003, and the resilience patterns that followed) describe how services exchange messages and survive partial failure.
  • Agent patterns (Anthropic’s Building effective agents, 2024, and the catalogs that followed) describe how a harness steers a model that chooses its next action itself.

Jia Huang’s Pattern Evolution frames the third step as the shift from a structure chosen at design time to a decision taken at runtime by a model working with incomplete information. That shift is why each card below carries a failure mode: the classic name describes the structure, and the card states which behavior the harness no longer guarantees.

Practitioners make the same connection on stage. Frank Coyle (UC Berkeley) recalls the 1990s movement: “We now have patterns for agents, but there’s also anti-patterns” (talk, 2:13). Nishant Gupta (Meta Superintelligence Labs) maps the older layer directly: “Distributed systems have solved something similar for decades” (talk, 6:03). On The Pragmatic Engineer, the case is that agents need the guardrails of enterprise patterns: “old patterns are seeming to coming back” (episode, 44:04). Talks for individual patterns are linked from each card under Watch.

Overview of the 29 patterns on this page in six columns: GoF creational (Factory Method, Singleton), GoF structural (Adapter, Composite, Decorator, Facade), GoF behavioral (Chain of Responsibility, Command, Mediator, Memento, Observer, Strategy, Template Method), Enterprise integration (Pipes and Filters, Content-Based Router, Scatter-Gather), Distributed and resilience (Bulkhead, Circuit Breaker, Saga, Sidecar, Event Sourcing), and Agent-native (Orchestrator-workers, Evaluator-optimizer, Plan-then-execute, Context isolation, Context compaction, Progressive disclosure, Deterministic gate, Goal loop).

Each crosswalk row carries two labels.

LabelMeaning
ConsensusTwo or more distinct sources map the classic pattern to the same main agent analogue. A card may add a second reading that refines it.
Single sourceOne source proposes the mapping. Treat it as a proposal.
DivergentSources map the same classic pattern to different agent analogues. The card lists each reading with its source.
Named by a sourceA source names the Claude Code mechanism itself.
Our mappingSources give the generic agent analogue; this guide maps it to Claude Code.

A row enters the table only when three conditions hold: a public source maps the classic pattern to an agent analogue, a documented Claude Code mechanism exists, and a failure mode can be stated. Saga is the one deliberate exception: Claude Code has no native compensation mechanism, and the row documents that gap.

Classic patternFamilyAgent analogueIn Claude CodeEvidenceMapping
Factory MethodGoF creationalSubagent spawning from a named definitionSubagent definitions and the Agent toolConsensusOur mapping
SingletonGoF creationalShared tool registry / Layered memory governance: decide which state is shared, isolated, persisted, or ephemeralCLAUDE.md hierarchy and auto memoryDivergentOur mapping
AdapterGoF structuralTool adapter that exposes an external system to the modelMCP serversConsensusOur mapping
CompositeGoF structuralAn agent that delegates to agents that can delegate againNested subagents (spawn depth)ConsensusOur mapping
DecoratorGoF structuralGuardrail wrapped around a model call / Context-injection middleware that enriches each requestUserPromptSubmit and PostToolUse hooksDivergentOur mapping
FacadeGoF structuralProject instruction file as the single entry point for conventionsCLAUDE.mdSingle sourceNamed by a source
Chain of ResponsibilityGoF behavioralHook or permission pipeline in front of tool calls / Agents chained so each one handles what it can and passes the restPermission rules: deny, then ask, then allowDivergentOur mapping
CommandGoF behavioralA tool call: a named action with structured argumentsTool calls and PreToolUse hooksConsensusOur mapping
MediatorGoF behavioralOrchestrator that coordinates workers which never talk to each otherMain conversation coordinating subagents; Agent teams (experimental, off by default; peer messaging, the non-mediated alternative)ConsensusOur mapping
MementoGoF behavioralCheckpoint and rewind of agent stateCheckpointing and /rewindConsensusOur mapping
ObserverGoF behavioralLifecycle hooks that react to agent eventsHooks (PreToolUse, PostToolUse, Stop, SubagentStop)ConsensusNamed by a source
StrategyGoF behavioralModel or approach selected per task / Runtime strategy switching, with the harness recording why, at what cost, and how to roll backmodel field per subagent and /modelConsensusOur mapping
Template MethodGoF behavioralSystem prompt that defines the steps / Fixed agent-loop skeleton with pluggable stepsSkills that define a procedure; Stop hook as the final step checkDivergentOur mapping
Pipes and FiltersEnterprise integrationPipeline where each agent or model call is a filterPrint mode in a shell pipeline (claude -p)ConsensusOur mapping
Content-Based RouterEnterprise integrationClassifier that sends a request to a specialized handlerAutomatic delegation by subagent description; Skill selection by descriptionConsensusOur mapping
Scatter-GatherEnterprise integrationParallel agents followed by a synthesis stepParallel subagents; Dynamic workflowsConsensusOur mapping
BulkheadDistributed and resiliencePer-agent isolation of context, tools, and budgetSubagent context isolation; isolation: worktreeConsensusOur mapping
Circuit BreakerDistributed and resilienceHard caps on turns, cost, and loop depth / Breakers on tools, models, and the agent’s own loop—max-turns and —max-budget-usd (print mode); maxTurns in subagent frontmatterConsensusOur mapping
SagaDistributed and resilienceCompensating actions for an agent planNo native saga: checkpoints plus scripted compensationConsensusOur mapping
SidecarDistributed and resilienceThe agent harness around the model loopHooks, permissions, and sandboxing around the loopSingle sourceOur mapping
Event SourcingDistributed and resilienceThe trace log as the event stream of an agent runSession transcripts, —resume and —continueSingle sourceOur mapping

Map of the Claude Code harness: the agent loop at the center, surrounded by hooks, permission rules, checkpoints, subagents, MCP servers, skills, CLAUDE.md, and limits. Each part is labeled with the classic pattern it plays: Observer, Chain of Responsibility, Memento, Mediator and Bulkhead, Adapter, Template Method, Facade, and Circuit Breaker.

GoF creational Consensus Our mapping

Factory Method card (GoF creational). Classic: A creator decides which product to build. In Claude Code: Subagent definitions and the Agent tool. Breaks when: A definition without a tools field inherits every tool. Check: Give every write-capable agent an explicit tools allowlist.

  • Classic intent: Let a creator decide which concrete product to instantiate, behind a common interface.
  • Agent side: Subagent spawning from a named definition (AgentPatterns.ai, Esther Aznar, Ivan Garcia Villar)
  • In Claude Code: Subagent definitions and the Agent tool
  • Failure mode: The factory hands every product the full toolbox: a subagent definition without a tools field inherits every tool available to subagents.
  • How to verify: List the tools field of each definition in .claude/agents/ and fail review when a write-capable agent has no explicit allowlist.

GoF creational Divergent Our mapping

Singleton card (GoF creational). Classic: One shared instance with one global access point. In Claude Code: CLAUDE.md hierarchy and auto memory. Breaks when: Parallel writers to one memory file overwrite each other. Check: Append from two sessions at once and look for lost entries.

  • Classic intent: Guarantee one shared instance of a component with a global access point.
  • Agent side, sources disagree:
  • In Claude Code: CLAUDE.md hierarchy and auto memory
  • Failure mode: One shared memory file becomes mutable global state: parallel sessions or agents that write it at the same time can overwrite each other’s entries.
  • How to verify: Run two sessions that both append to the same memory file and check whether either entry is lost.

GoF structural Consensus Our mapping

Adapter card (GoF structural). Classic: Convert one interface into the one a client expects. In Claude Code: MCP servers. Breaks when: Mirroring every endpoint crowds the context with near-duplicate tools. Check: Run /mcp and /context, then defer the tools nobody used.

  • Classic intent: Convert the interface of an existing component into the interface a client expects.
  • Agent side: Tool adapter that exposes an external system to the model (Esther Aznar, Ivan Garcia Villar, Marco Nissen)
  • In Claude Code: MCP servers
  • Failure mode: The adapter mirrors every upstream endpoint, so tool definitions crowd the context and the model picks among near-duplicate tools.
  • How to verify: Run /mcp and /context, then remove or defer the tools that no task in the last sprint used.
  • Watch: Christian Tzolov and Dariusz Jędrzejczyk (Devoxx), Unifying AI integration with Model Context Protocol at 21:02: The speakers explain that each vendor exposes its own APIs through an MCP server layer, a unified wrapper the LLM can use.

GoF structural Consensus Our mapping

Composite card (GoF structural). Classic: Treat one object and a tree of objects alike. In Claude Code: Nested subagents, capped by spawn depth. Breaks when: Each nesting layer multiplies token use. Check: Set the spawn depth explicitly and log every spawned subagent.

  • Classic intent: Treat a single object and a tree of objects through the same interface.
  • Agent side: An agent that delegates to agents that can delegate again (AgentPatterns.ai, Esther Aznar, Ivan Garcia Villar)
  • In Claude Code: Nested subagents (spawn depth)
  • Failure mode: Recursion without a budget: each layer multiplies token use. Claude Code caps nesting with CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH, which can be adjusted but not removed.
  • How to verify: Set CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH explicitly for automated runs and log spawned subagents with a SubagentStop hook.
  • Watch: Clement Escoffier (Devoxx), From LLM orchestration to autonomous agents: Agentic AI patterns with LangChain4j at 112:21: The speakers show an agent in a sequence that is itself a loop of two agents, so a workflow is used like a single sub agent.

GoF structural Divergent Our mapping

Decorator card (GoF structural). Classic: Add behavior by wrapping, in a fixed order. In Claude Code: UserPromptSubmit and PostToolUse hooks. Breaks when: Matching hooks run in parallel, so there is no fixed order. Check: Make each hook pass when it runs alone.

  • Classic intent: Add behavior to an object by wrapping it, without changing its class.
  • Agent side, sources disagree:
  • In Claude Code: UserPromptSubmit and PostToolUse hooks
  • Failure mode: A classic decorator stack has a fixed order. Matching hooks run in parallel, so a wrapper that assumes another wrapper already ran is a race.
  • How to verify: Write each hook so it passes when run alone, and test it with the other hooks disabled.
  • Watch: Mark Pollack, Christian Tzolov, Josh Long, James Ward (Devoxx), Bootiful Spring AI at 11:43: The speaker explains Spring AI advisors as a filter or pre-processor that wraps calls to and from the model and can mutate or log each request.
  • Watch: Thariq Shihipar, Claude Agent SDK [Full Workshop] at 107:10: An Anthropic speaker says hooks fire as events in the Agent SDK and are used for deterministic verification or for inserting context.

GoF structural Single source Named by a source

Facade card (GoF structural). Classic: One simple entry point to a complex subsystem. In Claude Code: CLAUDE.md. Breaks when: CLAUDE.md is context, not enforced configuration. Check: Back each must-never rule with a hook or a deny rule.

  • Classic intent: Offer one simple entry point in front of a complex subsystem.
  • Agent side: Project instruction file as the single entry point for conventions (AgentPatterns.ai)
  • In Claude Code: CLAUDE.md
  • Failure mode: The facade is read as a contract. The docs state that Claude treats CLAUDE.md as context, not enforced configuration: a rule written there is a request, not a guarantee.
  • How to verify: For every must-never rule in CLAUDE.md, add a PreToolUse hook or a deny rule and a test that triggers it.

GoF behavioral Divergent Our mapping

Chain of Responsibility card (GoF behavioral). Classic: Pass a request along handlers until one handles it. In Claude Code: Permission rules: deny, then ask, then allow. Breaks when: Specificity does not win: a broad deny beats a narrow allow. Check: Add a deny and a narrower allow, confirm the command stays blocked.

  • Classic intent: Pass a request along a chain of handlers until one of them handles it.
  • Agent side, sources disagree:
  • In Claude Code: Permission rules: deny, then ask, then allow
  • Failure mode: Teams expect declaration order or rule specificity to decide. The docs state that rules are evaluated deny, then ask, then allow, and specificity does not change that order: a broad deny beats a narrow allow.
  • How to verify: Add a deny and a more specific allow for the same command in a test project and check that the command stays blocked.

GoF behavioral Consensus Our mapping

Command card (GoF behavioral). Classic: Turn a request into an object you can queue, log or check. In Claude Code: Tool calls and PreToolUse hooks. Breaks when: The model writes the arguments, and unchecked they run as written. Check: Replay an out-of-scope tool input and assert the hook blocks it.

  • Classic intent: Turn a request into an object that can be queued, logged, checked, or undone.
  • Agent side: A tool call: a named action with structured arguments (Esther Aznar, Ivan Garcia Villar, Ashish Patel)
  • In Claude Code: Tool calls and PreToolUse hooks
  • Failure mode: The command object is written by the model. Without validation before dispatch, a malformed or out-of-scope argument executes as written.
  • How to verify: Feed a PreToolUse hook a recorded tool input with an out-of-scope path and assert that it blocks.

GoF behavioral Consensus Our mapping

Mediator card (GoF behavioral). Classic: Components talk through one coordinator. In Claude Code: The main conversation coordinating subagents. Breaks when: Workers return transcripts and flood the coordinator's context. Check: Ask each subagent for a bounded final report.

GoF behavioral Consensus Our mapping

Memento card (GoF behavioral). Classic: Snapshot the state and restore it later. In Claude Code: Checkpoints and /rewind. Breaks when: Only Claude's file edits are tracked, not Bash or external changes. Check: Change an untouched file with Bash, rewind, and see it survive.

  • Classic intent: Capture an object’s state so it can be restored later without exposing its internals.
  • Agent side: Checkpoint and rewind of agent state (AgentPatterns.ai, Ashish Patel)
  • In Claude Code: Checkpointing and /rewind
  • Failure mode: The snapshot is partial. The docs state that checkpoints only track changes made through Claude’s file editing tools; Bash commands and external processes are not captured, and edits made by a background subagent usually are not either.
  • How to verify: Use a Bash command to change a file Claude has not edited in this session, rewind, and confirm the change survives. Commit with git before risky shell work or delegated edits.
  • Watch: Hamza Tahir, Your Agents Need a Save Button at 0:14: The speaker argues agents need a save button: runtime checkpoints that let you replay, diff and decide, instead of read-only traces.

GoF behavioral Consensus Named by a source

Observer card (GoF behavioral). Classic: Subscribers are notified when state changes. In Claude Code: Hooks on PreToolUse, PostToolUse, Stop and SubagentStop. Breaks when: Hooks that assume an order, while matching hooks run in parallel. Check: Run each hook alone on a recorded event.

  • Classic intent: Notify subscribers automatically when a subject changes state.
  • Agent side: Lifecycle hooks that react to agent events (AgentPatterns.ai, Esther Aznar, Ivan Garcia Villar)
  • In Claude Code: Hooks (PreToolUse, PostToolUse, Stop, SubagentStop)
  • Failure mode: Subscribers assume an order. The docs state that matching hooks run in parallel, each one runs to completion, and for permission decisions the most restrictive result applies: one hook’s deny does not stop a sibling hook’s side effects.
  • How to verify: Run each hook alone against a recorded event payload; a hook that only passes after another one is not an observer.
  • Watch: Cole Medin, Watch This If Your Coding Agent is Ignoring Your Rules (You Need Hooks) at 0:44: The speaker defines hooks as actions guaranteed to fire on agent events, such as just before a file read or when the conversation stops.

GoF behavioral Consensus Our mapping

Strategy card (GoF behavioral). Classic: Swap the algorithm behind one interface. In Claude Code: The model field per subagent and /model. Breaks when: The model switches silently, with no record of cost or origin. Check: Pin the model per subagent and review /usage after the run.

  • Classic intent: Swap one algorithm for another behind the same interface at runtime.
  • Agent side, main reading first:
  • In Claude Code: model field per subagent and /model
  • Failure mode: The strategy changes silently. Nobody can tell afterwards which model produced which result or what the switch cost.
  • How to verify: Pin model in each subagent definition and check /usage or the session transcript after a run.
  • Watch: Archana Kamath and Tyler Gillam, Preferences Over Benchmarks: Model Routing at 1:46: The speaker argues that one model for every task is overkill and that routing each task to a fitting model cuts cost and risk.

GoF behavioral Divergent Our mapping

Template Method card (GoF behavioral). Classic: A fixed skeleton calls the steps. In Claude Code: Skills that define a procedure, plus a Stop hook. Breaks when: A prose skeleton is not enforced, so steps get skipped. Check: Block completion with a Stop hook when the artifact is missing.

Enterprise integration Consensus Our mapping

Pipes and Filters card (Enterprise integration). Classic: Steps connected by channels, one after another. In Claude Code: claude -p in a shell pipeline. Breaks when: Free text from one step is misread by the next. Check: Use JSON output and validate it between steps.

  • Classic intent: Process a message through a sequence of independent steps connected by channels.
  • Agent side: Pipeline where each agent or model call is a filter (Roan Brasil, Marco Nissen)
  • In Claude Code: Print mode in a shell pipeline (claude -p)
  • Failure mode: A filter emits free text that the next filter misreads, and the error travels down the pipe.
  • How to verify: Use —output-format json between steps and validate the shape before the next filter runs.
  • Watch: Mark Pollack, Christian Tzolov, Josh Long, James Ward (Devoxx), Bootiful Spring AI at 38:11: The speaker pipes git log into claude -p to generate release notes and calls it pipes and filters all over again.
  • Watch: Kevin Dubois and Mario Fusco (Devoxx), Agentic AI Patterns at 8:11: The speakers present the sequence pattern, calling one agent after another, also known as prompt chaining.

Enterprise integration Consensus Our mapping

Content-Based Router card (Enterprise integration). Classic: Route each message by its content. In Claude Code: Delegation and skill selection by description. Breaks when: Overlapping descriptions route the same request differently. Check: Rerun a routing test set after every description change.

Enterprise integration Consensus Our mapping

Scatter-Gather card (Enterprise integration). Classic: Send to many recipients and aggregate the replies. In Claude Code: Parallel subagents and dynamic workflows. Breaks when: The gather step averages contradictions, and cost grows per branch. Check: List disagreements and compare cost with a single agent.

Distributed and resilience Consensus Our mapping

Bulkhead card (Distributed and resilience). Classic: Isolate resources so one failure cannot sink everything. In Claude Code: Subagent context isolation and worktrees. Breaks when: The context is isolated, but the checkout is shared. Check: Give parallel writers their own worktree.

  • Classic intent: Isolate resources per consumer so one failure cannot sink the whole system.
  • Agent side: Per-agent isolation of context, tools, and budget (Esther Aznar, Ivan Garcia Villar, Jia Huang)
  • In Claude Code: Subagent context isolation; isolation: worktree
  • Failure mode: Only the context is isolated. Parallel agents still share one checkout and overwrite each other’s files.
  • How to verify: Give write-capable parallel subagents isolation: worktree and check that git status in the main checkout stays clean during the run.

Distributed and resilience Consensus Our mapping

Circuit Breaker card (Distributed and resilience). Classic: Stop calling a failing dependency and fail fast. In Claude Code: Turn and budget caps on a run. Breaks when: Static caps, often set on one layer only. Check: Run a looping task with both caps and expect an error exit.

Distributed and resilience Consensus Our mapping

Saga card (Distributed and resilience). Classic: Local steps, each with a compensating action. In Claude Code: No native saga: checkpoints plus scripted compensation. Breaks when: Rewind undoes local edits, not a push or an API call. Check: Write and test a compensation for each side effect.

Distributed and resilience Single source Our mapping

Sidecar card (Distributed and resilience). Classic: Cross-cutting policy runs next to the service. In Claude Code: Hooks, permissions and sandboxing around the loop. Breaks when: Policy in the prompt, or a hook that fails open. Check: Name the enforcing layer for every safety rule.

  • Classic intent: Attach cross-cutting capabilities (logging, policy, networking) next to a service instead of inside it.
  • Agent side: The agent harness around the model loop (Jia Huang)
  • In Claude Code: Hooks, permissions, and sandboxing around the loop
  • Failure mode: Policy lives in the prompt instead of the sidecar, so the model can talk itself out of it. A policy hook can also fail open: on most events, a hook that crashes or times out lets the action through unless it sets onFailure: “block”.
  • How to verify: List each safety rule and name the layer that enforces it: hook, permission rule, sandbox, or prompt only. For each policy hook, point it at a missing script and check that the action is blocked.

Distributed and resilience Single source Our mapping

Event Sourcing card (Distributed and resilience). Classic: Store every change as an event, replay to rebuild. In Claude Code: Session transcripts with --resume and --continue. Breaks when: Resuming restores the conversation, not the same answers. Check: Keep the transcript as an audit trail and pin inputs elsewhere.

  • Classic intent: Store every state change as an event, and rebuild state by replaying the log.
  • Agent side: The trace log as the event stream of an agent run (Jia Huang)
  • In Claude Code: Session transcripts, —resume and —continue
  • Failure mode: Replay is assumed to reproduce the result. Resuming a session restores the conversation, but the model calls that follow are not deterministic.
  • How to verify: Treat the transcript as an audit trail, not a replay log: pin the inputs you need to reproduce outside it.
  • Watch: Jonas Templestein, Make your own event-sourced agent harness using stream processors at 1:45: The speaker wants to build a coding agent harness that is purely event sourced, because the agent already keeps a log of events.
  • Watch: Ishaan Sehgal, The Log Is The Agent at 4:19: The speaker argues the log is the durable history from which every view of the agent (debugging, auditing, compaction) is a projection.

Four classic guarantees and what replaces them in an agent harness: a decorator stack with a fixed order becomes hooks that run in parallel; a memento that restores everything becomes checkpoints that track file edits only; an event log that replays becomes a transcript that resumes but does not reproduce; a facade that enforces becomes a CLAUDE.md file read as context.

Every break below has the same root: a classic pattern assumes the component in the middle executes what it is given, and a model does not.

Order is not guaranteed. A decorator stack and a chain of handlers run in a known order. Claude Code runs the matching hooks for one event in parallel, and for permission decisions the most restrictive result applies (hooks reference). Every matching hook runs to completion, so one hook’s deny does not stop the side effects of another. Write each hook so it is correct alone. Permission rules, by contrast, are evaluated in a documented order: deny, then ask, then allow, with specificity not changing that order (permissions).

Restore is partial. A memento captures the whole state it needs. Checkpoints only track changes made through Claude’s file editing tools; changes made through Bash commands or external processes are not captured (checkpointing). Edits made by a background subagent are usually outside the checkpoints too: rewinding restores only the files Claude had already edited in the conversation. For anything outside that scope, the Saga question applies: what is the compensating action, and who runs it?

Replay does not reproduce. An event-sourced system rebuilds the same state from the same log. A resumed Claude Code session restores the conversation, and the model calls that follow can differ. Keep the transcript as an audit trail, and pin elsewhere the inputs you need to reproduce a result.

Prose does not enforce. A template method calls its steps; a facade hides the subsystem behind a contract. A skill that lists steps, or a CLAUDE.md file that states rules, is context the model reads. The docs say so directly: Claude treats CLAUDE.md as context, not enforced configuration, and points to a PreToolUse hook to block an action regardless of what Claude decides (memory).

Observers can veto. A classic observer is notified and cannot change what its subject does. A PreToolUse hook can block the tool call it observes, so a hook is closer to a guard than to a listener. The veto only goes one way: a hook that returns allow does not bypass permission rules, and a matching deny or ask rule still applies (permissions).

Guards fail open. A classic guard that throws stops the request. On most events, a Claude Code hook that crashes, cannot start, or times out lets the action through, so a policy hook with a wrong path enforces nothing. Set "onFailure": "block" on a command or HTTP hook to reverse that, available from Claude Code v2.1.295 (hooks reference).

Limits are static. A classic circuit breaker opens after repeated failures and closes again after a cool-down. --max-turns, --max-budget-usd, and maxTurns are fixed caps set before the run (CLI reference): they bound a loop, they do not detect a failing dependency.

The wrapper is probabilistic too. Several sources map Decorator to guardrails or to context injection. A guardrail that is itself a model call inherits the uncertainty it is meant to contain. Keep at least one deterministic check on any path that must not fail.

These patterns sit close to classic ones, but they depend on two things classic patterns never had to manage: a context window as the scarce resource, and a model as the decision-maker. Where a crosswalk row covers a similar mechanism, the card names the closest classic pattern and what changes.

Orchestrator-workers card (agent-native pattern). What it does: A model splits the task at runtime, delegates, and synthesizes. In Claude Code: Subagents and dynamic workflows. What is new: The model draws the decomposition, and it pays on parallel work.

A central model breaks a task down at runtime, delegates the parts, and synthesizes the results.

Evaluator-optimizer card (agent-native pattern). What it does: One call answers, another evaluates and sends feedback. In Claude Code: A reviewer subagent and a Stop hook that runs the real tests. What is new: The judge is a model, so both sides can accept a wrong answer.

One call produces an answer, another evaluates it and sends feedback, in a loop.

Plan-then-execute card (agent-native pattern). What it does: Plan read-only before any file changes. In Claude Code: Plan mode. What is new: The same model executes the plan, so review the plan.

Separate a read-only planning phase from the phase that changes files.

Context isolation card (agent-native pattern). What it does: Run a noisy side task in its own context and return the conclusion. In Claude Code: Subagents return only their final response. What is new: The protected resource is the context window.

Run a noisy side task in its own context and return only its conclusion.

Context compaction card (agent-native pattern). What it does: Summarize near the window limit and continue from the summary. In Claude Code: Auto compaction and /compact. What is new: Lossy by design: what the summary drops is gone.

Summarize the conversation when it approaches the window limit, and continue from the summary.

Progressive disclosure card (agent-native pattern). What it does: Short descriptions first, full instructions on demand. In Claude Code: Skills and MCP tool search. What is new: A vague description hides a capability.

Load short descriptions first and the full instructions only when they are needed.

Deterministic gate card (agent-native pattern). What it does: What must always happen runs outside the model. In Claude Code: PreToolUse hooks and deny rules. What is new: Draw the line between suggestion and enforcement on purpose.

Put anything that must always happen in code that runs outside the model’s judgment.

Goal loop card (agent-native pattern). What it does: Keep working until a stated condition is met. In Claude Code: /goal and Stop hook continuation. What is new: A model judges the goal, so make it checkable.

Keep the agent working until a stated completion condition is met.

Pick by the shape of the problem, then use the simplest structure that passes its check, as Anthropic’s guidance recommends.

Yes

Yes

No

No

Yes

No

Yes

No

Yes

No

New task for the agent

Are the steps known

before the run?

Can each step's output

be validated by code

before the next step?

Pipes and Filters

claude -p in a pipeline

Template Method

skill + Stop hook check

Does the input decide

which specialist runs?

Content-Based Router

subagent descriptions

Can the work split into

independent parts?

Scatter-Gather

parallel subagents + synthesis

Is there a clear

quality criterion?

Evaluator-optimizer

reviewer subagent + tests

Orchestrator-workers

plan mode first

Add Bulkhead:

isolation: worktree for writers

Yes

Yes

No

No

Yes

No

Yes

No

Yes

No

New task for the agent

Are the steps known

before the run?

Can each step's output

be validated by code

before the next step?

Pipes and Filters

claude -p in a pipeline

Template Method

skill + Stop hook check

Does the input decide

which specialist runs?

Content-Based Router

subagent descriptions

Can the work split into

independent parts?

Scatter-Gather

parallel subagents + synthesis

Is there a clear

quality criterion?

Evaluator-optimizer

reviewer subagent + tests

Orchestrator-workers

plan mode first

Add Bulkhead:

isolation: worktree for writers

Three questions apply to every branch, whatever the pattern:

  • Which side effects leave the machine? Each one needs a written compensating action (Saga), because rewind will not undo it.
  • Which rules must never be broken? Each one needs a deterministic gate (a PreToolUse hook or a deny rule), because a prompt does not enforce anything.
  • What stops the run? Every automated branch needs a Circuit Breaker: a turn limit and a budget limit, set before the run.

Failure map: ten harness anti-patterns grouped in four columns. Specification and design: prompt as enforcement, unbounded loop, step repetition. Inter-agent misalignment: context flooding, unguarded shared checkout. Task verification: unverified done. Harness mechanics: rewind as rollback, ordered hooks assumption, specific allow overrides deny, untrusted content as instructions.

The first three categories come from the MAST taxonomy of multi-agent failures (Cemri et al.), which groups 14 failure modes into three categories: specification issues, inter-agent misalignment, and task verification (labels shortened in the table). The fourth category covers Claude Code mechanics that MAST does not address. The assignment of each anti-pattern to a category is this guide’s reading.

Anti-patternSymptomFixCategoryRelated patterns
Prompt as enforcementA must-never rule lives only in CLAUDE.md or a system prompt.Deterministic gate: a PreToolUse hook with onFailure: “block”, or a deny rule, with a test.Specification issuesDeterministic gate, Facade
Context floodingWorkers return full transcripts or logs to the coordinating thread.Context isolation: ask each worker for a bounded final report.Inter-agent misalignmentContext isolation, Mediator
Unbounded loopAn automated run has no turn, cost, or depth limit.Circuit breaker on every layer: —max-turns, —max-budget-usd, maxTurns, spawn depth.Specification issuesCircuit Breaker, Composite
Unverified doneThe agent declares success without running a check, or stops early.Evaluator-optimizer with a real test, enforced by a Stop hook.Task verificationEvaluator-optimizer, Template Method
Step repetitionThe agent redoes completed steps after an interruption or a reset of the conversation.Durable progress outside the context (a task list or a file) and idempotent side effects.Specification issuesEvent Sourcing, Saga
Rewind as rollbackA team counts on /rewind to undo shell commands or remote effects.Saga thinking: git commits before risky work, a written compensation for each external effect.Harness mechanics (beyond MAST)Memento, Saga
Ordered hooks assumptionA hook relies on another hook for the same event having run first.Independent observers: each hook passes or blocks on its own.Harness mechanics (beyond MAST)Observer, Decorator
Specific allow overrides denyA narrow allow rule is added to punch a hole in a broad deny.Permission rules are evaluated deny, then ask, then allow: narrow the deny instead.Harness mechanics (beyond MAST)Chain of Responsibility
Unguarded shared checkoutParallel write-capable agents edit the same working tree.Bulkhead: isolation: worktree per writing agent.Inter-agent misalignmentBulkhead, Scatter-Gather
Untrusted content as instructionsFetched pages, issue text, or tool output are allowed to steer the agent’s next action.Trust boundary: treat external content as data, and keep write and network tools behind permission rules.Harness mechanics (beyond MAST)Sidecar, Command

The guide already ships a skill that detects the 23 GoF patterns in a codebase: examples/skills/design-patterns/, described in Example 3: Design Patterns Analyzer Skill. Use it on the code an agent produces; use this page on the harness that produces it.

Practitioner writing and repositories that cover the same ground from other angles. None of them uses this page’s crosswalk; the related links point to the closest card here.

Licenses differ. Text and diagrams from sources without a stated license are cited and linked, never copied. Several widely shared repositories that describe Claude Code design patterns are built from leaked source code; they are excluded, and every Claude Code mechanism on this page is sourced from the official documentation only.

Crosswalks and catalogs

Papers

Vendor guidance and articles

Talks

Classic references

Claude Code documentation