Skills, hooks and slash commands
Three ways to extend an agent. Skills teach it a procedure, hooks force a rule, commands are saved prompts.
Words on this page (7)
- agent
- : A model run in a loop that chooses its own tools and steps until the task is done.
- skill
- : A folder of instructions and scripts an agent loads only when a task needs it.
- hook
- : A script the harness runs automatically at a fixed point, such as before a tool call. It enforces rules in code.
- prompt
- : The input text you give a model, including instructions, examples and data.
- harness
- : Everything around the model that makes it an agent: prompts, tools, rules, sandboxes, hooks, memory and checks.
- tool use
- : The model asks your program to run a function and reads the result.
- tool
- : A function the model can ask your program to run, described by a name, description and argument schema.
What it is
A is a folder with a SKILL.md and optional scripts. The sees only its name and description until the task matches, then loads the rest. This keeps context small while making specialized procedures available. A is a script the runs at a fixed point, such as before a or after a file edit. It is deterministic, so it enforces what a can only request. A slash command is a reusable prompt you trigger by name.
Choosing between them
If the agent should know how to do something when relevant, write a skill. If something must happen every time without exception, such as formatting on save or blocking a commit with secrets in it, write a hook. If you keep typing the same request, make a command. Prompts ask, hooks guarantee.
A worked example: choosing
Goal: always format files after the agent edits them. Not a skill (the agent might forget) and not a command. A hook runs the formatter after every edit, guaranteed. Goal: teach the agent your release checklist, only when someone says "prepare a release". A skill, because it loads only when relevant. Goal: you often type "review the last commit for security issues". Make it a command and run it with one word.
How each one runs
A skill works by loading on demand. At the start, the agent sees a one-line description of each skill. When your request matches, it reads the full file and follows it. The match is a judgment by the model, so a vague description may never trigger, or may trigger at the wrong time.
A hook is different. The harness, not the model, runs it when an event happens, such as "after a file is edited". The model cannot skip it. If a before-the-action hook exits with the code the treats as blocking (exit 2 in Claude Code), the harness stops the action and shows the message to the agent. Other error codes usually let the action go ahead, so check your tool's docs.
A command is a saved prompt that you start yourself, so it runs when you type its name and not otherwise.
A second example: choosing wrongly
You want to stop the agent from ever committing a file called secrets.env. You write a skill saying "never commit secrets". This relies on the model remembering and matching. One day it does not load. A hook that checks the staged files before each commit and fails if that file appears is the right tool, because it runs every time. Now the opposite: you want the agent to know your team's review style. A hook cannot teach style. That is a skill.
Trade-offs
Hooks are strict, so a faulty one blocks work: a before-edit check that blocks too often stops the agent from getting anything done. Keep hooks fast and test them by hand. Skills cost little context but need precise descriptions. Too many skills with similar descriptions confuse the choice.
What goes wrong
Skill never triggers: the description does not match how you phrase requests, so rewrite it using your own words. Hook does nothing: the event or the file pattern is wrong, so run the script by hand and check its exit code. Hook slows everything: it does heavy work on every edit, so move that work to a commit-time check.
Try it yourself
Create a command or skill that does one small job, such as summarising the last commit in three lines.
- Run it.
- Change the wording of the description and see whether it still gets picked.
Expect small wording changes to change when a skill triggers.
Common mistake
Using the prompt for rules that must never break. Prompts ask. Hooks enforce.
A restaurant has three kinds of instructions. A recipe book the chef opens when needed (a skill). A rule enforced by the kitchen's equipment, like an oven that refuses to go above 250 degrees (a hook). A button on the till that fires a standard order (a command). Different tools for different needs.
Check yourself
A rule must apply every single time, with no exceptions. What do you use?
Not quite. Hooks are code run by the harness, so they do not depend on the model remembering.
Why do skills keep context small?
Not quite. Progressive loading means the full instructions appear only when relevant.
You keep typing "review the last commit for security issues". What is the best fit?
Not quite. A command is a reusable prompt you trigger on demand.
You got 0 of 3 right.
Go deeper
- Repo
Anthropic · Official example skills and the format specification.
- Article
Anthropic · Why skills load progressively and how to design them.
- Docs
Anthropic · Events, matchers and examples for deterministic control.
- Docs
Anthropic · Authoring and organizing skills.
- Repo
hesreallyhim · Curated skills, hooks, commands and workflows from the community.
- Repo
Jesse Vincent · A popular skill collection for planning, TDD and review workflows.
Spotted a mistake or something unclear? Report it on GitHub.