Skills and Rules: What Goes Where
Why This Matters
Once you start writing things down for the agent, everything tends to end up in one big CLAUDE.md. That file then costs context in every session, including the ones where most of it is irrelevant. Skills and rules let you load the right knowledge at the right moment.
The difference
Rule (CLAUDE.md, .claude/rules/) | Skill (.claude/skills/<name>/SKILL.md) | |
|---|---|---|
| What | A constraint or convention | A procedure: how to do a specific task |
| When loaded | Always, or when matching files are touched | When the task matches the skill’s description |
| Size | A few lines | Can be long, with scripts and reference files |
| Example | “Never edit src/generated/” | “How to add an API endpoint: types, mock, tests, check” |
A simple test: if it starts with always or never, it is a rule. If it starts with when you need to…, it is a skill.
How skills load
A skill is a folder with a SKILL.md file. Its frontmatter has a name and a description. At the start of a session the agent only sees those short descriptions. When your request matches one, it loads the full instructions, plus any scripts or reference files in the folder when it needs them. That is why a project can have dozens of skills without filling the context window.
Skills live in .claude/skills/ in the repository (shared with the team) or in ~/.claude/skills/ (personal, every project). You can also run a skill directly as a slash command with its name.
When to write a skill
Write a skill when:
- you explain the same multi-step procedure to the agent more than once;
- the procedure has a fixed order or a checklist (release notes, a new endpoint, a migration);
- the agent needs reference material only for that task (an API contract, a style guide);
- a script would do part of the job more reliably than the model (formatting, validation).
When to write a rule
Write a rule when:
- it applies to most work in the repository;
- violating it causes real damage (data, security, broken builds);
- it is short enough to state in one or two lines.
Rules that must be enforced, not just requested, become hooks (lesson 15, Rules versus Hooks).
Hands-on
- List ten instructions you have given your agent in the last week.
- Mark each as rule, skill or hook (must be enforced).
- Move one procedure out of CLAUDE.md into a first skill folder; you write the full skill in the next lesson, lesson 8, Create and Edit Your Own Skills.
Walkthrough in TestRun Board
Sort everything the repository tells the agent into the three kinds:
| Instruction | Where it lives | Kind |
|---|---|---|
| Write or update a test for every behaviour change | AGENTS.md | Rule |
| Locate elements by role, never by CSS class | .claude/rules/testing.md (only for tests) | Path-scoped rule |
| How to add an API endpoint (contract, generate, api.ts, mock, tests) | .claude/skills/add-api-endpoint/SKILL.md | Skill |
| How to write a spec | .claude/skills/write-spec/SKILL.md | Skill |
Never edit src/generated/ | AGENTS.md and .claude/hooks/protect-paths.mjs | Rule, enforced by a hook |
Never use .only or .skip | AGENTS.md and ESLint no-restricted-properties | Rule, enforced by lint |
Then:
- Start a session and ask “Which skills are available in this project?” It should list both skills with their descriptions.
- Find one instruction you would add to this project and decide with the table above where it goes.
Key Takeaways
- Rules are short constraints that are always (or path-wise) loaded.
- Skills are procedures loaded on demand, by matching their description.
- “Always/never” means rule; “when you need to” means skill.
- Keep CLAUDE.md small by moving procedures into skills.