Drop in for a virtual coffee, Wednesdays at 5:30pm

Path-scoped rules

After the always-on project memory above, there is a lighter-touch way to give Claude rules: ones that switch on only when they are relevant. A path-scoped rule is an instruction that loads only when you are editing the files it is about, so the guidance shows up at the right moment and stays out of the way the rest of the time.

What aims a rule at the right files is a glob, a wildcard matching pattern for file paths, like every test file wherever it lives, or anything inside the terraform folder. The rule is the instruction, and the glob is how and where it is applied. So the same rule can be scoped to one folder or to one kind of file, whichever fits.

This earns its keep when a convention applies to files spread across the project. Test files, for instance, sit next to every component all over the tree. A CLAUDE.md only covers the folder it sits in, so to reach them all you would drop a copy into every folder and keep them in sync. One glob rule covers them in a single place, following the file type wherever it lives.

Say it another way

A path-scoped rule is like a sticky note that only appears on the drawer you have actually opened. You get the right reminder exactly when you are working on that part, not all of them at once.

The pattern written on the note, the glob, is what says which drawer. And because it can follow the kind of file rather than the folder, one note covers the same thing wherever it is kept, instead of taping a copy inside every cupboard.

Editing a fileDoes a rule's glob matchthis file?matchesno matchThe rule loadsjust in time, where it is neededIt stays out of contextno tokens spent on it
A path-scoped rule loads only when the file you are editing matches its glob, so the right guidance appears just in time and nothing irrelevant is carried the rest of the time.

Doing this with Claude Code: Path-scoped rules

Put a rule in a .claude/rules/ file with a paths glob, so it loads only for the files it is about.

Aim it with a glob. A wildcard pattern for file paths decides when the rule switches on, scoped either to a folder or to a kind of file.

It keeps context lean. The rule stays out of the way until you touch a matching file, so Claude is not carrying guidance it does not need.

Better than a scattered CLAUDE.md. When the same kind of file lives all over the tree, one glob rule beats dropping a CLAUDE.md copy into every folder and keeping them in sync.

Part of Ways to set AI up to help.