CLAUDE.md Repo Boundaries and Rules
Write CLAUDE.md rules that tell agents which files to edit, which files to avoid, and how to handle dirty worktrees safely.
Direct answer
CLAUDE.md should make repo boundaries explicit: which folders are source, generated, docs, infra, or deploy output; which files should not be edited; how to handle dirty worktrees; and what verification is required before final. Boundary rules prevent agents from making broad unrelated changes just to satisfy a narrow task.
Open CLAUDE.md ReviewerWhen to use this
- The repo has generated output, vendored files, migrations, or deploy artifacts.
- Agents keep touching unrelated files.
- Multiple people or agents work in the same worktree.
Steps
- Name source folders, generated folders, docs folders, and deploy output.
- List files or directories that require extra care.
- Add dirty-worktree rules.
- Define the expected edit scope for normal tasks.
- Run the reviewer and tighten any vague boundaries.
Example review focus
# CLAUDE.md ## Project Next.js static export. ## Rules - Follow existing patterns. - Be safe with files.
Replace vague safety language with concrete boundaries: source lives in `src/`, static files in `public/`, export output in `out/`, and generated build artifacts should not be manually edited. Add `do not revert unrelated user changes` and `stage only files related to the task`.
Common mistakes
- Do not say be careful when you can name the exact file boundary.
- Do not let generated output and source files look equally editable.
- Do not forget dirty-worktree rules for shared workspaces.
FAQ
- What is a repo boundary in CLAUDE.md?
- A repo boundary tells the agent where source files live, what is generated, what is owned by another system, and what should not be changed during normal tasks.
- Should CLAUDE.md mention dirty git status?
- Yes. Shared worktrees need rules like do not revert unrelated changes and stage only task-related files.
- Can this reduce accidental refactors?
- Yes. Clear boundaries make it easier for the agent to keep edits scoped to the requested behavior.
Related CLAUDE.md guides
Review CLAUDE.md for Token Waste
Find vague, repeated, or unused CLAUDE.md instructions that cost tokens every Claude Code turn without improving behavior.
CLAUDE.md Missing Commands Checklist
Check whether a CLAUDE.md includes the build, test, lint, dev server, deploy, and verification commands an agent needs before editing.
Review CLAUDE.md Before Converting to AGENTS.md
Clean a CLAUDE.md first, then convert it into AGENTS.md, Cursor rules, GitHub Copilot instructions, or Windsurf rules.