Rules: Context That Auto-Loads by Path

Day 10 · Week 2 · Context — The Secret Sauce

Slack Message — copy & paste

🤖 Tip #10 — Rules auto-load by file path — SCSS conventions only appear for .scss files. Targeted context, zero noise.

#10 Claude Code · CLI

How Path-Scoped Rules Work

  • Rules are markdown files in `.claude/rules/` with path patterns in the frontmatterwhen you work on a matching file, the rule auto-loads into context.
  • **Global vs. scoped**CLAUDE.md is global (loaded every session), but rules are path-scoped. JavaScript conventions don't pollute SCSS sessions, AEM backend rules don't confuse frontend work.
  • Real-world exampleseparate rules for each concern
    • JavaScript (ESLint Airbnb conventions)
    • SCSS (node-sass, sass-lint)
    • Accessibility (WCAG 2.1 AA)
    • Naming conventions
    • Each only loads when relevant
.claude/rules/ Path-Scoped Auto-Load
#10 Context — The Secret Sauce

Creating Effective Rules

  1. 1 **Dual frontmatter gotcha**for Copilot CLI, you also need `applyTo:` in the YAML. Without it, the rule only works in Claude Code. Use both `paths:` and `applyTo:` for cross-platform compatibility.
  2. 2 Create a rule for your most common file typeadd 3-5 conventions and watch the AI follow them automatically
  3. 3 Always include dual frontmatter for cross-platform support
    • `paths: ["**/*.scss"]` — Claude Code
    • `applyTo: "**/*.scss"` — Copilot CLI
  4. 4 Keep rules focusedone topic per file. A 'styles' rule, a 'testing' rule, a 'naming' rule. Easier to maintain and debug.
.claude/rules/ Path-Scoped Auto-Load
Your screenshot here Optional — add a screenshot from your own workflow
KAI by Dragan Filipovic