Skip to content
zeeshare.com

writing / FDE and agents

How Claude Code works

How Claude Code worksPart 3

Skills, hooks and subagents

On this page
  1. The toolkit, layer by layer
  2. Skills: recipe cards in a drawer
  3. Hooks: smoke alarms
  4. Subagents: specialists in another room
  5. One project, set up step by step
  6. Which one fits?
  7. Three rules of thumb

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.

Claude Main session CLAUDE.md and settings Skills Hooks Subagents

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.

permissions: what is allowed at all (.claude/settings.json) You: add a page for the sneakers CLAUDE.md always loaded: commands, rules, the folder map Claude Skills descriptions only release-notes fix-flaky-test add-product-page matched: full steps now loaded before a tool after Hooks always run, outside Claude's choice Edit What fills the context CLAUDE.md, every session skill descriptions, tiny one skill's steps, when used hooks: nothing, unless they send a message back subagents: only their result Subagent own context window, returns a short result
The fridge rules (CLAUDE.md) are always there. A recipe card (skill) comes out only when it matches. The alarms (hooks) check from outside. A specialist (subagent) works apart and sends back a summary.
LayerEveryday pictureRead when
CLAUDE.mdHouse rules on the fridgeEvery session
SkillA recipe card in a drawerOnly when a task matches
HookA smoke alarmAlways runs, outside Claude’s choice
SubagentA specialist in another roomIn their own space; only the report comes back
PermissionThe keys you hand overOn 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.

Your request Add a page for thenew sneakers Skills: only descriptions loaded add-product-page Use when adding a product page:route, images, structured data. release-notes Use when writing release notesfrom merged pull requests. fix-flaky-test Use when a test passes and failswithout code changes. Context used descriptions: about 100 tokens each + add-product-page steps, now loaded You can also run a skill yourself by name: /add-product-page
Pick a request. Claude reads the descriptions and opens only the skill that fits. The token count is an example.

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.

Write a skill when
  • 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.md until it is used.
  • You want a workflow you can also run by name, such as /release-notes.
Not a skill when
  • 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.

SessionStart UserPromptSubmit PreToolUse PostToolUse Stop add context check the prompt can block it check the result can say "not yet" style check: no problems exit 0, nothing to say tool
Like smoke alarms, hooks go off at fixed points in every turn, whatever Claude decides. Pick a scenario.

The hook says yes or no with a number when it finishes:

{ "hook_event_name": "PreToolUse", "tool_name": "Read", "tool_input": { "file_path": ".env" } } JSON in, on stdin your script guard-secrets.mjs exit 0: go ahead exit 2: block it stderr goes back to Claude exit 1 or other: a warning the action still goes ahead A hook meant to enforce a rule must exit 2. Exit 1, the usual Unix failure code, only warns.
A hook is a small program. The number it ends with is its answer: 0 means yes, 2 means no.

Rule: A hook that must stop something has to answer with 2. Answering with 1 only grumbles, and the action still goes ahead.

Write a hook when
  • 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.
Not a hook when
  • 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.

EventWhen it runsExit 2
SessionStartA session starts or resumesShown to you only. Plain output becomes context for Claude
UserPromptSubmitYou send a promptBlocks the prompt
PreToolUseBefore a tool runsBlocks the tool call; the message goes to Claude
PostToolUseAfter a tool succeedsThe tool already ran; the message goes to Claude
StopClaude is about to finishClaude keeps working
SubagentStopA subagent is about to finishThe 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.

Main session: "Get the checkout redesign ready to merge" a11y-reviewer tools: Read, Grep, Glob reads 40 files own context window custom, in .claude/agents/ test-runner tools: Bash, Read runs 412 tests own context window custom, in .claude/agents/ Explore read-only, built in finds every coupon call own context window ships with Claude Code 3 missing labels all green 4 call sites only these short results go back to the main session
Three specialists, each in their own room with their own tools, working at the same time and sending back a short report. The examples are invented.

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.

Use a subagent when
  • 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.
Not a subagent when
  • 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. 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. 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. 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. 4 · A hook: a guard that always runs

    Registered for PreToolUse on Read|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. 5 · A hook: tests before finishing

    A Stop hook. 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. 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. 7 · The next morning

    You ask for a page for the new sneakers. Claude plans first, the add-product-page skill 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 a SKILL.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.json that 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 as Read(./.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. Add disable-model-invocation: true so 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.mdSkillHookSubagentPermission rule
Who starts itAlways loadedClaude or youClaude CodeClaude or youClaude Code
Costs contextEvery sessionOnly when usedNoOnly its resultNo
Can block an actionNoNoYesNoYes
Certain to applyClaude follows it, usuallyOnly if it matchesYesOnly if it is calledYes
Best forFacts and rules that are always trueProcedures needed sometimesMusts and guardsNoisy or parallel jobsPlain 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 or sometimes?

Always true goes in CLAUDE.md. Needed sometimes goes in a skill, so it costs nothing until it is used.

Must, not should

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.

Keep the answer, drop the noise

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.

See services
Next in this seriesHow Claude Code worksMCP servers and plugins6 min read