Module 07: Advanced Patterns
Last updated:
Time: 2-3 hours | Complexity: ⭐⭐⭐ Advanced
Orchestrate multi-agent workflows. Build complex automation that coordinates multiple specialized agents.
What you’ll learn
Section titled “What you’ll learn”- Multi-agent architecture patterns
- Orchestration strategies
- Error handling and recovery
- Production-grade automation
- Team workflows
- Real-world scenarios
Multi-agent systems
Section titled “Multi-agent systems”A multi-agent system is when multiple specialized agents work together on one goal.
Before choosing a team pattern, separate the layers: the model produces tokens, a runtime harness owns a session’s model-and-tool loop, the repository harness supplies instructions and verification, and an orchestrator coordinates sessions. Agent Harness Engineering explains that model; the Agent Harness Map compares loop-owning runtimes and keeps the broader directory separate. Use Agent Tools: Beyond Claude Code for frameworks and control planes, the glossary for terms, Agent Evaluation to score the result, Session Observability to inspect execution, and Security Hardening before running work unattended.
Example: Code release workflow
Section titled “Example: Code release workflow”Instead of one Claude handling everything:
You: "Release version 3.5.0" ↓ ├─→ [Version Agent] Updates VERSION file │ ├─→ [Changelog Agent] Creates release notes │ ├─→ [Test Agent] Runs full test suite │ ├─→ [Security Agent] Security audit │ ├─→ [Docs Agent] Updates documentation │ └─→ [Release Agent] Tags, builds, publishes
Result: Complete, tested, documented releaseEach agent is fast at its specialized task.
Orchestration patterns
Section titled “Orchestration patterns”Pattern 1: Sequential (pipeline)
Section titled “Pattern 1: Sequential (pipeline)”Agents run one after another. Output of agent N becomes input to agent N+1.
Input ↓[Agent 1: Parse Requirements] → Output: structured requirements ↓[Agent 2: Design Schema] → Output: database schema ↓[Agent 3: Generate Code] → Output: code skeleton ↓[Agent 4: Write Tests] → Output: test suite ↓Final ResultWhen to use: Workflows where each step depends on the previous.
Example:
Use the requirements-parser subagent to parse the feature request into specifications
# Later, once we have specifications:Use the database-designer subagent to design the schema based on these specs
# Once schema is approved:Use the code-generator subagent to generate models based on the schemaPattern 2: Parallel (fork-join)
Section titled “Pattern 2: Parallel (fork-join)”Multiple agents work simultaneously, results combined.
Input ↓ ┌──────┼──────┐ ↓ ↓ ↓ [Unit [Int. [Sec. Tests] Tests] Audit] ↓ ↓ ↓ └──────┼──────┘ ↓ Combine Results ↓ Final ReportWhen to use: Independent checks or tasks.
Example:
Request: "Review my code changes using separate subagents for quality, security, test coverage and performance, in parallel"
Parallel tasks:- Code quality agent reviews- Security agent scans- Test coverage agent checks- Performance agent analyzes
(Claude can start independent subagents at the same time, and each works in its own context window)
Results combined into one reportPattern 3: Conditional (if-then)
Section titled “Pattern 3: Conditional (if-then)”Route to different agents based on conditions.
Input: "Fix the bug" ↓[Analyzer: Is it security?] ├─ YES → [Security Agent] ├─ PERFORMANCE → [Performance Agent] └─ LOGIC → [Logic Agent] ↓ResultExample:
Use the bug-classifier subagent to categorize this bug: security, performance, or logic
# Based on response:# If security:Use the security-patcher subagent to fix the security vulnerability
# If performance:Use the perf-optimizer subagent to optimize this codeBuilding a release workflow
Section titled “Building a release workflow”Scenario
Section titled “Scenario”You want to automate your release process. Right now you:
- Update VERSION file
- Update CHANGELOG
- Run tests
- Run security scan
- Create git tag
- Push to origin
- Deploy to staging
Solution: Multi-Agent workflow
Section titled “Solution: Multi-Agent workflow”Step 1: Create agents (each specializes in one task)
.claude/agents/version-manager.md:
---name: version-managerdescription: Manages version files and tagstools: Read, Edit, Write, Bash---
# Version Manager
## PurposeUpdate VERSION files and create git tags locally. Never push: the release-publisher step owns publishing.
(The `tools` list does not stop `git push`, because `Bash` runs any command. Enforce "no push" outside the prompt: a `permissions.deny` rule such as `Bash(git push *)` in settings, or a `PreToolUse` hook, and scope it to the agents that must not publish.)
## Tasks- Bump version (patch, minor, major)- Update VERSION file- Update version in package.json, pyproject.toml, etc- Create annotated git tags.claude/agents/changelog-generator.md:
---name: changelog-generatordescription: Generates release notes---
# Changelog Generator
## PurposeCreate readable release notes from commits
## Output Format- Version header- Breaking changes (if any)- New features- Bug fixes- Deprecations.claude/agents/test-validator.md:
---name: test-validatordescription: Runs full test suite---
# Test Validator
## PurposeExecute all tests and verify coverage
## Minimum Requirements- All tests pass- Coverage >80%- No flaky tests.claude/agents/release-publisher.md:
---name: release-publisherdescription: Publishes and deploys---
# Release Publisher
## PurposeTag and push to origin
## Steps1. Create git tag2. Push to origin3. Trigger CI/CD pipeline4. Monitor deploymentStep 2: Create a release workflow skill
Custom commands are now skills: a folder under .claude/skills/ whose name becomes the slash command. (Existing .claude/commands/<name>.md files keep working.)
.claude/skills/release-workflow/SKILL.md:
---name: release-workflowdescription: Orchestrate a complete release processdisable-model-invocation: true---
Orchestrate a complete release. The bump type is: $ARGUMENTS (patch, minor or major).
## Process
1. Validate release readiness2. Update version (version-manager subagent)3. Generate changelog (changelog-generator subagent)4. Run tests (test-validator subagent)5. Security scan (security-auditor subagent)6. Publish and deploy (release-publisher subagent), only after I confirm
## Requirements- All tests passing- No outstanding security issues- Changelog updateddisable-model-invocation: true keeps Claude from starting a release on its own: only you can type /release-workflow.
Step 3: Use the workflow
/release-workflow patchClaude then:
- Delegates to version-manager → updates VERSION
- Delegates to changelog-generator → creates release notes
- Delegates to test-validator → verifies tests pass
- Delegates to security-auditor → scans for vulnerabilities
- Delegates to release-publisher → creates tag, pushes (after your confirmation)
- You review the result of each step
The step order here is guidance to the model, not a guarantee. If a gate must never be skipped (for example “no push before tests pass”), enforce it in a script, hook or CI job.
Error handling in multi-agent systems
Section titled “Error handling in multi-agent systems”Pattern: Graceful degradation
Section titled “Pattern: Graceful degradation”If one agent fails, others continue:
[Test Agent] ❌ FAILED: 3 test failures ↓[Security Agent] ✅ PASSED: No vulnerabilities ↓[Docs Agent] ✅ PASSED: Docs updated ↓[Aggregate Results] ⚠️ Release blocked (tests failed) ✅ Security passed ✅ Docs ready [Instructions to fix tests first]Pattern: Retry on failure
Section titled “Pattern: Retry on failure”For transient failures (network, timeouts), retry the real check from a script. Slash commands cannot be called from a bash script; the script runs the actual command (here npm test) and uses claude -p only when you want Claude’s judgment:
#!/bin/bash# Release helper script (not a hook)
max_retries=3retry=0
while [ $retry -lt $max_retries ]; do if npm test; then echo "✅ Tests passed" exit 0 fi
retry=$((retry + 1)) if [ $retry -lt $max_retries ]; then echo "⚠️ Retry $retry/$max_retries" sleep 5 fidone
echo "❌ Tests failed after $max_retries attempts"claude -p "Use the test-validator subagent to summarize why the tests keep failing" || trueexit 1Gate on the real command’s exit code. The exit code of claude -p says whether Claude ran, not whether your tests passed.
Pattern: Rollback on error
Section titled “Pattern: Rollback on error”If something goes wrong, undo only what the release created:
#!/bin/bash# Rollback helper (script, not a hook)
START_SHA=$(git rev-parse HEAD)NEW_TAG=""
cleanup_and_exit() { echo "Rolling back..." # Discard uncommitted release edits, keep unrelated work intact git restore VERSION CHANGELOG.md # Remove the tag only if this run created it [ -n "$NEW_TAG" ] && git tag -d "$NEW_TAG" # Undo a release commit made by this run (history is kept, nothing is force-reset) [ "$(git rev-parse HEAD)" != "$START_SHA" ] && git revert --no-edit "$START_SHA"..HEAD exit 1}
# Run release steps (non-interactive Claude call for the bump, real commands for the checks)if ! claude -p "Use the version-manager subagent to bump the patch version"; then cleanup_and_exitfi
if ! npm test; then cleanup_and_exitfi
# If we get here, release succeededexit 0Avoid git reset --hard in a rollback helper: it also discards unrelated uncommitted work.
Production patterns
Section titled “Production patterns”Pattern 1: Staged rollout
Section titled “Pattern 1: Staged rollout”Release to different environments progressively:
/release major ↓[Dev] Deploy and test ✅ Verified ↓[Staging] Deploy and test ✅ Verified ↓[Prod] Deploy with monitoring ✅ Monitoring green ↓Release CompletePattern 2: Approval gates
Section titled “Pattern 2: Approval gates”Block advancement until reviewed. A hook cannot prompt in the terminal: its standard input carries JSON, not your keyboard. Use a PreToolUse hook to make Claude Code ask you instead.
.claude/hooks/pre-prod-deploy.sh:
#!/bin/bash# Ask for confirmation before any production deploy commandinput=$(cat)command=$(printf '%s' "$input" | jq -r '.tool_input.command // empty')
case "$command" in *"deploy --env prod"*) jq -n '{hookSpecificOutput: {hookEventName: "PreToolUse", permissionDecision: "ask", permissionDecisionReason: "Production deploy: confirm tests and security checks passed"}}' ;;esacexit 0Register it in .claude/settings.json under hooks.PreToolUse with "matcher": "Bash" and "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pre-prod-deploy.sh" (see Module 06 for the registration shape). Claude Code then shows its normal permission prompt with your reason. Use "deny" instead of "ask" to block outright.
Pattern 3: Monitoring & rollback
Section titled “Pattern 3: Monitoring & rollback”After deployment, verify health with a script that your release workflow runs:
#!/bin/bash# post-deploy-check.sh (called by the release workflow, not a Claude Code hook event)
sleep 10 # Let services start
# Health checksif ! curl -f https://api.example.com/health; then echo "❌ Health check failed" echo "Rolling back..." git revert -n HEAD git commit -m "Rollback: deployment health check failed" exit 1fi
echo "✅ Deployment successful and healthy"exit 0Exercise: Build your first multi-agent workflow
Section titled “Exercise: Build your first multi-agent workflow”Scenario
Section titled “Scenario”You have a data science project. Release checklist:
- Update model version
- Run validation tests
- Generate performance report
- Update documentation
- Create release tag
Step 1: Create agents
Section titled “Step 1: Create agents”Create .claude/agents/ with (each file needs name, description and, ideally, a tools list):
model-versioner.md- Updates VERSION, model metadatavalidator.md- Runs validation testsreport-generator.md- Creates performance metricsdoc-updater.md- Updates README, API docsrelease-tagger.md- Creates git tag
Step 2: Create the orchestration skill
Section titled “Step 2: Create the orchestration skill”.claude/skills/ml-release/SKILL.md:
---name: ml-releasedescription: Release a new model versiondisable-model-invocation: true---
Release a new model version. Bump type: $ARGUMENTS (major, minor or patch).
## Workflow1. model-versioner subagent bumps version2. validator subagent runs test suite3. report-generator subagent generates metrics4. doc-updater subagent updates documentation5. release-tagger subagent creates release tagStep 3: Test it
Section titled “Step 3: Test it”/ml-release patchWatch as Claude delegates each step to its subagent. Review each result before the tag step.
Best practices for advanced systems
Section titled “Best practices for advanced systems”✅ Design agents to be composable (outputs fit into next agent)
✅ Log everything (helps debug failures)
✅ Test workflows on small changes first
✅ Document the orchestration flow (so others understand)
✅ Build in approval gates for risky operations
✅ Monitor after automation (verify success)
❌ Chain too many agents (>7 becomes hard to debug)
❌ Make agents interdependent (prefer loose coupling)
❌ Skip error handling (things will fail)
❌ Deploy automated releases without testing workflow first
❌ Assume agents will always agree (build conflict resolution)
Validation: You’re ready if…
Section titled “Validation: You’re ready if…”✓ You can explain multi-agent orchestration patterns
✓ You’ve created at least 2-3 cooperating agents
✓ You understand error handling strategies
✓ You know how to design workflows with approval gates
✓ You could build a release automation for your project
What’s next?
Section titled “What’s next?”You’ve completed the 7-module learning path! You now understand:
- ✅ Installation and setup
- ✅ Core loop and context
- ✅ Memory and configuration
- ✅ Agent specialization
- ✅ Skills and knowledge
- ✅ Hooks and automation
- ✅ Advanced orchestration
Next steps
Section titled “Next steps”Option A: Deep Dive into a Domain
- Go deeper into security:
guide/security/ - Go deeper into DevOps:
guide/ops/ - Go deeper into architecture:
guide/core/architecture.md
Option B: Build Something
- Create a multi-agent workflow for your project
- Implement one of the exercises from this path
- Build a plugin bundle and share with team
Option C: Learn from Examples
- Review production agents in
examples/agents/ - Study plugin bundles in
examples/plugins/ - Explore skills in
guide/core/skill-design-patterns.md
Option D: Self-Assess
- Take
/self-assessment comprehensiveto find gaps - Get personalized recommendations
- Create a learning plan for weak areas
Completed Module 07? → You’re a Claude Code power user.
Explore the full guide at guide/ultimate-guide.md for depth, or teach others what you’ve learned.