brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: scope instructions with paths in .claude/rules

Claude
~/tips/tip-claude-rules-paths-frontmatter

---

Makes a Claude Code rule load only when Claude works on files matching a pattern.

Why should Claude read your API rules while it is editing a CSS file? With path-scoped rules it does not have to.

Put markdown files in .claude/rules/. Add YAML frontmatter with a paths field and the rule only loads when Claude works with matching files.

---
paths:
  - "src/api/**/*.ts"
---

# API Development Rules

- All API endpoints must include input validation
- Use the standard error response format

A path-scoped rule loads when Claude uses Read, Write or Edit on a matching file. It also loads when it views a single matching file with something like cat. Rules without paths load at launch like CLAUDE.md. Personal rules that apply everywhere go in ~/.claude/rules/.

This suits monorepos and projects with a front end and a back end. Instructions for each side stay in their own files, and neither costs context when Claude works on the other. The main CLAUDE.md also stays short enough to get read.

The caveat: patterns are relative to the folder that holds the .claude directory, and a rule that never loads is usually a pattern that never matches. Check the glob first, not the wording.

Further reading: How Claude remembers your project – Claude Code docs, On this site: put personal project notes in CLAUDE.local.md and gitignore it, On this site: @-import files in CLAUDE.md instead of pasting them

More Claude tips /recap /focus /skill-doctor /autocompact 500k claude purge ~/work/my-repo --dry-run All Claude tips (83) All topics

Link