$npx -y skills add NeoLabHQ/context-engineering-kit --skill create-agentComprehensive guide for creating Claude Code agents with proper structure, triggering conditions, system prompts, and validation - combines official Anthropic best practices with proven patterns
| 1 | # Create Agent Command |
| 2 | |
| 3 | Create autonomous Claude Code agents that handle complex, multi-step tasks independently. This command provides comprehensive guidance based on official Anthropic documentation and proven patterns. |
| 4 | |
| 5 | ## User Input |
| 6 | |
| 7 | ```text |
| 8 | Agent Name: $1 |
| 9 | Description: $2 |
| 10 | ``` |
| 11 | |
| 12 | ## What Are Agents? |
| 13 | |
| 14 | Agents are **autonomous subprocesses** spawned via the Task tool that: |
| 15 | |
| 16 | - Handle complex, multi-step tasks independently |
| 17 | - Have their own isolated context window |
| 18 | - Return results to the parent conversation |
| 19 | - Can be specialized for specific domains |
| 20 | |
| 21 | | Concept | Agent | Command | |
| 22 | |---------|-------|---------| |
| 23 | | **Trigger** | Claude decides based on description | User invokes with `/name` | |
| 24 | | **Purpose** | Autonomous work | User-initiated actions | |
| 25 | | **Context** | Isolated subprocess | Shared conversation | |
| 26 | | **File format** | `agents/*.md` | `commands/*.md` | |
| 27 | |
| 28 | ## Agent File Structure |
| 29 | |
| 30 | Agents use a unique format combining **YAML frontmatter** with a **markdown system prompt**: |
| 31 | |
| 32 | ```markdown |
| 33 | --- |
| 34 | name: agent-identifier |
| 35 | description: Use this agent when [triggering conditions]. Examples: |
| 36 | |
| 37 | <example> |
| 38 | Context: [Situation description] |
| 39 | user: "[User request]" |
| 40 | assistant: "[How assistant should respond and use this agent]" |
| 41 | <commentary> |
| 42 | [Why this agent should be triggered] |
| 43 | </commentary> |
| 44 | </example> |
| 45 | |
| 46 | <example> |
| 47 | [Additional example...] |
| 48 | </example> |
| 49 | |
| 50 | model: inherit |
| 51 | color: blue |
| 52 | tools: ["Read", "Write", "Grep"] |
| 53 | --- |
| 54 | |
| 55 | You are [agent role description]... |
| 56 | |
| 57 | **Your Core Responsibilities:** |
| 58 | 1. [Responsibility 1] |
| 59 | 2. [Responsibility 2] |
| 60 | |
| 61 | **Analysis Process:** |
| 62 | [Step-by-step workflow] |
| 63 | |
| 64 | **Output Format:** |
| 65 | [What to return] |
| 66 | ``` |
| 67 | |
| 68 | ## Frontmatter Fields Reference |
| 69 | |
| 70 | ### Required Fields |
| 71 | |
| 72 | #### `name` (Required) |
| 73 | |
| 74 | **Format**: Lowercase with hyphens only |
| 75 | **Length**: 3-50 characters |
| 76 | **Rules**: |
| 77 | |
| 78 | - Must start and end with alphanumeric character |
| 79 | - Only lowercase letters, numbers, and hyphens |
| 80 | - No underscores, spaces, or special characters |
| 81 | |
| 82 | | Valid | Invalid | Reason | |
| 83 | |-------|---------|--------| |
| 84 | | `code-reviewer` | `helper` | Too generic | |
| 85 | | `test-generator` | `-agent-` | Starts/ends with hyphen | |
| 86 | | `api-docs-writer` | `my_agent` | Underscores not allowed | |
| 87 | | `security-analyzer` | `ag` | Too short (<3 chars) | |
| 88 | | `pr-quality-reviewer` | `MyAgent` | Uppercase not allowed | |
| 89 | |
| 90 | #### `description` (Required, Critical) |
| 91 | |
| 92 | **The most important field** - Defines when Claude triggers the agent. |
| 93 | |
| 94 | **Requirements**: |
| 95 | |
| 96 | - Length: 10-5,000 characters (ideal: 200-1,000 with 2-4 examples) |
| 97 | - **MUST start with**: "Use this agent when..." |
| 98 | - **MUST include**: `<example>` blocks showing usage patterns |
| 99 | - Each example needs: context, user request, assistant response, commentary |
| 100 | |
| 101 | **Example Block Format**: |
| 102 | |
| 103 | ```markdown |
| 104 | <example> |
| 105 | Context: [Describe the situation - what led to this interaction] |
| 106 | user: "[Exact user message or request]" |
| 107 | assistant: "[How Claude should respond before triggering]" |
| 108 | <commentary> |
| 109 | [Explanation of why this agent should be triggered in this scenario] |
| 110 | </commentary> |
| 111 | assistant: "[How Claude triggers the agent - 'I'll use the [agent-name] agent...']" |
| 112 | </example> |
| 113 | ``` |
| 114 | |
| 115 | **Best Practices for Descriptions**: |
| 116 | |
| 117 | - Include 2-4 concrete examples |
| 118 | - Show both proactive and reactive triggering scenarios |
| 119 | - Cover different phrasings of the same intent |
| 120 | - Explain reasoning in commentary |
| 121 | - Be specific about when NOT to use the agent |
| 122 | |
| 123 | #### `model` (Required) |
| 124 | |
| 125 | **Values**: `inherit`, `sonnet`, `opus`, `haiku` |
| 126 | **Default**: `inherit` (recommended) |
| 127 | |
| 128 | | Value | Use Case | Cost | |
| 129 | |-------|----------|------| |
| 130 | | `inherit` | Use parent conversation model | Default | |
| 131 | | `haiku` | Fast, simple tasks | Lowest | |
| 132 | | `sonnet` | Balanced performance | Medium | |
| 133 | | `opus` | Maximum capability, complex reasoning | Highest | |
| 134 | |
| 135 | **Recommendation**: Use `inherit` unless you have a specific reason to override. |
| 136 | |
| 137 | #### `color` (Required) |
| 138 | |
| 139 | **Purpose**: Visual indicator in UI to distinguish agents |
| 140 | |
| 141 | **Values**: `blue`, `cyan`, `green`, `yellow`, `magenta`, `red` |
| 142 | |
| 143 | **Best Practice**: Use different colors for different agents in the same plugin to distinguish them visually. |
| 144 | |
| 145 | ### Optional Fields |
| 146 | |
| 147 | #### `tools` (Optional) |
| 148 | |
| 149 | **Purpose**: Restrict available tools (principle of least privilege) |
| 150 | **Format**: Array of tool names |
| 151 | **Default**: All tools available |
| 152 | |
| 153 | ```yaml |
| 154 | # Common tool restrictions |
| 155 | tools: ["Read", "Grep", "Glob"] # Read-only analysis |
| 156 | tools: ["Read", "Write", "Grep", "Glob"] # Code modification |
| 157 | tools: ["Read", "Bash", "Grep"] # System operations |
| 158 | ``` |
| 159 | |
| 160 | **Security Principle**: Only grant tools the agent actually needs. |
| 161 | |
| 162 | ## Triggering Patterns |
| 163 | |
| 164 | ### Pattern 1: Explicit Request |
| 165 | |
| 166 | User directly asks for the agent's function. |
| 167 | |
| 168 | ```markdown |
| 169 | <example> |
| 170 | Context: User |