// Coordinate multiple agents in parallel or sequential workflows. Use when running agents simultaneously, delegating to sub-agents, switching between specialized agents, or managing agent selection. Trigger keywords - "parallel agents", "sequential workflow", "delegate", "multi-agent", "sub-agent", "agent switching", "task decomposition".
| name | multi-agent-coordination |
| description | Coordinate multiple agents in parallel or sequential workflows. Use when running agents simultaneously, delegating to sub-agents, switching between specialized agents, or managing agent selection. Trigger keywords - "parallel agents", "sequential workflow", "delegate", "multi-agent", "sub-agent", "agent switching", "task decomposition". |
| version | 0.1.0 |
| tags | ["orchestration","multi-agent","parallel","sequential","delegation","coordination"] |
| keywords | ["parallel","sequential","delegate","sub-agent","agent-switching","multi-agent","task-decomposition","coordination"] |
Version: 1.0.0 Purpose: Patterns for coordinating multiple agents in complex workflows Status: Production Ready
Multi-agent coordination is the foundation of sophisticated Claude Code workflows. This skill provides battle-tested patterns for orchestrating multiple specialized agents to accomplish complex tasks that are beyond the capabilities of a single agent.
The key challenge in multi-agent systems is dependencies. Some tasks must execute sequentially (one agent's output feeds into another), while others can run in parallel (independent validations from different perspectives). Getting this right is the difference between a 5-minute workflow and a 15-minute one.
This skill teaches you:
When to Use Sequential:
Use sequential execution when there are dependencies between agents:
Example: Multi-Phase Implementation
Phase 1: Architecture Planning
Task: api-architect
Output: ai-docs/architecture-plan.md
Wait for completion โ
Phase 2: Implementation (depends on Phase 1)
Task: backend-developer
Input: Read ai-docs/architecture-plan.md
Output: src/auth.ts, src/routes.ts
Wait for completion โ
Phase 3: Testing (depends on Phase 2)
Task: test-architect
Input: Read src/auth.ts, src/routes.ts
Output: tests/auth.test.ts
When to Use Parallel:
Use parallel execution when agents are independent:
Example: Multi-Perspective Validation
Single Message with Multiple Task Calls:
Task: designer
Prompt: Validate UI against Figma design
Output: ai-docs/design-review.md
---
Task: ui-manual-tester
Prompt: Test UI in browser for usability
Output: ai-docs/testing-report.md
---
Task: senior-code-reviewer
Prompt: Review code quality and patterns
Output: ai-docs/code-review.md
All three execute simultaneously (3x speedup!)
Wait for all to complete, then consolidate results.
The 4-Message Pattern for True Parallel Execution:
This is CRITICAL for achieving true parallelism:
Message 1: Preparation (Bash Only)
- Create workspace directories
- Validate inputs
- Write context files
- NO Task calls, NO TodoWrite
Message 2: Parallel Execution (Task Only)
- Launch ALL agents in SINGLE message
- ONLY Task tool calls
- Each Task is independent
- All execute simultaneously
Message 3: Consolidation (Task Only)
- Launch consolidation agent
- Automatically triggered when N agents complete
Message 4: Present Results
- Show user final consolidated results
- Include links to detailed reports
Anti-Pattern: Mixing Tool Types Breaks Parallelism
โ WRONG - Executes Sequentially:
await TodoWrite({...}); // Tool 1
await Task({...}); // Tool 2 - waits for TodoWrite
await Bash({...}); // Tool 3 - waits for Task
await Task({...}); // Tool 4 - waits for Bash
โ
CORRECT - Executes in Parallel:
await Task({...}); // Task 1
await Task({...}); // Task 2
await Task({...}); // Task 3
// All execute simultaneously
Why Mixing Fails:
Claude Code sees different tool types and assumes there are dependencies between them, forcing sequential execution. Using a single tool type (all Task calls) signals that operations are independent and can run in parallel.
Task Detection Logic:
Intelligent workflows automatically detect task type and select appropriate agents:
Task Type Detection:
IF request mentions "API", "endpoint", "backend", "database":
โ API-focused workflow
โ Use: api-architect, backend-developer, test-architect
โ Skip: designer, ui-developer (not relevant)
ELSE IF request mentions "UI", "component", "design", "Figma":
โ UI-focused workflow
โ Use: designer, ui-developer, ui-manual-tester
โ Optional: ui-developer-codex (external validation)
ELSE IF request mentions both API and UI:
โ Mixed workflow
โ Use all relevant agents from both categories
โ Coordinate between backend and frontend agents
ELSE IF request mentions "test", "coverage", "bug":
โ Testing-focused workflow
โ Use: test-architect, ui-manual-tester
โ Optional: codebase-detective (for bug investigation)
ELSE IF request mentions "review", "validate", "feedback":
โ Review-focused workflow
โ Use: senior-code-reviewer, designer, ui-developer
โ Optional: external model reviewers
Agent Capability Matrix:
| Task Type | Primary Agent | Secondary Agent | Optional External |
|---|---|---|---|
| API Implementation | backend-developer | api-architect | - |
| UI Implementation | ui-developer | designer | ui-developer-codex |
| Testing | test-architect | ui-manual-tester | - |
| Code Review | senior-code-reviewer | - | codex-code-reviewer |
| Architecture Planning | api-architect OR frontend-architect | - | plan-reviewer |
| Bug Investigation | codebase-detective | test-architect | - |
| Design Validation | designer | ui-developer | designer-codex |
Agent Switching Pattern:
Some workflows benefit from adaptive agent selection based on context:
Example: UI Development with External Validation
Base Implementation:
Task: ui-developer
Prompt: Implement navbar component from design
User requests external validation:
โ Switch to ui-developer-codex OR add parallel ui-developer-codex
โ Run both: embedded ui-developer + external ui-developer-codex
โ Consolidate feedback from both
Scenario 1: User wants speed
โ Use ONLY ui-developer (embedded, fast)
Scenario 2: User wants highest quality
โ Use BOTH ui-developer AND ui-developer-codex (parallel)
โ Consensus analysis on feedback
Scenario 3: User is out of credits
โ Fallback to ui-developer only
โ Notify user external validation unavailable
File-Based Instructions (Context Isolation):
When delegating to sub-agents, use file-based instructions to avoid context pollution:
โ
CORRECT - File-Based Delegation:
Step 1: Write instructions to file
Write: ai-docs/architecture-instructions.md
Content: "Design authentication system with JWT tokens..."
Step 2: Delegate to agent with file reference
Task: api-architect
Prompt: "Read instructions from ai-docs/architecture-instructions.md
and create architecture plan."
Step 3: Agent reads file, does work, writes output
Agent reads: ai-docs/architecture-instructions.md
Agent writes: ai-docs/architecture-plan.md
Step 4: Agent returns brief summary ONLY
Return: "Architecture plan complete. See ai-docs/architecture-plan.md"
Step 5: Orchestrator reads output file if needed
Read: ai-docs/architecture-plan.md
(Only if orchestrator needs to process the output)
Why File-Based?
Anti-Pattern: Inline Delegation
โ WRONG - Context Pollution:
Task: api-architect
Prompt: "Design authentication system with:
- JWT tokens with refresh token rotation
- Email/password login with bcrypt hashing
- OAuth2 integration with Google, GitHub
- Rate limiting on login endpoint (5 attempts per 15 min)
- Password reset flow with time-limited tokens
- Email verification on signup
- Role-based access control (admin, user, guest)
- Session management with Redis
- Security headers (CORS, CSP, HSTS)
- ... (500 more lines of requirements)"
Problem: Orchestrator's context now contains 500+ lines of requirements
that are only relevant to the architect agent.
Brief Summary Returns:
Sub-agents should return 2-5 sentence summaries, not full output:
โ
CORRECT - Brief Summary:
"Architecture plan complete. Designed 3-layer authentication:
JWT with refresh tokens, OAuth2 integration (Google/GitHub),
and Redis session management. See ai-docs/architecture-plan.md
for detailed component breakdown."
โ WRONG - Full Output:
"Architecture plan:
[500 lines of detailed architecture documentation]
Components: AuthController, TokenService, OAuthService...
[another 500 lines]"
Proxy Mode Invocation:
For external AI models (Claudish), use the PROXY_MODE directive:
Task: codex-code-reviewer PROXY_MODE: x-ai/grok-code-fast-1
Prompt: "Review authentication implementation for security issues.
Code context in ai-docs/code-review-context.md"
Agent Behavior:
1. Detects PROXY_MODE directive
2. Extracts model: x-ai/grok-code-fast-1
3. Extracts task: "Review authentication implementation..."
4. Executes: claudish --model x-ai/grok-code-fast-1 --stdin <<< "..."
5. Waits for full response (blocking execution)
6. Writes: ai-docs/grok-review.md (full detailed review)
7. Returns: "Grok review complete. Found 3 CRITICAL issues. See ai-docs/grok-review.md"
Key: Blocking Execution
External models MUST execute synchronously (blocking) so the agent waits for the full response:
โ
CORRECT - Blocking:
RESULT=$(claudish --model x-ai/grok-code-fast-1 --stdin <<< "$PROMPT")
echo "$RESULT" > ai-docs/grok-review.md
echo "Review complete - see ai-docs/grok-review.md"
โ WRONG - Background (returns before completion):
claudish --model x-ai/grok-code-fast-1 --stdin <<< "$PROMPT" &
echo "Review started..." # Agent returns immediately, review not done!
When to Delegate:
Delegate to sub-agents when:
When to Execute in Main Context:
Execute in main orchestrator when:
Context Size Estimation:
Note: Token estimates below are approximations based on typical usage. Actual context consumption varies by skill complexity, Claude model version, and conversation history. Use these as guidelines, not exact measurements.
Estimate context usage to decide delegation strategy:
Context Budget: ~200k tokens (Claude Sonnet 4.5 - actual varies by model)
Current context usage breakdown:
- System prompt: 10k tokens
- Skill content (5 skills): 10k tokens
- Command instructions: 5k tokens
- User request: 1k tokens
- Conversation history: 20k tokens
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Total used: 46k tokens
Remaining: 154k tokens
Safe threshold for delegation: If task will consume >30k tokens, delegate
Example: Architecture planning for large system
- Requirements: 5k tokens
- Expected output: 20k tokens
- Total: 25k tokens
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Decision: Delegate (keeps orchestrator lightweight)
Delegation Strategy by Context Size:
| Task Output Size | Strategy |
|---|---|
| < 1k tokens | Execute in orchestrator |
| 1k - 10k tokens | Delegate with summary return |
| 10k - 30k tokens | Delegate with file-based output |
| > 30k tokens | Multi-agent decomposition |
Example: Multi-Agent Decomposition
User Request: "Implement complete e-commerce system"
This is >100k tokens if done by single agent. Decompose:
Phase 1: Break into sub-systems
- Product catalog
- Shopping cart
- Checkout flow
- User authentication
- Order management
- Payment integration
Phase 2: Delegate each sub-system to separate agent
Task: backend-developer
Instruction file: ai-docs/product-catalog-requirements.md
Output file: ai-docs/product-catalog-implementation.md
Task: backend-developer
Instruction file: ai-docs/shopping-cart-requirements.md
Output file: ai-docs/shopping-cart-implementation.md
... (6 parallel agent invocations)
Phase 3: Integration agent
Task: backend-developer
Instruction: "Integrate 6 sub-systems. Read output files:
ai-docs/*-implementation.md"
Output: ai-docs/integration-plan.md
Total context per agent: ~20k tokens (manageable)
vs. Single agent: 120k+ tokens (context overflow risk)
multi-agent-coordination + multi-model-validation:
Use Case: Code review with multiple AI models
Step 1: Agent Selection (multi-agent-coordination)
- Detect task type: Code review
- Select agents: senior-code-reviewer (embedded) + external models
Step 2: Parallel Execution (multi-model-validation)
- Follow 4-Message Pattern
- Launch all reviewers simultaneously
- Wait for all to complete
Step 3: Consolidation (multi-model-validation)
- Auto-consolidate reviews
- Apply consensus analysis
multi-agent-coordination + quality-gates:
Use Case: Iterative UI validation
Step 1: Agent Selection (multi-agent-coordination)
- Detect task type: UI validation
- Select agents: designer, ui-developer
Step 2: Iteration Loop (quality-gates)
- Run designer validation
- If not PASS: delegate to ui-developer for fixes
- Loop until PASS or max iterations
Step 3: User Validation Gate (quality-gates)
- MANDATORY user approval
- Collect feedback if issues found
multi-agent-coordination + todowrite-orchestration:
Use Case: Multi-phase implementation workflow
Step 1: Initialize TodoWrite (todowrite-orchestration)
- Create task list for all phases
Step 2: Sequential Agent Delegation (multi-agent-coordination)
- Phase 1: api-architect
- Phase 2: backend-developer (depends on Phase 1)
- Phase 3: test-architect (depends on Phase 2)
- Update TodoWrite after each phase
Do:
Don't:
Performance Tips:
Scenario: User requests "Review my authentication code with Grok and Gemini"
Agent Selection:
Execution:
Message 1: Preparation
- Write code context to ai-docs/code-review-context.md
Message 2: Parallel Execution (3 Task calls in single message)
Task: senior-code-reviewer
Prompt: "Review ai-docs/code-review-context.md for security issues"
---
Task: codex-code-reviewer PROXY_MODE: x-ai/grok-code-fast-1
Prompt: "Review ai-docs/code-review-context.md for security issues"
---
Task: codex-code-reviewer PROXY_MODE: google/gemini-2.5-flash
Prompt: "Review ai-docs/code-review-context.md for security issues"
All 3 execute simultaneously (3x faster than sequential)
Message 3: Auto-Consolidation
Task: senior-code-reviewer
Prompt: "Consolidate 3 reviews from:
- ai-docs/claude-review.md
- ai-docs/grok-review.md
- ai-docs/gemini-review.md
Prioritize by consensus."
Message 4: Present Results
"Review complete. 3 models analyzed your code.
Top 5 issues by consensus:
1. [UNANIMOUS] Missing input validation on login endpoint
2. [STRONG] SQL injection risk in user query
3. [MAJORITY] Weak password requirements
See ai-docs/consolidated-review.md for details."
Result: 5 minutes total (vs 15+ if sequential), consensus-based prioritization
Scenario: User requests "Implement payment integration feature"
Agent Selection:
Execution:
Phase 1: Architecture Planning
Write: ai-docs/payment-requirements.md
"Integrate Stripe payment processing with webhook support..."
Task: api-architect
Prompt: "Read ai-docs/payment-requirements.md
Create architecture plan"
Output: ai-docs/payment-architecture.md
Return: "Architecture plan complete. Designed 3-layer payment system."
Wait for completion โ
Phase 2: Implementation (depends on Phase 1)
Task: backend-developer
Prompt: "Read ai-docs/payment-architecture.md
Implement payment integration"
Output: src/payment.ts, src/webhooks.ts
Return: "Payment integration implemented. 2 new files, 500 lines."
Wait for completion โ
Phase 3: Testing (depends on Phase 2)
Task: test-architect
Prompt: "Write tests for src/payment.ts and src/webhooks.ts"
Output: tests/payment.test.ts, tests/webhooks.test.ts
Return: "Test suite complete. 20 tests covering payment flows."
Wait for completion โ
Phase 4: Code Review (depends on Phase 3)
Task: senior-code-reviewer
Prompt: "Review payment integration implementation"
Output: ai-docs/payment-review.md
Return: "Review complete. 2 MEDIUM issues found."
Wait for completion โ
Result: Sequential execution ensures each phase has correct inputs
Scenario: User requests "Validate navbar implementation" with optional external AI
Agent Selection:
Execution:
Step 1: Ask user preference
"Do you want external AI validation? (Yes/No)"
Step 2a: If user says NO (speed mode)
Task: designer
Prompt: "Validate navbar against Figma design"
Output: ai-docs/design-review.md
Return: "Design validation complete. PASS with 2 minor suggestions."
Step 2b: If user says YES (quality mode)
Message 1: Parallel Validation
Task: designer
Prompt: "Validate navbar against Figma design"
---
Task: designer PROXY_MODE: design-review-codex
Prompt: "Validate navbar against Figma design"
Message 2: Consolidate
Task: designer
Prompt: "Consolidate 2 design reviews. Prioritize by consensus."
Output: ai-docs/design-review-consolidated.md
Return: "Consolidated review complete. Both agree on 1 CRITICAL issue."
Step 3: User validation
Present consolidated review to user for approval
Result: Adaptive workflow based on user preference (speed vs quality)
Problem: Parallel tasks executing sequentially
Cause: Mixed tool types in same message
Solution: Use 4-Message Pattern with ONLY Task calls in Message 2
โ Wrong:
await TodoWrite({...});
await Task({...});
await Task({...});
โ
Correct:
Message 1: await Bash({...}); (prep only)
Message 2: await Task({...}); await Task({...}); (parallel)
Problem: Orchestrator context overflowing
Cause: Inline instructions or full output returns
Solution: Use file-based delegation + brief summaries
โ Wrong:
Task: agent
Prompt: "[1000 lines of inline requirements]"
Return: "[500 lines of full output]"
โ
Correct:
Write: ai-docs/requirements.md
Task: agent
Prompt: "Read ai-docs/requirements.md"
Return: "Complete. See ai-docs/output.md"
Problem: Wrong agent selected for task
Cause: Task type detection failed
Solution: Explicitly detect task type using keywords
Check user request for keywords:
- API/endpoint/backend โ api-architect, backend-developer
- UI/component/design โ designer, ui-developer
- test/coverage โ test-architect
- review/validate โ senior-code-reviewer
Default: Ask user to clarify task type
Problem: Agent returns immediately before external model completes
Cause: Background execution (non-blocking claudish call)
Solution: Use synchronous (blocking) execution
โ Wrong:
claudish --model grok ... & (background, returns immediately)
โ
Correct:
RESULT=$(claudish --model grok ...) (blocks until complete)
Multi-agent coordination is about choosing the right execution strategy:
Master these patterns and you can orchestrate workflows of any complexity.
Extracted From:
/implement command (task detection, sequential workflows)/validate-ui command (adaptive agent switching)/review command (parallel execution, 4-Message Pattern)CLAUDE.md Parallel Multi-Model Execution Protocol