Expand description
BP-5 (catalog D2 “Path-scoped rules”: rule files activated only when
matching files are touched; cc§2 “.claude/rules/*.md — modular
instruction files; optional paths: frontmatter scopes a rule to file
globs so it loads only when Claude touches matching files”).
A prompt-assembly input, not a module. A rule file is an instruction file that happens to carry a selector. There are exactly two ways it can reach a prompt, and both are doors that already existed:
- No
paths:— it joins the instruction blob at construction, besideCLAUDE.md/AGENTS.md, under the samecore.project_contextbyte budget (agent::assemble_project_instructions). - With
paths:— it is held back, and injected as a tool-result notice the first time a tool touches a matching file. That is the exact mechanismcore.nested_instructionsalready uses for a subdirectory’s own CLAUDE.md (tools::builtins::nested_instructions_notice), with the selector swapped from “the directory you touched” to “a glob this rule declares”. Each rule is injected at most once per session, deduped by path, exactly as nested instructions are.
Roots. <CLAUDE_CONFIG_DIR>/rules/ (the user tier) and
.claude/rules/ in each directory of the instruction walk
(docs:memory#organize-rules-with-claude-rules). Read only when
[core.path_rules] is on; a config that does not set it opens no
directory at all.
Structs§
- Rule
File - One
.claude/rules/*.mdfile.
Functions§
- always_
on_ text - The unscoped rules’ contribution to the instruction blob, in load order. Empty when nothing is unscoped.
- load
- Every rule file
configloads, user tier first, then the instruction walk from the outermost root down tocwd— the same root→cwd ordering instruction files use, so the nearest rule is read last. Empty (and free of any filesystem work) when[core.path_rules]is off.