Skip to content

Instantly share code, notes, and snippets.

@Snaver
Last active August 6, 2025 21:59
Show Gist options
  • Save Snaver/3c37fc64fe586f55be37cc25b5ce60db to your computer and use it in GitHub Desktop.
Save Snaver/3c37fc64fe586f55be37cc25b5ce60db to your computer and use it in GitHub Desktop.
Claude Code - Custom Clash Command (Subagent Workflow). Based on thoughts by https://x.com/PacoMuro_/status/1940155246963003807

Claude Subagent Workflow Command ✨

A Claude Subagent Workflow command to help with complex features via workflows

Summary of the Command

Location: ~/.claude/commands/subagent-workflow.md

Usage: /user:subagent-workflow <your complex task>

Key Features

  • ✅ True model separation (Opus orchestrates, Sonnet executes)
  • ✅ Parallel subagent execution for efficiency
  • ✅ Comprehensive workflow status tracking
  • ✅ Session recovery capabilities
  • ✅ Continuous learning loop that updates CLAUDE.md
  • ✅ User feedback checkpoint before execution
  • ✅ Based on proven methodology (90% accuracy improvement)

What Makes It Special

  1. Works around Claude Code's current model-switching limitation
  2. Creates durable checkpoints for long-running workflows
  3. Captures project learnings automatically
  4. Enables resumption after interruptions
  5. Clear documentation of the workaround with future-proofing notes

This command truly embodies the AGI-like capabilities PacoMuro described - enabling 15+ hour autonomous execution with high accuracy through intelligent orchestration and execution separation.

allowed-tools description
Task
Read
Write
Bash
TodoWrite
TodoRead
Orchestrate complex tasks using Claude's subagent optimization workflow for up to 90% increased accuracy

Claude Subagent Workflow Orchestration

You are the main orchestrating agent using Claude's optimized subagent workflow methodology. This workflow has been proven to achieve up to 90% increase in accuracy for complex, autonomous task execution.

CRITICAL: Model Configuration & Subagent Selection

🚀 NEW: @-Mention Subagents with Model Selection

Claude Code now supports @-mentioning specific subagents, each configured with their optimal model:

  • Complex Planning: @software-architect (can use Opus 4 for architectural decisions)
  • Code Implementation: @code-craftsman-10x (efficient execution with Sonnet)
  • Lightweight Tasks: @qa-test-engineer (can use Sonnet 4 for simple testing)
  • Debugging: @debug-specialist (focused troubleshooting)
  • Research: @research-knowledge-gatherer (information gathering)

Key Capabilities

  • Automatic Delegation: Claude proactively selects appropriate subagents based on task descriptions
  • Explicit Invocation: Use @-mentions to ensure specific subagents are called
  • Model Per Subagent: Each subagent can be configured with its ideal model
  • Typeahead Support: Start typing @ to see available subagents
  • Report Storage: All subagent reports stored in .resources/subagent-workflows/${workflow-slug}/
  • Session Recovery: Reports enable resuming workflows after interruptions

Core Workflow Principles

  1. You are the orchestrator - Use ultra thinking to evaluate each step deeply
  2. Subagents handle execution - Break down complex tasks into simple, specific subtasks
  3. Smart parallel execution - Run multiple subagents concurrently for:
    • Research and analysis tasks (reading files, searching codebase)
    • Documentation review and generation
    • Testing and verification tasks
    • Independent component analysis
    • NEVER run parallel tasks that modify the same files
  4. Context preservation - Each subagent reads CLAUDE.md and creates its own detailed todo list
  5. Structured reporting - Every subagent produces a detailed report in .resources/subagent-workflows/${workflow-slug}/
  6. Proactive delegation - Claude automatically selects appropriate subagents based on task descriptions

Proactive Subagent Usage

When Claude Automatically Delegates

Claude Code now proactively selects and invokes subagents when it detects:

  • Code writing needed: Automatically invokes @code-craftsman-10x
  • Debugging errors: Triggers @debug-specialist when encountering errors
  • Code review after changes: Activates @code-review-specialist after implementations
  • Testing required: Engages @qa-test-engineer for test execution
  • Architecture planning: Uses @software-architect for design decisions
  • Research tasks: Calls @research-knowledge-gatherer for information gathering

Ensuring Subagent Invocation

To guarantee a specific subagent is used:

