Skills, Commands, Subagents or Hooks: Which to Use
Claude Code gives you four ways to make behaviour reusable, and they overlap. Pick by asking two questions: must it happen every time, and does it need its own room to work? A rule that must always hold is a hook. A big side task is a subagent. Know-how is a skill. A prompt you type often is a command.
What to consider
- Must it always happen? The model can skip an instruction. A hook cannot.
- How much will it read? Long searches and reviews fill the context window. A subagent keeps them out of it.
- Who starts it? The agent on its own, or you by name.
At a glance
| Skill | Slash command | Subagent | Hook | |
|---|---|---|---|---|
| Lives in | .claude/skills/x/SKILL.md | .claude/commands/x.md | .claude/agents/x.md | .claude/settings.json |
| Starts | When a task matches, or /x | When you type /x | When Claude delegates, or you ask | On an event, every time |
| Runs in | The main conversation | The main conversation | Its own context window | Outside the model, as a shell command |
| Use it when | The agent should recognise a task on its own | You want a shortcut for a prompt | A side task would flood the context | A rule must hold every time |
Pick one
flowchart LR
A[Behaviour you want again and again] --> B{Must it happen every time, with no exceptions?}
B -- yes --> H[Hook]
B -- no --> C{Does it need lots of reading or searching?}
C -- yes --> S[Subagent]
C -- no --> D{Should the agent pick it up on its own?}
D -- yes --> K[Skill]
D -- no --> M[Slash command]
Hook: format every file Claude edits
Hooks run your command, not the model, so they never forget. This one formats each file after an edit. The hook receives the tool call as JSON on standard input.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{ "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write" }
]
}
]
}
}
Subagent: review code in a separate context
A subagent works in its own context window and returns only its conclusion, so a long search or review does not crowd your main conversation.
---
name: code-reviewer
description: Reviews a diff for bugs and missing tests. Use after a change is complete.
tools: Read, Grep, Glob
---
You review code changes. List each problem with the file, the line,
and the input that breaks it. Do not edit files.
Skill: teach a repeatable task
Use a skill when the agent should recognise the task on its own, such as writing release notes or following your deploy checklist. See How to Create a Claude Code Skill for the full setup.
Slash command: a prompt you type often
Fix GitHub issue #$ARGUMENTS. Read the issue with `gh issue view`,
write a failing test, fix it, and run the suite.
Save it as .claude/commands/fix-issue.md, then type /fix-issue 123. Claude Code now treats commands as a kind of skill: existing .claude/commands/ files keep working, and for new work a skill with disable-model-invocation: true does the same job and can bundle files.
Move a prompt you keep pasting in three steps
- Find it. Look for any instruction you have pasted more than twice this week.
- Place it. Run it through the chart above.
- Test it. Create the file and check that it starts when you expect and not otherwise.