How Claude Code worksPart 3
Skills, hooks and subagents
On this page
In short: When a new colleague joins, you give them a few things. House rules on the fridge that are always true: that is CLAUDE.md. A drawer of recipe cards they pull out only when a task needs one: those are skills. Smoke alarms that go off whether anyone remembers or not: those are hooks. Specialists you send off with a brief who come back with a report: those are subagents. And the keys you hand over, or keep: those are permissions.
Part 1 showed where your colleague works and Part 2 how they remember. This part is about steering them. The project in the examples, an online shop called the Acme storefront, is made up.
The toolkit, layer by layer
Think of it like this: The fridge rules are read every morning. A recipe card comes out of the drawer only when it is needed. The smoke alarm is always on. A specialist works in another room and brings back a summary.
| Layer | Everyday picture | Read when |
|---|---|---|
CLAUDE.md | House rules on the fridge | Every session |
| Skill | A recipe card in a drawer | Only when a task matches |
| Hook | A smoke alarm | Always runs, outside Claude’s choice |
| Subagent | A specialist in another room | In their own space; only the report comes back |
| Permission | The keys you hand over | On every action |
Skills: recipe cards in a drawer
Think of it like this: Your colleague sees the title on every card in the drawer. They only take a card out, and read the steps, when a task matches its title.
A skill is a short file of steps for one kind of job, like “add a product page”. At the start, Claude only sees each skill’s one-line description. When your request matches, the full steps load. So a long recipe costs nothing until it is used. That is the difference from putting everything on the fridge.
Write the description the way people will ask: “Use when adding a product page”. You can also run a skill yourself by typing its name, like /add-product-page.
- A procedure has several steps you repeat now and then, such as adding a product page.
- Know-how is needed only sometimes. A skill keeps it out of
CLAUDE.mduntil it is used. - You want a workflow you can also run by name, such as
/release-notes.
- It is a rule for every session. Put it in
CLAUDE.md. - It must happen no matter what Claude decides. That is a hook.
- You will do it once. Just ask.
Under the hood: the skill file
A skill is a folder in .claude/skills/ with a SKILL.md inside: a short header with name and description, then the steps. A few header options:
disable-model-invocation: true: only you can start it, by typing/name.context: fork: it runs in a forked helper, so its work stays out of your session.allowed-tools: tools it may use without asking during that turn.
The folder can also hold reference files and scripts that load only when the steps point to them. The docs suggest keeping SKILL.md under 500 lines.
Custom slash commands are now skills. A file in .claude/commands/ and a skill in .claude/skills/ both create /name and work the same way.
Hooks: smoke alarms
Think of it like this: A smoke alarm does not wait for anyone to remember to check for smoke. It just goes off. A note on the fridge asks; an alarm insists.
A hook is a small script that runs at set moments, such as just before Claude edits a file, or just before it says it is done. Claude cannot skip it. If the hook says no, the action stops, and Claude is told why.
The hook says yes or no with a number when it finishes:
Rule: A hook that must stop something has to answer with 2. Answering with 1 only grumbles, and the action still goes ahead.
- Something must happen every time: block secret files, format after an edit, run tests before finishing.
- The check is mechanical, so a script can decide it.
- Each session should start with fresh facts, such as the current branch or ticket.
- It needs judgement, such as "is this copy clear?" Use a skill or a reviewer subagent.
- It is slow and would run on every tool call, keeping Claude waiting.
- It is meant to enforce a rule but exits 1. Use exit 2, or it only warns.
Under the hood: events and settings
Hooks are set in .claude/settings.json under hooks: an event, an optional matcher that picks which tools it applies to, and the command to run. $CLAUDE_PROJECT_DIR points at the project root. Type /hooks in Claude Code to see every active hook.
| Event | When it runs | Exit 2 |
|---|---|---|
SessionStart | A session starts or resumes | Shown to you only. Plain output becomes context for Claude |
UserPromptSubmit | You send a prompt | Blocks the prompt |
PreToolUse | Before a tool runs | Blocks the tool call; the message goes to Claude |
PostToolUse | After a tool succeeds | The tool already ran; the message goes to Claude |
Stop | Claude is about to finish | Claude keeps working |
SubagentStop | A subagent is about to finish | The subagent keeps working |
There are many more events in the docs. For a guard that must hold even if its script is missing or crashes, set "onFailure": "block".
Subagents: specialists in another room
Think of it like this: You send a specialist off with a short brief. They do the reading in their own room and come back with a one-page report. Your desk stays clear.
A subagent is a helper with its own instructions, its own tools and its own space. It starts fresh, knowing only the brief it is given. It does the job and sends back a short result. Several can work at the same time.
Remember: A specialist does not know what you have been discussing. When the helper needs everything you talked about, send a fork instead, the photocopy from Part 2.
- A job means reading or searching a lot and only the conclusion matters.
- You want an independent reviewer with fewer tools than the main session.
- Several jobs are independent and can run at the same time.
- The task is small. Starting one costs time and tokens.
- Steps depend on each other in order.
- It needs what you have discussed. A subagent does not see your conversation; a fork does (Part 2).
Under the hood: the subagent file
A subagent is a Markdown file in .claude/agents/ with a name, a description, and optionally tools and model, followed by its instructions. Claude hands work to it when a task matches the description; adding “use proactively” encourages that. Claude Code also ships a few built in, such as Explore, a fast read-only searcher, and Plan, which gathers context in plan mode. When Claude starts them from your session they run in the background.
One project, set up step by step
Here is the whole toolkit on the made-up Acme storefront. Each step adds one file.
- 1 · CLAUDE.md: the rules for every session
Short and always true: how to test, what never to do, and the plan-first rule.
# Acme storefront - Plan first. Wait for approval before editing. - Test with npm test. Lint with npm run lint. - Work on a branch. Never commit to main.
- 2 · Permissions: what is allowed at all
In
.claude/settings.json. Tests run without asking, pushes ask first, secrets and force pushes are denied."permissions": { "defaultMode": "plan", "allow": ["Bash(npm test)", "Bash(npm run lint)"], "ask": ["Bash(git push:*)"], "deny": ["Read(./.env)", "Bash(git push --force:*)"] } - 3 · A skill: a procedure used sometimes
.claude/skills/add-product-page/SKILL.md. Only the description sits in context until a request matches it.--- name: add-product-page description: Use when adding a product page: route, images, structured data. --- 1. Copy the product page template to a new route. 2. Add the images at 1x and 2x. 3. Add Product structured data, then run npm test.
- 4 · A hook: a guard that always runs
Registered for
PreToolUseonRead|Edit|Write. Exit 2 blocks the call and the message goes back to Claude.// .claude/hooks/guard-secrets.mjs let raw = ''; for await (const chunk of process.stdin) raw += chunk; const file = JSON.parse(raw).tool_input?.file_path ?? ''; if (/(^|\/)\.env$/.test(file)) { console.error('Blocked: .env holds secrets.'); process.exit(2); } - 5 · A hook: tests before finishing
A
Stophook. If the tests fail, exit 2 keeps Claude working instead of stopping."Stop": [{ "hooks": [{ "type": "command", "command": "npm test --silent || { echo 'Tests failed' >&2; exit 2; }" }] }] - 6 · A subagent: a reviewer with its own context
.claude/agents/a11y-reviewer.md. Read-only tools, and "use proactively" so Claude calls it after UI changes.--- name: a11y-reviewer description: Reviews changed pages for accessibility. Use proactively after UI changes. tools: Read, Grep, Glob model: sonnet --- Check each changed page for missing labels, alt text and contrast. Report the file, the line and the fix. Do not edit files.
- 7 · The next morning
You ask for a page for the new sneakers. Claude plans first, the
add-product-pageskill loads, the guard blocks one attempt to read.env, the reviewer finds two missing labels, and the tests pass before Claude stops. You only typed one sentence.
Which one fits?
- A rule for every session: CLAUDE.mdShort facts and rules that are always true: how to test, what never to do. It is read at the start of every session, so keep it to what matters each time.
- A procedure we repeat now and then: A skillA folder in
.claude/skills/with aSKILL.md. Only its description is loaded until a request matches, then the steps load. You can also run it by name. - Must happen every time, no exceptions: A hookA script in
.claude/settings.jsonthat runs at a fixed point, such as before a tool or at stop. Exit 2 blocks. It does not depend on Claude remembering. - A noisy job, only the answer matters: A subagentA file in
.claude/agents/with its own tools and its own context. It works apart and sends back a short result. If it needs your conversation, use a fork instead. - Never allow it at all: A deny ruleIn
permissions.deny, such asRead(./.env). Simpler than a hook when the answer is always no. Use a hook when the check needs logic. - A shortcut I type myself: A skill you run by nameType
/name. Adddisable-model-invocation: trueso only you can start it. Files in.claude/commands/still work the same way; skills are now the recommended form.
Under the hood: the full comparison
| CLAUDE.md | Skill | Hook | Subagent | Permission rule | |
|---|---|---|---|---|---|
| Who starts it | Always loaded | Claude or you | Claude Code | Claude or you | Claude Code |
| Costs context | Every session | Only when used | No | Only its result | No |
| Can block an action | No | No | Yes | No | Yes |
| Certain to apply | Claude follows it, usually | Only if it matches | Yes | Only if it is called | Yes |
| Best for | Facts and rules that are always true | Procedures needed sometimes | Musts and guards | Noisy or parallel jobs | Plain yes or no |
Also in the toolkit: Phone lines to other systems, called MCP servers, and ready-packed toolboxes, called plugins. Part 4 covers both.
Three rules of thumb
Always true goes in CLAUDE.md. Needed sometimes goes in a skill, so it costs nothing until it is used.
If it must happen, make it a hook or a permission rule. A line in CLAUDE.md is a request; a hook is a guarantee.
Send noisy work to a subagent and keep only its result in your session.
QuizClaude keeps forgetting to run the linter before it finishes, even though CLAUDE.md asks it to. What makes it happen every time?
Show the answer
Answer: A Stop hook that runs the linter and answers 2 when it fails
The fridge note and the recipe card only guide what Claude chooses to do. The smoke alarm goes off whatever Claude chooses. A Stop hook keeps Claude working until the linter passes.
Words in this post:
- CLAUDE.md: a file of rules Claude reads at the start of every session.
- Skill: a file of steps for one kind of job, loaded when needed.
- Hook: a script that runs at set moments and can say no.
- Subagent: a helper with its own instructions, tools and space.
- Permission rule: a line in settings that allows, asks about or blocks an action.
Facts here were checked against the Claude Code documentation on skills, hooks and subagents in November 2026. These features change often, so the docs are the final word for your version.
Setting up Claude Code or AI agents for your team?
I help teams build this: agents, RAG search and Claude Code setups that hold up in production.
Series
How Claude Code works
- How Claude Code worksWhere Claude runs
- How Claude Code worksSessions and forks
- How Claude Code worksSkills, hooks and subagentsyou are here
- How Claude Code worksMCP servers and plugins
- How Claude Code worksPermissions and safety
- How Claude Code worksContext and cost
- How Claude Code worksSpecs as the source of truth
- How Claude Code worksContract first
- How Claude Code worksVerify against the spec
- How Claude Code worksHandoffs and memory
- How Claude Code worksYour setup as a kit
- How Claude Code worksRolling it out