Quick Reference
%{
  subagents: [
    %{
      name: "agent-name",           # Required: kebab-case
      description: "MUST BE USED...", # Required: delegation trigger
      prompt: "You are...",          # Required: system prompt
      tools: [:read, :write],        # Optional: defaults to all
      usage_rules: [:package]        # Optional: best practices
    }
  ]
}
Field Reference
| Field | Required | Description | Example | 
|---|
| name | ✓ | Agent identifier (kebab-case) | "test-expert" | 
| description | ✓ | Delegation trigger | "MUST BE USED for tests" | 
| prompt | ✓ | System instructions | "You are a test expert..." | 
| tools |  | Tool restrictions | [:read, :grep, :bash] | 
| usage_rules |  | Package best practices | [:usage_rules_elixir] | 
Creation Methods
# Method 1: Meta Agent (Recommended)
# Just ask Claude: "Create a sub-agent for GraphQL"
# Method 2: Interactive Generator
mix claude.gen.subagent
# Method 3: Manual
# Edit .claude.exs then run:
mix claude.install
| Config | Behavior | Use Case | 
|---|
| toolsomitted | Inherits all tools + MCP | Maximum flexibility | 
| tools: [...] | Static list only | Security/performance | 
| No :task | Cannot delegate | Prevent loops | 
# Package root rules
:package_name              # deps/package_name/usage-rules.md
# All package rules  
"package_name:all"         # deps/package_name/usage-rules/*
# Specific sub-rule
"package_name:subrule"     # deps/package_name/usage-rules/subrule.md
# Special cases
:usage_rules_elixir        # Elixir best practices
:usage_rules_otp           # OTP patterns
Design Principles
# ❌ Bad: Assumes context
prompt: "Continue from where we left off..."
# ✅ Good: Self-contained
prompt: """
## Context Discovery
1. Check priv/repo/migrations/
2. Read latest migration
3. Check lib/*/repo.ex
"""
- Specify files: "Check lib/app/schema.ex first"
- Use patterns: grep "defmodule.*Schema"notread **/*
- Limit reads: Don't read entire directories
- Clean slate: Each invocation starts fresh
Common Patterns
# Database Expert
%{
  name: "database-expert",
  description: "MUST BE USED for migrations and schema",
  tools: [:read, :write, :grep, :bash],
  prompt: """
  ## Check First
  - priv/repo/migrations/
  - lib/*/schemas/
  """
}
# Test Specialist
%{
  name: "test-expert",
  description: "MUST BE USED for ExUnit tests",
  tools: [:read, :write, :edit, :bash],
  usage_rules: [:usage_rules_elixir]
}
# Phoenix Expert
%{
  name: "phoenix-expert",
  description: "MUST BE USED for controllers and views",
  tools: [:read, :edit, :grep],
  usage_rules: [:phoenix]  # If Phoenix 1.8+
}
Troubleshooting
| Issue | Solution | 
|---|
| Agent not invoked | Check descriptionstarts with "MUST BE USED" | 
| Missing tools | Omit toolsfield to inherit all | 
| No memory | Design prompts to be self-contained | 
| Slow performance | Limit initial file reads | 
| Delegation loops | Don't include :tasktool |