Blog · AI Lint

Claude Code rules folder: scope an instruction to the files it governs

· DOSAYGO

A rule about database migrations is noise when an agent edits a README. Put it near the work it governs, then check that the rule appears when that work begins.

Claude Code supports project rules in .claude/rules/. A rule without a paths field loads at launch. A path-scoped rule loads when Claude reads, writes or edits a matching file. The memory documentation describes the loading behavior and glob syntax. Save this example, written for a fictional repository, as .claude/rules/migrations.md:

---
paths:
  - "db/migrations/**/*.sql"
---
# Migration changes

- Preserve existing migration files that have shipped. Add a new migration for a correction.
- Include a rollback or explain why one is unsafe.
- Run the migration test documented in db/README.md and report its output.

The team must first verify that its deployment process really treats shipped migrations as immutable, and that the test exists. If it does not, change the rule. A bad rule applied consistently is still bad.

Check the boundary

Do not rely on the /context all list alone for this. When we tried it on Claude Code 2.1.336 in non-interactive mode, a path-scoped rule loaded on a matching read and still did not appear under Memory Files. Claude Code's InstructionsLoaded hook records what loads and why. Add it to .claude/settings.json in a test checkout (merge it if you already have settings):

{
  "hooks": {
    "InstructionsLoaded": [
      {"hooks": [{"type": "command",
        "command": "cat >> /tmp/claude-instructions.log; echo >> /tmp/claude-instructions.log"}]}
    ]
  }
}

Start a fresh session, ask Claude to read a matching migration, and look in the log for your rule file with "load_reason":"path_glob_match". Clear the log, start another session, read only an unrelated file, and confirm the rule is absent. Then ask for a migration change on a disposable branch and run the real test on a disposable database. A loaded file shows availability, not compliance; review the resulting diff and test output. Path-scoped rules are also summarized away by compaction until a matching file is touched again, so keep anything that must always be present in an unscoped rule or the root CLAUDE.md.

AI Lint supplies architecture and security doctrine, a checklist, rejected patterns, and agent wiring. It is context for an agent, not a static analyzer or a guarantee that a rule loaded or was obeyed. Adapt the repository-specific instruction above to your process and enforce critical constraints in tests and access controls too.

For company repositories, buy a paid pack: the free edition covers only individuals doing personal or evaluation work. One person working commercially can take a Personal pack ($49 for Apps or Systems, $79 for the Bundle). A whole legal entity takes a Company license ($299 or $499) with unlimited internal users.

See AI Lint company packs

← All posts