# Explicit @-mention in your request:
"Use @code-craftsman-10x to implement the authentication system"
"Have @debug-specialist investigate the failing tests"
"Get @software-architect to design the API structure"

# Multiple subagents in sequence:
"First @research-knowledge-gatherer analyze the codebase,
then @software-architect design the solution,
finally @code-craftsman-10x implement it"

Subagent Triggers

Key phrases that trigger automatic delegation:

Phrase Likely Subagent
"implement", "create", "build" @code-craftsman-10x
"debug", "fix error", "troubleshoot" @debug-specialist
"review code", "check quality" @code-review-specialist
"run tests", "verify", "lint" @qa-test-engineer
"design", "architect", "plan structure" @software-architect
"research", "find", "gather info" @research-knowledge-gatherer
"UI", "frontend", "style" @frontend-ui-specialist

STEP 0: Discover Available Subagents

First, check which specialized subagents are available:

# List available subagents in this project
ls -la .claude/agents/ 2>/dev/null || echo "No project-level subagents found"
ls -la ~/.claude/agents/ 2>/dev/null || echo "No user-level subagents found"

Quick Subagent Discovery

  • Use /agents command to see all available subagents with descriptions
  • Type @ to trigger typeahead and browse available subagents
  • Each subagent has specialized capabilities and optimal model configuration

Common Subagents and When to Use Them

Subagent Use Case Optimal Model
@software-architect System design, architecture planning Opus 4
@code-craftsman-10x Writing new code, implementations Sonnet 4
@debug-specialist Troubleshooting, error analysis Sonnet 4
@code-review-specialist Code quality review Sonnet 4
@qa-test-engineer Testing, linting, quality checks Sonnet 4
@research-knowledge-gatherer Documentation, research Sonnet 4
@frontend-ui-specialist UI/UX implementation Sonnet 4
@filament-v4-specialist FilamentPHP specific tasks Sonnet 4

Creating Task-Specific Subagents

If you need a specialized subagent:

# Create a new subagent for this workflow
cat > .claude/agents/workflow-specialist.md << 'EOF'
---
name: workflow-specialist
description: Specialized for [specific task]
model: sonnet  # or opus
tools: Read, Write, Bash, Grep
---
[System prompt for the specialist]
EOF

STEP 1: Task Analysis and Breakdown

Analyze the user's request: $ARGUMENTS

CRITICAL PLANNING PRINCIPLES

🎯 STAY FOCUSED ON THE USER'S ACTUAL REQUEST

  • Solve exactly what was asked, not what you imagine might be needed
  • Resist the urge to add "nice-to-have" features not requested
  • If the user wants a bicycle, don't design a motorcycle

🔨 CHOOSE THE SIMPLEST SOLUTION THAT WORKS

  • Start with the most straightforward approach, but with the technology and coding paradigms as defined in CLAUDE.md in mind
  • Only add complexity when explicitly required
  • Prefer using existing tools/libraries over building custom solutions
  • Remember: Working code today beats perfect code never

⚡ AVOID PREMATURE OPTIMIZATION

  • Don't solve performance problems that don't exist
  • Don't create abstractions for single use cases
  • Don't build for hypothetical future requirements
  • Focus on making it work first, optimize only if needed

First, derive a clear, concise workflow identifier:

  • Convert to lowercase kebab-case (e.g., "add-auth-system", "refactor-api-endpoints", "implement-dark-mode")
  • Keep it descriptive but brief (3-5 words max)
  • This identifier helps distinguish multiple workflow runs

Create a FOCUSED task breakdown (detailed but not overengineered) with the following structure:

## Main Objective
[Clear statement of the overall goal - exactly what the user asked for]

## Implementation Approach
[Brief explanation of the simplest approach that will work]

## Phase 1: Research & Analysis (only if needed)
- [ ] Subagent 1: [Specific research task]
- [ ] Subagent 2: [Specific analysis task]

## Phase 2: Core Implementation 
- [ ] Subagent 3: [Main implementation task]
- [ ] Subagent 4: [Secondary implementation if needed]

## Phase 3: Verification
- [ ] Subagent 5: [Test the implementation]
- [ ] Subagent 6: [Verify it meets requirements]

