Study FAQ
Why is my path-scoped Claude Code rule missing or loading too broadly?
Also asked as 2
- How do I diagnose a Claude Code rule that does not apply to the intended files?
- What should I check when .claude/rules guidance loads for the wrong paths?
Answer
Check the saved rule's location, parsed frontmatter, pattern base, and the file operation that should trigger it. A folder name inside .claude/rules/ organizes rules; it does not create a path condition.
Put supported paths frontmatter at the top of the Markdown file. For a project rule, patterns are relative to the directory containing the project's .claude folder. Choose explicit patterns and test a matching file, a nested match if intended, and a nonmatching file. Do not assume the glob dialect is identical to a shell or another tool.
For example, a rule listing "**/*.test.ts" and "**/*.spec.tsx" targets those suffixes. It does not cover .test.tsx or .spec.ts. Quote patterns correctly in YAML.
Current Claude Code documentation says matching Read, Write, and Edit operations can load the rule, as can supported Bash reads such as viewing a single file with cat. Seeing a matching filename in a listing does not establish loading. Confirm that project configuration sources are enabled and that the session is using the intended project or worktree.
If loading is too broad, look for absent or malformed frontmatter, an unconditional duplicate, and an overly broad pattern. Current documentation says invalid YAML is treated as unscoped guidance, so a parse error can broaden loading. Use the supported debug diagnostics and, when appropriate, the InstructionsLoaded hook to observe which file loaded and why.
Finally, inspect a representative result for the convention itself. Loaded guidance can still conflict with other instructions or be ignored. It does not enforce access permissions, and moving to another file does not prove previously loaded text was removed.
Full explanation
Apply path-specific rules for conditional convention loading
Learning material · CCAR-F
Read the full explanation