AITraining2U

Programs

Resources

Case Studies

Quick Links

Enquire Now
Domain 2 · 20%% of exam

Path-scoped rules with .claude/rules/

How to keep instructions out of context until they are relevant.

4 min read · Lesson 4 of 11 in this domain

A root CLAUDE.md loads on every single session, so anything you put there costs context in every unrelated conversation. Rules files solve that. Dropping a markdown file into .claude/rules/ gives you the same instruction mechanism, but adding a paths glob in its frontmatter makes it conditional: the rule enters context only when Claude works with a file that matches. It is the difference between telling someone your API conventions every morning and handing them the note when they open the API folder.

Key points
  • Put markdown files in .claude/rules/. All .md files are discovered recursively, so you can organise into subdirectories.
  • A rule without a paths field loads unconditionally at launch, at the same priority as .claude/CLAUDE.md.
  • A rule with paths frontmatter loads only when Claude works with files matching those globs. This is the mechanism for scoping instructions by file type or directory.
  • Path-scoped rules trigger when Claude reads a matching file, not on every tool use.
  • User-level rules live in ~/.claude/rules/ and load before project rules, giving project rules higher priority.
  • Rules vs skills: rules load every session (or on path match); skills load only when invoked or judged relevant.
A path-scoped rule
---
paths:
  - "src/api/**/*.ts"
  - "lib/**/*.{ts,tsx}"
---

# API Development Rules
- All API endpoints must include input validation
- Use the standard error response format
Exam trap

"Put a conditional sentence in the root CLAUDE.md" — that loads on every session regardless, costing context in every unrelated conversation.

Check your understanding

How do you load a rule only for TypeScript files under src/api/?

Correct answer: A — A paths glob in .claude/rules/ frontmatter
Path-scoped rules are the purpose-built mechanism; a root CLAUDE.md loads every session regardless.

A rules file has no paths field. When does it load?

Correct answer: B — At launch, unconditionally
Omitting paths is the normal way to write an always-on rule.

Practise this domain with 20%%-weighted questions in the study app.

Open in study app

Source: Claude Code Docs — Memory · Independent study aid, not affiliated with or endorsed by Anthropic.