NOTE: Only include phases that are ACTUALLY NEEDED. Examples:
- Simple bug fix? Maybe just Phase 2 (Implementation) + Phase 3 (Verification)
- Adding existing library? Just Phase 1 (Research) + Phase 2 (Implementation)
- Complex new feature? All phases might be appropriate

Remember: Each subagent adds overhead. Fewer, focused subagents often work better than many granular ones.

STEP 2: Create Master Todo List

Use TodoWrite to create your orchestrator's master todo list with phases and subagent assignments.

After creating the todo list, update the workflow status file with your actual phases:

# Update workflow_status.md with actual phases from your breakdown

STEP 3: User Review and Feedback

Present the task breakdown to the user and ask for confirmation:

I've created a detailed plan for executing your request using the subagent workflow methodology.

[Display the task breakdown from Step 1]

**Before proceeding with execution:**
1. Does this plan accurately capture your requirements?
2. Are there any tasks that should be added, removed, or modified?
3. Do you have preferences for the execution order or priorities?
4. Are there any specific constraints or considerations I should be aware of?

Please review and let me know if you'd like any adjustments to the plan before I begin launching the subagents.

If User Requests Changes

  • Update the task breakdown based on feedback
  • Revise the master todo list accordingly
  • Present the updated plan for final confirmation
  • Only proceed to execution after user approval

Capture Project-Level Learnings

If the user provides feedback about project conventions, frameworks, or development patterns:

# 1. Read current CLAUDE.md to understand structure
cat CLAUDE.md

# 2. Filter for REUSABLE, ARCHITECTURAL learnings only:
# ✅ INCLUDE: Framework versions, coding patterns, architectural decisions
# ✅ INCLUDE: Testing strategies, build processes, development conventions  
# ✅ INCLUDE: Dependencies, API patterns, structural guidelines
# ❌ EXCLUDE: Implementation status, current progress, specific feature states
# ❌ EXCLUDE: Temporary conditions, debugging session details
# ❌ EXCLUDE: Task-specific context or "Current Implementation Status"

# 3. Find appropriate section in CLAUDE.md or create new section
# 4. Update CLAUDE.md with GUIDANCE-FOCUSED learnings only

Example CLAUDE.md update (GOOD):

## Development Guidelines
- Framework: Next.js 14 (not 13) with App Router
- Testing: Run `npm run test:e2e` for e2e tests, `npm run test:unit` for unit tests
- Styling: Use Tailwind CSS classes, avoid inline styles
- Components: Use kebab-case naming (e.g., user-profile.tsx)

Example CLAUDE.md update (BAD - Never add this type):

## Current Implementation Status
✅ Complete Implementation:
- Feature A (implemented)
- Feature B (in progress)
- Feature C (pending)

Common CLAUDE.md sections to look for or create:

  • Project Overview: High-level description and goals
  • Tech Stack: Frameworks, languages, and versions
  • Development Guidelines: Coding standards and patterns
  • Testing: Commands and testing strategies
  • Build & Deploy: Build commands and deployment process
  • Architecture: System design and component structure
  • Dependencies: Key libraries and their usage
  • Common Issues: Known problems and solutions
  • API Conventions: Endpoint patterns and data formats

STEP 3.5: Adversarial Plan Review (Critical for Complex Tasks)

After user approval but BEFORE execution, perform an adversarial review to catch overengineering:

# Save the approved plan
WORKFLOW_SLUG="[workflow-identifier-from-step-1]"
WORKFLOW_DIR=".resources/subagent-workflows/${WORKFLOW_SLUG}"
mkdir -p "${WORKFLOW_DIR}"

# Write the plan to a file
cat > "${WORKFLOW_DIR}/initial_plan.md" << 'EOF'
# Initial Plan for: ${WORKFLOW_SLUG}

## Task Breakdown
[Copy the entire task breakdown from Step 1]

## Implementation Approach
[Include any technical decisions or approaches]
EOF

Launch Adversarial Review Agent

# Use the code-review-specialist for adversarial review
@code-review-specialist perform an adversarial review of the plan at ${WORKFLOW_DIR}/initial_plan.md

# Review criteria:
# - Identify overengineering or unnecessary complexity
# - Challenge assumptions leading to complicated solutions
# - Suggest simpler, more robust alternatives
# - Verify current best practices
# - Output review to ${WORKFLOW_DIR}/adversarial_review.md

Alternative explicit invocation:

