Frontmatter 경로가 있는 .claude/rules/
일치하는 파일을 편집할 때만 규칙을 불러옵니다
Frontmatter 경로가 있는 .claude/rules/은(는) CoddyKit의 무료 Claude Architect 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Claude Architect 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
The Monolithic CLAUDE.md Problem
As your project grows, a single CLAUDE.md tends to collect rules for everything: React components, SQL migrations, CI scripts, Terraform. Every one of those rules is loaded into context on every session, even when you are only touching one file type.
That wastes tokens and dilutes attention. The model attends most to the start and end of context (lost-in-the-middle), so a giant rules file can bury the instruction that actually matters for the file you are editing.
.claude/rules/ solves this: split rules into small files that load only when you edit matching files.
How Path-Scoped Rules Work
A rule file lives in .claude/rules/ and starts with a YAML frontmatter block. The key field is paths: a list of glob patterns. The rule body is injected into context only when the files you are working on match one of those patterns.
Think of it as conditional, file-aware instructions. No match means the rule stays out of context entirely, keeping the window lean for the task at hand.
Anatomy of a Rule File
Here is a minimal path-scoped rule. The frontmatter is delimited by --- lines; everything after it is the instruction the model receives when a match occurs.
Because the paths here target test files, this guidance only appears when you are editing tests, not when you touch production code.
---
paths:
- "**/*.test.tsx"
- "**/*.test.ts"
---
# Test Conventions
- Use the existing `renderWithProviders` helper, never bare `render`.
- One behavior per `it` block; describe blocks group by component.
- Mock network calls with MSW handlers from `test/mocks/`.Glob Patterns Are the Trigger
The paths globs are the same style Claude Code's Glob tool uses, for example **/*.test.tsx. A few practical patterns:
src/api/**— anything under the API directory**/*.sql— every SQL file in the repoinfra/**/*.tf— Terraform only inside infra
Scope tightly. A rule that matches **/* defeats the purpose: it is just your old monolithic CLAUDE.md wearing a frontmatter hat.
Where Rules Sit in the Hierarchy
Path-scoped rules layer on top of the CLAUDE.md hierarchy:
- User-level
~/.claude/CLAUDE.md— personal, NOT shared via VCS (new teammates miss it). - Project-level
./CLAUDE.mdor.claude/CLAUDE.md— shared via VCS, always loaded. - Directory-level — scoped to a subtree.
- .claude/rules/ with frontmatter
paths— loaded conditionally per matching file.
Keep CLAUDE.md for the few rules that are universally true. Push file-type-specific rules into .claude/rules/.
A Realistic rules/ Directory
Organize rules by concern, one file per file-type or domain. Each carries its own paths, so editing a migration pulls in DB rules while editing a component pulls in React rules, and never the reverse.
# Project layout
.claude/
CLAUDE.md # small: universal project facts
rules/
react.md # paths: src/**/*.tsx
sql-migrations.md # paths: db/migrations/**/*.sql
ci-scripts.md # paths: .github/workflows/**
terraform.md # paths: infra/**/*.tfMigrations Rule Example
Database rules are often strict and easy to forget. Scoping them to migration files means the guidance is in context exactly when it is relevant, and absent when you are writing UI code.
---
paths:
- "db/migrations/**/*.sql"
---
# Migration Rules
- Every migration must be reversible: include a `-- DOWN` section.
- Never DROP a column in the same migration that stops writing to it.
- Wrap DDL in a transaction; add indexes CONCURRENTLY where supported.
- After inserts, re-sync sequences with setval(...).Imports vs Path-Scoped Rules
Two ways to modularize, and they are not the same:
@pathimports inside CLAUDE.md, e.g.@./standards/coding-style.md, always pull that content in. Great for shared standards that apply broadly..claude/rules/withpathsfrontmatter loads conditionally, only when editing matching files.
Rule of thumb: if the guidance applies to a specific file type, scope it with paths. If it applies everywhere, an import (or CLAUDE.md itself) is fine.
<!-- Inside .claude/CLAUDE.md -->
# Project Standards
@./standards/coding-style.md <!-- always loaded -->
@./standards/commit-format.md <!-- always loaded -->
<!-- File-type specifics live in .claude/rules/*.md, loaded only on match -->The Token & Attention Payoff
The win is twofold. First, fewer tokens: irrelevant rule bodies never enter the window, leaving room for the actual code and tool output. Second, sharper attention: the rules present are the ones that match your current files, so the model is not sifting through Terraform conventions while fixing a React bug.
This is the same discipline as trimming verbose tool output to relevant fields, applied to your standing instructions.
Sharing and Secrets
Because .claude/rules/ lives in the repo, it is shared via VCS like project-level CLAUDE.md. New teammates get the same scoped guidance automatically, which user-level ~/.claude/CLAUDE.md would NOT give them.
Treat rule files like code: review them, and never paste secrets. If a rule references an integration, point to env vars such as ${GITHUB_TOKEN} rather than committing a token.
Design Checklist
When you split a monolithic CLAUDE.md into path-scoped rules:
- One file per file-type or domain; keep each focused.
- Make
pathsglobs as tight as the rule's true scope. - Leave only universal facts in CLAUDE.md; move file-specific rules out.
- Use
@importsfor always-on shared standards;pathsfor conditional ones. - Commit to VCS so the team shares the same behavior.
The result is a context window that adapts to whatever file you happen to be editing.
Quick Check: Scoping a SQL Rule
Your CLAUDE.md has grown to 600 lines and most sessions never touch SQL, yet detailed migration rules load every time and crowd out the relevant code. You want those migration rules in context only when editing files under db/migrations/, shared with the whole team. What is the best approach?
Recap
Key takeaways:
.claude/rules/*.mdwith YAML frontmatterpathsloads a rule only when editing matching files, saving context and tokens versus a monolithic CLAUDE.md.pathsuses Glob-style patterns like**/*.test.tsxordb/migrations/**/*.sql; scope them tightly.- Rule files are shared via VCS, unlike user-level
~/.claude/CLAUDE.md. - Use
@importsfor always-on shared standards; usepathsfrontmatter for conditional, file-type-specific rules. - Keep CLAUDE.md small and universal; push file-specific guidance into
.claude/rules/for adaptive, lean context.
자주 묻는 질문
“Frontmatter 경로가 있는 .claude/rules/” 강의는 무료인가요?
네 — “Frontmatter 경로가 있는 .claude/rules/” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Claude Architect 강의 전체를 잠금 해제할 수 있습니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.
“Frontmatter 경로가 있는 .claude/rules/”에서 뭘 배우나요?
일치하는 파일을 편집할 때만 규칙을 불러옵니다 브라우저에서 직접 실행하는 실습 코드로 Claude Architect을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Claude Architect을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Claude Architect은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“Frontmatter 경로가 있는 .claude/rules/” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Claude Architect 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Claude Architect 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 사용자, 프로젝트 및 디렉터리 수준
- @path 가져오기 구문
- Frontmatter 경로가 있는 .claude/rules/
- 단일형 규칙과 모듈형 규칙