Claude Code Hooks vs Slash Commands vs Prompt Instructions
7 min read · Reviewed 2026-06-12
There are several ways to shape how Claude Code behaves: prompt instructions, slash commands, hooks, and MCP servers. They look interchangeable but they sit at very different levels of control — and only one of them is guaranteed to run.
This guide compares them with concrete examples — an actual slash command file next to an actual hook — so you know which tool to reach for and how to combine them.
Hooks vs slash commands vs prompt instructions: what is the difference?
Prompt instructions are text the model reads and usually follows. Slash commands are reusable prompts you invoke on demand inside the conversation. Hooks are commands that fire outside the model on lifecycle events. The first two steer the AI; the third constrains it.
What does a slash command look like?
A slash command is just a Markdown file in .claude/commands/. Its filename becomes the command name, and its body is a prompt the model reads when you type the command. Here is /gen-test — type it and the model writes tests for the current file:
<!-- .claude/commands/gen-test.md -->
---
description: Generate unit tests for the current file
---
Write thorough unit tests for the file I'm currently editing.
Cover the happy path, edge cases, and error handling.
Use the project's existing test framework and conventions.When you type /gen-test, Claude Code injects this prompt into the conversation and the model acts on it. It is interpreted by the model, runs inside the context window, and only happens when you trigger it.
What does a hook look like by comparison?
A hook is a command on disk plus a registration in settings.json. It is not a prompt — the model never reads it. Here is a hook that runs your tests every time Claude says it is done, registered on the Stop event:
// .claude/settings.json
{
"hooks": {
"Stop": [
{
"hooks": [
{ "type": "command", "command": "node $CLAUDE_PROJECT_DIR/.claude/hooks/stop-run-tests.mjs" }
]
}
]
}
}The Stop event has no matcher — it always fires when Claude finishes. The script runs in its own process, runs the test suite, and reports failures back. The model did not decide to run it and cannot skip it. That is the structural difference: a slash command is an instruction you give the model; a hook is a rule the runtime enforces around the model.
What are prompt instructions (CLAUDE.md)?
Prompt instructions live in your prompt or in a CLAUDE.md file the model loads as context. They are perfect for soft guidance — coding style, tone, architectural preferences — but they are probabilistic. The model may follow them, may interpret them loosely, or may decide an exception applies.
Do hooks really cost zero tokens?
A hook runs in a separate process, so its logic never enters the context window — that part genuinely costs nothing. But the claim is often overstated. The moment a hook prints text back to the model, that text consumes tokens: a PreToolUse hook that blocks with a reason, or a UserPromptSubmit hook that injects context, both add to the conversation. A silent hook is free; a talkative one is not. The win is that you control exactly what (if anything) reaches the model, instead of paying for instructions the model re-reads every turn.
How are hooks different from MCP servers?
MCP (Model Context Protocol) servers and hooks solve opposite problems. An MCP server adds capabilities: it gives the model new tools and data sources — a database it can query, an API it can call, a knowledge base it can read. Hooks govern the lifecycle: they sit around the tools the model already has and decide what is allowed, what gets logged, and what runs automatically.
- MCP server → expand what Claude can do (new tools, new data).
- Hook → constrain and automate how Claude uses the tools it already has.
They are complementary. You might add an MCP server for your internal API, then add a PreToolUse hook that blocks calls to it without the right scope.
When should you use each?
- Prompt instructions / CLAUDE.md → soft guidance and preferences.
- Slash commands → on-demand, interactive tasks you trigger yourself.
- Hooks → guarantees: guardrails, gates, and automation that must run every time.
- MCP servers → new capabilities and data the model would not otherwise have.
Can you combine them?
Yes — and the best setups do. Use CLAUDE.md to set direction, slash commands for repeatable tasks, MCP servers for new capabilities, and hooks to enforce the non-negotiables (run tests, block secrets, protect main). They are layers, not alternatives.
Frequently asked questions
- Are hooks better than slash commands?
- They do different jobs. Slash commands are interactive prompts you trigger; hooks are commands the runtime fires automatically and the model cannot skip. Use both.
- Do hooks replace CLAUDE.md?
- No. CLAUDE.md is great for soft guidance the model interprets. Hooks enforce the rules that must hold regardless of what the model decides.
- Do hooks really cost zero tokens?
- A silent hook does — it runs outside the context window. But any text a hook prints back (a block reason, injected context) does consume tokens. You control exactly what reaches the model.
- What is the difference between a hook and an MCP server?
- An MCP server adds new capabilities and data the model can use. A hook governs the lifecycle around tools the model already has — allowing, blocking, logging, and automating.
Related hooks
Sources
Read next
- What Are Claude Code Hooks? A Practical GuideClaude Code hooks are commands that run automatically at lifecycle events. See the lifecycle, a complete working hook, and the settings.json that wires it up.
- PreToolUse vs PostToolUse: Which Claude Code Hook to UsePreToolUse runs before a tool and can block it; PostToolUse runs after and reacts. See two complete hooks, the differing stdin payloads, and a one-line rule.
- Write Your First Claude Code Hook in 5 MinutesA step-by-step tutorial: create the hooks folder, write a Bash command logger, register it in settings.json, test it, and watch it run. No deps beyond Node.
- Inject Context into Claude Code with HooksUse UserPromptSubmit and SessionStart hooks to inject context into Claude Code — conventions, current date, and git state — on every prompt and at startup.