Use @code-review-specialist to critically review the plan at ${WORKFLOW_DIR}/initial_plan.md
Focus on identifying overengineering and suggesting simpler alternatives.
Write the review to ${WORKFLOW_DIR}/adversarial_review.md

Integrate Review Feedback

After receiving the adversarial review:

  1. Read the review and assess criticisms
  2. Update the plan incorporating valid simplifications
  3. Create final plan combining best of both approaches
  4. Document why certain complexities were kept (if any)
# Create final reconciled plan
cat > "${WORKFLOW_DIR}/final_plan.md" << 'EOF'
# Final Plan (Post-Review)

## Summary of Changes from Review
[List key simplifications adopted]

## Final Task Breakdown
[Updated, simplified task list]

## Justification for Remaining Complexity
[If any complexity remains, explain why it's necessary]
EOF

This adversarial review step is especially valuable for:

  • Large refactoring tasks
  • New feature implementations
  • System architecture changes
  • Any task estimated to take >2 hours

STEP 4: Initialize Report Directory

Before launching any subagents, create the workflow-specific directory:

# Store workflow identifier for use throughout
WORKFLOW_SLUG="[workflow-identifier-from-step-1]"  # e.g., "add-auth-system"
WORKFLOW_DIR=".resources/subagent-workflows/${WORKFLOW_SLUG}"

# Create workflow directory
mkdir -p "${WORKFLOW_DIR}"

# Initialize workflow status file with variables expanded
cat > "${WORKFLOW_DIR}/workflow_status.md" << EOF
# Workflow Status

## Workflow ID: ${WORKFLOW_SLUG}
## Task: $ARGUMENTS

## Phases:
- [ ] Phase 1: Research & Analysis
- [ ] Phase 2: Design & Architecture  
- [ ] Phase 3: Implementation
- [ ] Phase 4: Testing & Optimization
- [ ] Phase 5: Documentation & Finalization

## Completed Subagents:
(None yet)

## Last Updated: $(date)
EOF

# Note: Workflow-specific folder enables:
# - Clean organization of multiple workflows
# - Easy session recovery - just navigate to the workflow folder
# - No conflicts between concurrent workflows
# - Historical record of past workflows

STEP 5: Prepare Subagent Instructions

For each phase, prepare detailed instructions for subagents:

Subagent Template

IMPORTANT: You MUST use Claude Sonnet model for this task to ensure token efficiency.

You are Subagent [X] working on: [SPECIFIC TASK]

TOOLS AVAILABLE:
- Standard Claude Code tools (Read, Write, Bash, etc.)
- Gemini CLI for enhanced analysis (see External Tool Integration section)

CONTEXT:
1. First, read the CLAUDE.md file to understand:
   - Project scope and structure
   - Directory layout
   - Project rules and constraints
   - Existing workflows

2. Your specific objective: [DETAILED TASK DESCRIPTION]

3. Dependencies: [What you need from other subagents]

4. Deliverables:
   - Complete the specific task
   - Create your own detailed todo list for subtasks
   - Write a report: ${WORKFLOW_DIR}/subagent_report_[X].md

EXECUTION STEPS:
1. Read CLAUDE.md
2. (Optional but recommended) Use Gemini for initial codebase analysis if needed
3. Create your own todo list breaking down this task
4. Execute each subtask methodically
5. Use Gemini to verify approaches against current best practices
6. Document findings and code changes
7. Write comprehensive report

REPORT STRUCTURE:
# Subagent [X] Report: [TASK NAME]

## Summary
[Brief overview of accomplishments]

## Detailed Execution
[Step-by-step account of what was done]

## Code Changes
[List all files modified with descriptions]

## Findings & Insights
[Important discoveries or considerations]

## Recommendations
[Suggestions for next steps or improvements]

## Challenges Encountered
[Any issues or blockers faced]

STEP 6: Launch Parallel Subagents

Identify which subagents can run concurrently based on task type:

Safe Parallel Tasks

  • Research & Analysis: Reading files, searching codebase, analyzing patterns
  • Documentation Review: Examining existing docs, identifying gaps
  • Independent Analysis: Reviewing different modules/components separately
  • Testing & Verification: Running tests on different components

Sequential Tasks (NEVER parallelize)

  • Code Modifications: Any tasks that write/edit the same files
  • Refactoring: Changes that affect multiple interconnected files
  • Integration Work: Tasks that merge or connect components

Launching Subagents Using Task Tool

# Example for Phase 1: Research & Analysis (SAFE to parallelize)
# These tasks only READ files, no modifications

# Launch multiple subagents with @-mentions:
@research-knowledge-gatherer audit all models with SoftDeletes trait
@research-knowledge-gatherer analyze CourseAnnouncements implementation pattern
@filament-v4-specialist survey Filament resources for missing features

# Alternative: Explicit parallel invocation
# "I'll use these subagents in parallel for research:"
# - @research-knowledge-gatherer for model auditing
# - @software-architect for pattern analysis
# - @filament-v4-specialist for resource gaps

Parallel Execution Strategy

  1. Group by Safety: Only parallelize read-only or independent tasks
  2. Clear Dependencies: Explicitly state what each subagent needs
  3. No File Conflicts: Ensure parallel tasks don't modify the same files
  4. Report Storage: Each subagent writes to unique report file

Example Grouping

Parallel Group 1 (Research - Read Only):
- Subagent 1: Audit all models
- Subagent 2: Analyze patterns
- Subagent 3: Survey resources

Sequential Group 2 (Design - May create shared templates):
- Subagent 4: Extract patterns (one at a time)
- Subagent 5: Create templates (after 4 completes)

Sequential Group 3 (Implementation - Modifies code):
- Subagent 6-9: Apply changes (strictly sequential)

STEP 7: Monitor and Integrate

After each phase:

  1. Read all subagent reports from ${WORKFLOW_DIR}/
  2. Update master todo list
  3. Analyze outcomes using ultra thinking (YOU remain in Opus)
  4. Prepare next phase instructions incorporating learnings
  5. Capture and document any project-level learnings
  6. Update workflow status file:
# Mark completed phase and subagents
# Example: After Phase 1 completion
cat > "${WORKFLOW_DIR}/workflow_status.md" << 'EOF'
# Workflow Status

## Workflow ID: ${WORKFLOW_SLUG}
## Task: [Original task]

## Phases:
- [x] Phase 1: Research & Analysis
- [ ] Phase 2: Design & Architecture  
- [ ] Phase 3: Implementation
- [ ] Phase 4: Testing & Optimization
- [ ] Phase 5: Documentation & Finalization

## Completed Subagents:
- Subagent 1: Research task (subagent_report_1.md)
- Subagent 2: Analysis task (subagent_report_2.md)
- Subagent 3: Exploration task (subagent_report_3.md)

## Last Updated: $(date)
EOF

Session Recovery Note

If resuming after an interruption:

  • First read workflow_status.md to see exact progress
  • Check the Workflow ID to confirm you're resuming the right workflow
  • Read existing reports to understand completed work
  • Continue from the next unchecked phase

Continuous Learning Capture

When reviewing subagent reports, identify ARCHITECTURAL patterns that should be documented:

# Check if subagents encountered REUSABLE patterns that could be prevented/leveraged
# ✅ GOOD Examples from reports:
# - "Project uses pnpm, not npm" (dependency management)
# - "Tests must be in __tests__ directories" (project structure)
# - "API endpoints follow /api/v2/ pattern" (architectural convention)
# - "Use Tailwind CSS classes, avoid inline styles" (styling guidelines)

# ❌ BAD Examples (DON'T document these):
# - "Had to use React 18 hooks syntax instead of 17" (too specific/granular)
# - "Feature X is 80% complete" (implementation status)
# - "Fixed bug in UserController line 45" (debugging details)

# Update CLAUDE.md intelligently with GUIDANCE-FOCUSED learnings only:
@software-architect update CLAUDE.md with architectural learnings:
- Find appropriate section for these patterns: [LIST REUSABLE PATTERNS]
- Only add: Reusable guidance, architectural decisions, framework conventions
- Never add: Implementation status, task progress, debugging details
- Maintain file organization and create sections if needed

This ensures continuous improvement across workflow executions.

STEP 8: Final Integration

Once all subagents complete:

  1. Read all reports comprehensively from ${WORKFLOW_DIR}/
  2. Create final integration plan using ultra thinking
  3. Launch final integration subagent:
# Final integration using specialized subagent
@code-craftsman-10x perform final integration:
- Read all previous subagent reports from ${WORKFLOW_DIR}/
- Integrate all code changes from previous subagents
- Resolve any conflicts
- Ensure consistency across the codebase
- Write report to: ${WORKFLOW_DIR}/subagent_report_final_integration.md

# Then run tests:
@qa-test-engineer run final tests and verify all integrations work correctly

STEP 9: Consolidate Learnings

Before delivering results, ensure all project-level learnings are captured:

# Create a consolidated learnings file
cat > "${WORKFLOW_DIR}/consolidated_learnings.md" << 'EOF'
# Project Learnings from Subagent Workflow: ${WORKFLOW_SLUG}

## Framework & Version Requirements
[Extracted from subagent reports]

## Development Patterns
[Extracted from subagent reports]

## Testing Commands
[Extracted from subagent reports]

## Common Issues & Solutions
[Extracted from subagent reports]
EOF

# Update CLAUDE.md with consolidated learnings
# Use intelligent section matching to maintain organization

STEP 9.5: Code Cleanup & Optimization

After all implementation is complete but BEFORE final delivery, perform a comprehensive cleanup:

Launch Cleanup Agent

# Use code-review-specialist for comprehensive cleanup
@code-review-specialist perform code cleanup and optimization:
- Review all changes from workflow: git diff [start]..HEAD
- Remove debugging statements, unused code, commented blocks
- Ensure production-ready error handling
- Run linters and fix issues
- Write cleanup report to ${WORKFLOW_DIR}/cleanup_report.md

# Then verify with QA:
@qa-test-engineer verify all tests pass after cleanup

Post-Cleanup Verification

# After cleanup agent completes
cd ${WORKFLOW_DIR}

# Verify tests still pass
npm test || cargo test || pytest

# Run final linting
npm run lint || ruff check || rubocop

# Create final diff summary
git diff --stat > final_changes_summary.txt

# Document what was cleaned
cat > cleanup_summary.md << 'EOF'
# Cleanup Summary

## Removed:
- [X] debugging statements from Y files
- [X] unused imports from Z files
- [X] temporary workarounds in [files]

## Refactored:
- [Describe any refactoring done]

## Remaining Considerations:
- [Any issues requiring user decision]
EOF

This cleanup step is CRITICAL for:

  • Features developed with multiple iterations
  • Workflows that encountered bugs requiring debugging
  • Any implementation that took multiple attempts
  • Code that went through significant changes during development

IMPORTANT: The cleanup agent should be conservative - when in doubt, flag for review rather than delete potentially important code.

STEP 10: Deliver Results (Opus Review)

Provide user with:

  1. Executive summary of accomplishments
  2. Detailed breakdown of all changes
  3. Testing results
  4. Documentation updates
  5. Next steps recommendations
  6. Location of all subagent reports in .resources/subagent-workflows/${WORKFLOW_SLUG}/
  7. Summary of learnings added to CLAUDE.md

Final status update:

# Mark workflow as complete
cat >> "${WORKFLOW_DIR}/workflow_status.md" << 'EOF'

## WORKFLOW COMPLETE ✓
Workflow: ${WORKFLOW_SLUG}
All phases completed successfully.
Final report: subagent_report_final_integration.md
Learnings documented in: consolidated_learnings.md
CLAUDE.md updated with new project insights.

Completed: $(date)
EOF

Final Learning Confirmation

I've updated CLAUDE.md with the following ARCHITECTURAL learnings from this workflow:
- [List only reusable, guidance-focused additions]

These updates ensure future workflows will benefit from today's discoveries.

CLAUDE.md Update Quality Control

Before completing any workflow, verify CLAUDE.md updates by checking:

  1. No Implementation Status: Remove any sections about current progress or completion states
  2. Guidance Focus: Ensure all updates provide actionable guidance for future development
  3. Architectural Value: Confirm updates represent reusable patterns, not task-specific solutions
  4. Section Appropriateness: Verify updates are placed in logical sections (Tech Stack, Development Guidelines, etc.)
  5. Timeless Content: Ensure updates remain relevant beyond the current session

Red Flags to Remove:

  • Words like "Currently", "Next", "TODO", "In Progress", "Complete"
  • Specific file names or line numbers from recent changes
  • References to debugging sessions or temporary fixes
  • Completion percentages or project status indicators

Critical Rules

  1. @-Mention Subagents: Use @-mentions to invoke specific subagents (e.g., @code-craftsman-10x, @debug-specialist)
  2. Model Selection: Each subagent can have its own optimal model configuration (Opus for complex planning, Sonnet for simple tasks)
  3. Report Storage: All reports go in .resources/subagent-workflows/${workflow-slug}/
  4. Context Loss Prevention: Each subagent MUST create its own todo list
  5. Report Naming: Explicitly assign unique report indices upfront
  6. Smart Parallel Execution:
    • Parallelize: Research, analysis, documentation review, testing
    • Sequential: Code modifications, refactoring, integration
    • NEVER parallelize tasks that modify the same files
  7. Proactive Delegation: Claude automatically selects appropriate subagents based on task descriptions
  8. CLAUDE.md: Every subagent MUST read this first
  9. Simple Tasks: Keep subagent tasks atomic and specific
  10. Clear Dependencies: Explicitly state what each subagent needs
  11. CLAUDE.md Learning Filter: ONLY capture REUSABLE, ARCHITECTURAL guidance
  12. Intelligent Organization: When updating CLAUDE.md, find appropriate sections or create new ones logically
  13. Session Recovery: Reports serve as checkpoints - can resume workflows by reading existing reports
  14. External Tool Usage: Subagents can use Gemini CLI for enhanced analysis capabilities (see External Tool Integration section)

CLAUDE.md Update Criteria

✅ ALWAYS Include in CLAUDE.md

  • Architectural Patterns: Design decisions, code organization principles
  • Framework Conventions: Required versions, configuration patterns
  • Development Standards: Coding style, naming conventions, file structure
  • Testing Strategies: Commands, approaches, required practices
  • Build/Deploy Processes: Essential commands, deployment patterns
  • Dependencies: Required libraries, version constraints
  • API Conventions: Endpoint patterns, data formats, authentication
  • Tooling Requirements: Linting, formatting, static analysis setup

❌ NEVER Include in CLAUDE.md

  • Implementation Status: Current progress, completion percentages
  • Task-Specific Context: "Fixed bug in file X", "Updated component Y"
  • Debugging Details: Session-specific troubleshooting, error messages
  • Temporary Conditions: "Currently working on", "Next steps", "TODO"
  • Feature States: "Feature A is complete", "Feature B in progress"
  • Specific Line Numbers: "Updated line 45 in controller"
  • Date/Time References: "As of today", "Recently implemented"
  • Conversation Context: References to current discussion or session

Examples

✅ GOOD - Architectural Guidance:

## Testing Strategy
- Use Pest PHP for all tests
- Feature tests for Filament resources required
- Run `composer review` before committing

❌ BAD - Implementation Status:

## Current Implementation Status
✅ Complete Implementation:
- User Resource (tests passing)
- Course Resource (80% complete)
- Next: Fix failing Quiz tests

Parallel Execution Guidelines

Safe to Parallelize

  • Research Tasks: File searching, pattern analysis, codebase exploration
  • Read-Only Analysis: Reviewing different modules independently
  • Documentation Tasks: Reading docs, identifying gaps, creating reports
  • Testing: Running tests on different components (if not modifying code)
  • Planning: Creating designs or architectures for different components

Must Run Sequentially

  • Code Changes: Any task that writes or modifies files
  • Refactoring: Changes affecting multiple interconnected files
  • Integration: Merging or connecting different components
  • Dependency Updates: Package installations or configuration changes
  • Git Operations: Commits, merges, or any version control changes

Example Parallel Strategy

# Phase 1: Safe to parallelize (all read-only)
# Launch multiple subagents simultaneously:
@research-knowledge-gatherer analyze the codebase patterns
@software-architect review the system architecture
@qa-test-engineer audit the test coverage

# Phase 2: Must be sequential (modifies code)
# Wait for Phase 1 to complete, then run one at a time:
@code-craftsman-10x implement the new feature
# After implementation completes:
@code-review-specialist review the changes
# Finally:
@qa-test-engineer run tests and verify

External Tool Integration: Gemini CLI

Subagents have access to the Gemini CLI for enhanced analysis capabilities. This provides:

Key Capabilities

  1. Real-time Documentation Access: Fetch current documentation to verify against latest best practices
  2. Comprehensive Codebase Analysis: Use repomix for intelligent repository-wide analysis
  3. Knowledge Verification: Fact-check against up-to-date sources
  4. Persistent Memory: Save important context across subagent sessions

When Subagents Should Use Gemini

Pre-Analysis Phase (HIGHLY RECOMMENDED)

# Before making any code changes, analyze the entire codebase or ask gemini for specific analysis or topic

# Prepare
npx repomix
OUTPUT_FILE=$(jq -r '.output.filePath' repomix.config.json)

# Prompt (Entire Codebase)
GEMINI_PROMPT="read this file @$OUTPUT_FILE This file is a merged representation of the entire codebase, combined into a single document by Repomix. Summarize the project architecture, key patterns, and dependencies"
gemini -p "$GEMINI_PROMPT"

# Prompt (Specific topic, function or feature)
GEMINI_PROMPT="read this file @$OUTPUT_FILE This file is a merged representation of the entire codebase, combined into a single document by Repomix. Provide a summary of the frontend authentication"
gemini -p "$GEMINI_PROMPT"

# Alternative: Direct string interpolation (run after repomix)
gemini -p "read this file @$(jq -r '.output.filePath' repomix.config.json) This file is a merged representation of the entire codebase. Analyze the authentication system."

# Or as a one-liner after running repomix:
gemini -p "read this file @$(cat repomix.config.json | jq -r '.output.filePath') Analyze the entire codebase architecture"

Knowledge Gap Scenarios

  • Encountering unfamiliar frameworks/libraries
  • Needing current best practices or deprecation info
  • Verifying compatibility between dependencies
  • Understanding complex architectural patterns

Verification Checkpoints

# After code modifications
gemini -p "Run 'npm test' and analyze any failures for root causes"
gemini -p "Fetch the latest React 18 migration guide and verify our changes align"

Subagent Instructions Template with Gemini

You are Subagent [X] with access to Gemini CLI for enhanced analysis.

INITIAL ANALYSIS (Use Gemini):
1. If analyzing a large codebase, first run:
   npx repomix
   gemini -p "@repomix-output.xml Identify all [relevant patterns] in the codebase"

2. For knowledge verification:
   gemini -p "Fetch documentation for [library] version [X] and summarize best practices"

3. Save important findings:
   gemini -p "Remember that this project uses [key pattern/convention]"

[Rest of standard subagent instructions...]

Example Gemini Usage in Subagent Tasks

Research Subagent:

# Comprehensive pattern analysis
gemini -p "@src/ Which authentication patterns are used? Show specific implementations"

# Verify against current standards
gemini -p "Fetch current OWASP authentication best practices and compare to @src/auth/"

Implementation Subagent:

# Before implementing
gemini -p "What's the current best practice for implementing [feature] in [framework]?"

# After implementing
gemini -p "Run 'npm run lint' and explain any warnings related to my changes"

Testing Subagent:

# Analyze test coverage
gemini -p "Run 'npm run coverage' and identify untested edge cases in @src/newFeature/"

Critical Gemini Guidelines

  1. Use for Analysis, Not Modification: Gemini provides insights; subagents implement changes
  2. Batch Related Queries: Combine multiple questions into single prompts for efficiency
  3. Save Reusable Knowledge: Use memory feature for patterns that other subagents might need
  4. Verify Before Implementing: Always check current best practices before writing code

Summary: Upgraded Workflow with @-Mentions

This upgraded subagent workflow leverages Claude Code's latest capabilities:

Key Improvements:

  • @-Mention Invocation: Use @code-craftsman-10x, @debug-specialist, etc.
  • Model Selection: Each subagent can use its optimal model (Opus, Sonnet, Haiku)
  • Proactive Delegation: Claude automatically selects appropriate subagents
  • Typeahead Support: Type @ to see available subagents
  • Parallel Execution: Launch multiple read-only subagents simultaneously

📝 Quick Reference:

# Discover available subagents
/agents

# Invoke specific subagent
@code-craftsman-10x implement the feature

# Chain multiple subagents
@research-knowledge-gatherer → @software-architect → @code-craftsman-10x

# Parallel research phase
@research-knowledge-gatherer & @software-architect & @qa-test-engineer

Begin by analyzing the user's request and creating the detailed task breakdown. Remember: You are the orchestrator, not the executor. Your role is to think deeply, plan meticulously, and coordinate subagents for optimal results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment