Create, adjust, improve, or optimize Claude Code subagents and skills...
You create and optimize Claude Code subagents, skills, and CLAUDE.md files.
For skills/agents:
For CLAUDE.md: Read references/claude-md-reference.md for the full review checklist, @import syntax, and inclusion/exclusion criteria (sourced from Anthropic official docs).
For detailed information beyond this file:
@import syntax, modular organizationUse SUBAGENT when:
Use SKILL when:
disable-model-invocation: trueuser-invocable: falseDefault to skill - simpler, runs in main context.
When a skill needs parallel workers, it can orchestrate an agent team internally. See "Agent Teams in Skills" under Best Practices and references/agent-teams-reference.md for the full guide.
Create .claude/skills/<name>/SKILL.md (project-level) or skills/<name>/SKILL.md (plugin-level):
---
name: my-skill
description: What it does. Use when [triggers]. Helps with [use cases].
disable-model-invocation: true # Add for workflows with side effects
---
Instructions Claude follows when skill is invoked.
Supporting files go in the skill directory:
my-skill/
├── SKILL.md # Main instructions (required)
├── references/ # Detailed docs loaded when needed
│ └── checklist.md
└── scripts/ # Executable scripts
└── helper.sh
Create .claude/agents/<name>.md (project-level) or agents/<name>.md (plugin-level):
---
name: my-agent
description: What it does. Use proactively when [triggers].
tools: Read, Glob, Grep, Bash
model: sonnet
permissionMode: dontAsk # Add for read-only agents (auto-deny writes)
---
You are a specialist in [domain]. When invoked:
1. [First action]
2. [Second action]
3. Return summary of findings/changes.
| Field | Description |
|---|---|
name |
Slash command name (defaults to directory). Lowercase, numbers, hyphens only, max 64 chars |
description |
Critical - triggers auto-discovery. Falls back to first paragraph if omitted |
argument-hint |
Autocomplete hint: [issue-number] |
disable-model-invocation |
true = only user can invoke |
user-invocable |
false = hidden from / menu |
allowed-tools |
Tools without permission prompts |
model |
Model override: sonnet, opus, haiku |
context |
fork = run in isolated subagent |
agent |
Subagent type when forked |
hooks |
Lifecycle hooks (PreToolUse, PostToolUse) |
| Field | Description |
|---|---|
name |
Unique identifier (lowercase, hyphens). Required |
description |
Critical - when Claude delegates. Required |
tools |
Allowlist (inherits all including MCP if omitted). Use Task(type1, type2) to restrict spawnable agents |
disallowedTools |
Denylist from inherited tools |
model |
sonnet, opus, haiku, inherit (default: inherit) |
permissionMode |
default, acceptEdits, delegate, dontAsk, bypassPermissions, plan |
maxTurns |
Max agentic turns before stopping |
skills |
Preload full skill content at startup |
mcpServers |
MCP servers available (name reference or inline config) |
memory |
Persistent memory scope: user, project, or local |
background |
true = always run as background task (concurrent, no MCP) |
isolation |
worktree = run in temporary git worktree (auto-cleaned if no changes) |
hooks |
PreToolUse, PostToolUse, Stop (SubagentStart/SubagentStop in settings.json only) |
| Variable | Description |
|---|---|
$ARGUMENTS |
All arguments passed |
$ARGUMENTS[N] or $N |
Positional argument (0-indexed) |
${CLAUDE_SESSION_ID} |
Current session ID |
!{backtick}command{backtick} |
Dynamic command output (runs before Claude sees content). Syntax: exclamation + backtick-wrapped shell command |
---
name: code-reviewer
description: Reviews code quality. Use proactively after writing code.
tools: Read, Grep, Glob, Bash
model: sonnet
---
Review code for quality, security, and best practices.
Run git diff to see changes. Provide feedback by priority.
---
name: deploy
description: Deploy to production
disable-model-invocation: true
context: fork
allowed-tools: Bash, Read
---
Deploy $ARGUMENTS:
1. Run tests
2. Build
3. Push to target
---
name: legacy-context
description: Context about legacy system. Use when working with payment code.
user-invocable: false
---
Legacy payment system uses SOAP API, XML config, stored procedures.
Key files: src/payments/legacy-adapter.ts
---
name: parallel-review
description: Parallel code review with specialized reviewers
allowed-tools: Read, Glob, Grep, Task, Bash, TeamCreate, TeamDelete,
SendMessage, TaskCreate, TaskUpdate, TaskList, TaskGet
disable-model-invocation: true
---
1. TeamCreate → TaskCreate (one per reviewer) → spawn teammates
2. Wait for findings messages (auto-delivered)
3. Merge, deduplicate, act on results
4. Shutdown teammates → TeamDelete
Fallback: if TeamCreate fails, use sequential Task subagents
---
name: db-reader
description: Execute read-only SQL queries
tools: Bash
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate-readonly.sh"
---
Hook script (exit 2 to block):
#!/bin/bash
INPUT=$(cat)
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
if echo "$CMD" | grep -iE '\b(INSERT|UPDATE|DELETE|DROP)\b' >/dev/null; then
echo "Blocked: Only SELECT allowed" >&2
exit 2
fi
exit 0
Hooks support three types beyond shell commands:
| Type | Use For | Example |
|---|---|---|
command |
Shell script validation | "command": "./scripts/validate.sh" |
prompt |
LLM yes/no decision (uses Haiku) | "prompt": "Check if all tasks are complete" |
agent |
Multi-turn validation with tool access | "prompt": "Run tests and verify", "timeout": 120 |
prompt and agent hooks return structured JSON with permissionDecision: "allow", "deny", or "ask".
Claude uses descriptions for auto-discovery. Follow the [what] + [when] + [features] formula:
Poor: "Helps with code"
Good: "Explains code using diagrams and analogies. Use when describing how code works, teaching about codebases, or answering 'how does this work?' questions."
Test: ask Claude "When should this skill be used?" — if the answer doesn't match your intent, refine the description.
Skills load in 3 stages to optimize context:
name + description always in contextDesign skills with this in mind: keep SKILL.md focused; put large docs in supporting files.
Keep SKILL.md under 500 lines - Use supporting files in the skill's own directory for details.
Skills are self-contained - Each skill directory is independent. There is NO shared directory pattern across skills. Supporting files go in <skill>/references/ or similar subdirectories within that skill.
Extended thinking — Include the word "ultrathink" in skill content to enable extended thinking.
Reducing duplication across skills:
user-invocable: false for shared knowledge Claude auto-loads| Scenario | Frontmatter |
|---|---|
| Side effects (deploy, commit, modify files) | disable-model-invocation: true |
| Background knowledge (not a command) | user-invocable: false |
| Safe for Claude to auto-invoke | (default - no flags) |
Limit tool access - Grant only what's needed via tools or allowed-tools.
Permission modes for subagents:
default - Standard promptsdontAsk - Auto-deny prompts (use for read-only agents)acceptEdits - Auto-accept file editsdelegate - Coordination-only (for agent team leads, restricts to team management tools)bypassPermissions - Skip all checks (dangerous)Match model to task complexity:
haiku - Fast, cheap (exploration, simple validation, tests)sonnet - Balanced (code review, git operations, implementation)opus - Complex reasoning, bug detection, critical decisionsMax 3-4 custom subagents - Too many reduces productivity and confuses delegation.
When a skill needs parallel workers (code review, parallel implementation, competing hypotheses), it can orchestrate an agent team. Requires CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1. See references/agent-teams-reference.md for full guide.
When to use teams inside a skill:
Key rules for team-orchestrating skills:
_workers/worker-N/) with own branch; domain-based assignment allowed. Review-only workers (code-audit, frontend-review) share the main directory safely. Fallback: partition by file ownership if worktrees unavailableTeamCreate fails, fall back to sequential subagentsRequired allowed-tools for team skills:
TeamCreate, TeamDelete, SendMessage, TaskCreate, TaskUpdate, TaskList, TaskGet, Task
Skill lifecycle with teams:
TeamCreate → TaskCreate (one per work unit) → spawn teammates via Task with team_nameTaskUpdateTeamDelete| Type | Project | User (all projects) |
|---|---|---|
| Skill | .claude/skills/<name>/SKILL.md |
~/.claude/skills/<name>/SKILL.md |
| Subagent | .claude/agents/<name>.md |
~/.claude/agents/<name>.md |
Priority: CLI flag > project > user > plugin
For complete reference, see:
Local references: See references/skills-reference.md, references/subagents-reference.md, and references/agent-teams-reference.md for detailed lookup tables.