creating-agents
Expert guidance for creating Claude Code subagents and multi-agent workflows. Use when designing new subagents, configuring agent tools/permissions, implementing orchestration patterns, or troubleshooting agent delegation.
What this skill does
# Creating Claude Code Agents Expert guidance for designing and implementing Claude Code subagents based on Anthropic's official specification and industry best practices. ## Core principles Subagents solve three fundamental problems: ### 1. Context Preservation Main conversation context is precious. Subagents isolate verbose operations (test runs, documentation fetches, log analysis) and return only summaries. **Without subagents:** Running tests consumes 50K+ tokens in your main context **With subagents:** Test output stays in subagent context; you get a 500-token summary ### 2. Parallelization Launch multiple subagents simultaneously for independent tasks: ``` Research the authentication, database, and API modules in parallel using separate subagents ``` Each explores its area independently, then Claude synthesizes findings. ### 3. Specialization A single agent handling everything becomes a "jack of all trades, master of none." As instruction complexity increases, reliability decreases. Subagents enable focused expertise with minimal tool access. ## How Delegation Works Claude automatically delegates based on each subagent's `description` field. Write clear descriptions that include: - **What it does**: "Reviews code for quality and security" - **When to use it**: "Use proactively after code changes" - **Trigger keywords**: Include terms users might say **Good description:** ```yaml description: Reviews code for quality, security, and best practices. Use proactively after code changes or when user mentions review, audit, or code quality. ``` **Bad description:** ```yaml description: Helps with code ``` ## Agent Design Principles ### 1. Single Responsibility Each subagent should excel at ONE specific task. Don't create a "helper" agent that does everything. **Good:** `code-reviewer`, `test-runner`, `doc-researcher` **Bad:** `general-helper`, `code-assistant`, `utility-agent` ### 2. Minimal Tool Access Grant only the tools necessary for the task: | Role | Recommended Tools | | ---- | ----------------- | | Reviewer/Auditor | Read, Grep, Glob | | Researcher | Read, Grep, Glob, WebFetch, WebSearch | | Implementer | Read, Write, Edit, Bash, Glob, Grep | | Domain Expert | Read, Grep, Glob + domain-specific | See [references/tool-permissions.md](references/tool-permissions.md) for detailed guidance. ### 3. Clear System Prompts The markdown body becomes the subagent's system prompt. Be specific about: - When to use which approach - Output format expectations - What NOT to do (constraints) ### 4. Model Selection - **haiku**: Fast, cheap - ideal for read-only exploration - **sonnet**: Balanced - good for most tasks - **opus**: Most capable - use for complex reasoning - **inherit**: Uses main conversation model (default) ## YAML Frontmatter Reference | Field | Required | Description | | ----- | -------- | ----------- | | `name` | Yes | Unique identifier (lowercase, hyphens) | | `description` | Yes | When Claude should delegate | | `tools` | No | Tools the agent can use (inherits all if omitted) | | `disallowedTools` | No | Tools to explicitly deny | | `model` | No | Model to use (default: inherit) | | `permissionMode` | No | Permission handling mode | | `skills` | No | Skills to preload into context | | `hooks` | No | Lifecycle hooks for this agent | See [references/official-spec.md](references/official-spec.md) for complete specification. ## Orchestration Patterns ### Fan-Out (Parallel Research) Multiple agents explore different areas simultaneously: ``` Use subagents to research authentication patterns, database schema, and API design in parallel ``` Best for: Independent research tasks, codebase exploration, documentation gathering. ### Pipeline (Sequential Processing) Chain agents where each builds on previous results: ``` First use code-reviewer to find issues, then use debugger to fix them ``` Best for: Review-then-fix workflows, multi-stage processing. ### Orchestrator-Worker A lead agent decomposes tasks and delegates to specialists: ``` Analyze this feature request and delegate implementation to appropriate specialists ``` Best for: Complex features, large-scale refactoring. See [references/orchestration-patterns.md](references/orchestration-patterns.md) for detailed patterns. ## Common Anti-Patterns Avoid these mistakes when creating agents: | Anti-Pattern | Problem | Solution | | ------------ | ------- | -------- | | Vague description | Claude doesn't know when to delegate | Include specific trigger keywords | | Over-broad tools | Security risk, unfocused behavior | Grant minimal necessary permissions | | No verification | Can't tell if agent succeeded | Include verification steps in prompt | | Premature complexity | Multi-agent when single suffices | Start simple, add agents as needed | | Generic naming | Hard to discover and delegate | Use specific, task-focused names | See [references/anti-patterns.md](references/anti-patterns.md) for detailed guidance. ## What Would You Like To Do? 1. **Create a new agent** - Step-by-step workflow guides 2. **Use a template** - Copy and customize ready-made agents 3. **Audit an existing agent** - Check against best practices 4. **Learn design patterns** - Understand orchestration and anti-patterns --- ### 1. Create a New Agent Choose by agent type: - [Read-only agent](workflows/create-read-only-agent.md) - Reviewers, analyzers, auditors - [Code writer agent](workflows/create-code-writer-agent.md) - Implementers, fixers, generators - [Research agent](workflows/create-research-agent.md) - Documentation and web researchers ### 2. Use a Template Ready-to-use agents you can customize: - [Code reviewer](templates/code-reviewer.md) - Quality and security review - [Debugger](templates/debugger.md) - Bug diagnosis and fixing - [Researcher](templates/researcher.md) - Web and documentation research - [Domain expert](templates/domain-expert.md) - Specialized domain expertise ### 3. Audit an Existing Agent - [Audit workflow](workflows/audit-existing-agent.md) - Checklist and improvement process ### 4. Learn Design Patterns - [Orchestration patterns](references/orchestration-patterns.md) - Fan-out, pipeline, orchestrator-worker - [Tool permissions](references/tool-permissions.md) - Selecting tools by role - [Anti-patterns](references/anti-patterns.md) - Common mistakes to avoid ## Testing Your Agent ### 1. Manual Testing ``` # Test delegation Use the [agent-name] to [task description] # Test automatic delegation (if description says "use proactively") [Task that should trigger the agent] ``` ### 2. Verify Tool Access Check the agent has exactly the tools it needs, no more: ``` Use [agent-name] to describe what tools you have access to ``` ### 3. Test with Different Models If you set `model: haiku` for speed, ensure instructions are clear enough: - Haiku needs explicit, step-by-step instructions - Sonnet/Opus can infer more from context ### 4. Check Edge Cases - What happens if the agent can't find what it needs? - Does it fail gracefully or loop indefinitely? - Are error messages helpful? ## Storage Locations | Location | Scope | Use Case | | -------- | ----- | -------- | | `.claude/agents/` | Current project | Team-shared, version-controlled | | `~/.claude/agents/` | All your projects | Personal agents | | `--agents` CLI flag | Current session | Testing, automation | | Plugin `agents/` | Where plugin enabled | Distributed via plugin | Higher-priority locations override lower when names conflict. ## Real-World Examples See [examples/real-world-agents.md](examples/real-world-agents.md) for battle-tested agents including: - Security auditor - Performance analyzer - Documentation generator - Test writer - Migration assistant ## Success Criteria A well-designed agent: - [ ] Has a **single responsibility** - one job, minimal tools - [ ] Has a **specific description** with trigger keywords (what AND when) - [ ] Uses **minimal tool access** appr
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.