Detailed guide for each Claude Code configuration type.
Purpose: Specialized subagents for delegated tasks with limited scope.
Create an agent when you need:
- Focused expertise on a specific domain (security, architecture, testing)
- Limited tool access (don't need full toolset)
- Reusable specialist that can be invoked across projects
- Separation of concerns in complex workflows
---
name: agent-name
description: What this agent does. When to use it. Be specific about triggers.
tools: Read, Grep, Glob, Bash # Limit to what's needed
model: opus # or sonnet for faster/simpler tasks
---
You are a [role] specialist focused on [primary goal].
## Your Role
- Responsibility 1
- Responsibility 2
## Process
### 1. Phase Name
- Step 1
- Step 2
## Output Format
[Define expected output structure]
## Best Practices
[Domain-specific guidance]| Field | Purpose | Examples |
|---|---|---|
name |
Identifier for invocation | planner, code-reviewer |
description |
Triggers automatic invocation | Include "Use when..." |
tools |
Limited tool access | Read, Grep, Glob, Bash |
model |
Model selection | opus (complex), sonnet (fast) |
- Limit Tools: Agents don't need full toolset. Give only what's required.
- Specific Description: Include trigger phrases so Claude knows when to delegate.
- Clear Process: Define step-by-step workflow.
- Output Format: Specify expected output structure.
- Model Selection: Use
opusfor complex reasoning,sonnetfor simpler tasks.
Purpose: Always-follow guidelines loaded into every session.
Create a rule when you need:
- Non-negotiable invariants (security, style)
- Automated enforcement without user prompting
- Universal application across all projects
- Checklists that must be verified
# Rule Name Guidelines
## Mandatory Checks
Before [trigger action]:
- [ ] Check 1
- [ ] Check 2
## Category 1
```code
// NEVER: Bad example
bad_code
// ALWAYS: Good example
good_codeIf [violation] found:
- Action 1
- Action 2
### Best Practices
1. **Keep Concise**: Rules are always loaded - minimize token usage.
2. **Use Checklists**: Easy to verify compliance.
3. **Show Examples**: NEVER/ALWAYS patterns are clear.
4. **Define Protocols**: What to do when violations found.
5. **Non-Negotiable Only**: Rules should be invariants, not preferences.
---
## 3. Commands (`~/.claude/commands/`)
**Purpose**: Slash commands for quick execution (`/command-name`).
### When to Create a Command
Create a command when you need:
- User-triggered workflow (not automatic)
- Repeatable process with consistent output
- Quick access to complex operations
- Standardized workflow invocation
### Command Structure
```markdown
---
description: What this command does in one line.
---
# Command Name
## What This Command Does
[Explanation]
## When to Use
[Triggers]
## How It Works
[Process steps]
## Example Usage
[Concrete example with input/output]
## Related Agents
[Which agent this command invokes]
- Action-Oriented Description: Start with verb (e.g., "Enforce test-driven...")
- Clear Triggers: When should user invoke this?
- Concrete Examples: Show realistic input/output.
- Link to Agents: Commands often invoke specialized agents.
- Wait for Confirmation: Some commands (like
/plan) should wait before acting.
Purpose: Trigger-based automations fired on tool events.
Create a hook when you need:
- Automatic actions before/after tool use
- Guardrails and safety checks
- Automated formatting or validation
- Session lifecycle management
| Type | When Fired | Use Case |
|---|---|---|
PreToolUse |
Before tool executes | Block unsafe commands, warn about patterns |
PostToolUse |
After tool executes | Auto-format, lint, validate |
PreCompact |
Before context compaction | Save state |
SessionStart |
New session begins | Load previous context |
Stop |
Session ends | Final audits, persist state |
{
"hooks": {
"PreToolUse": [
{
"matcher": "tool == \"Bash\" && tool_input.command matches \"pattern\"",
"hooks": [
{
"type": "command",
"command": "#!/bin/bash\ninput=$(cat)\n# Logic here\necho \"$input\""
}
],
"description": "What this hook does"
}
]
}
}tool == "ToolName" # Match specific tool
tool_input.field matches "pattern" # Match field with regex
* # Match all
- Specific Matchers: Don't use
*unless necessary. - Exit Codes:
exit 1to block,exit 0to allow. - Pass Through Input: Always
echo "$input"at end to allow tool execution. - Descriptive Messages:
echo '[Hook] MESSAGE' >&2for user feedback. - Test Thoroughly: Hooks can break workflows if misconfigured.
Purpose: Domain knowledge and workflow definitions.
Create a skill when you need:
- Project-specific knowledge (schemas, APIs, patterns)
- Framework-specific guidance
- Reusable workflow that spans multiple commands
- Documentation that Claude needs to reference
skill-name/
├── SKILL.md # Main skill file
├── references/ # Supporting documentation
│ └── detailed-guide.md
└── assets/ # Templates, scripts
└── template.md
- Concise SKILL.md: Keep under 500 lines.
- Progressive Disclosure: Put details in references/.
- Clear Triggers: Description should specify when to use.
- No Redundancy: Don't duplicate content between SKILL.md and references.
- Templates in Assets: Things to copy, not read into context.
Purpose: Project context and personal preferences.
Put in your project root for:
- Project overview and tech stack
- Build/test commands
- File structure documentation
- Project-specific patterns
- Environment variables
Put in ~/.claude/ for:
- Personal coding preferences
- Universal rules you always want
- Links to your modular rules/agents
- Editor integration notes
- Project-Specific in Project: Don't duplicate user-level content.
- Link to Rules: Reference
~/.claude/rules/instead of duplicating. - Keep Updated: Update CLAUDE.md as project evolves.
- Quick Reference: Include command reference for fast lookup.