Writing the Perfect CLAUDE.md
CLAUDE.md is Claude Code's persistent memory. A well-written file eliminates repeated instructions, enforces conventions automatically, and makes every session smarter than the last.
What CLAUDE.md Does
When you run claude in a directory, Claude Code automatically reads any CLAUDE.md it finds and injects it at the top of the context window. This happens before you type a single word.
Think of it as a briefing document Claude reads every morning before sitting down to work with you. Anything in that document becomes active knowledge for the entire session.
./CLAUDE.md — Project-level. Committed to the repo. Shared with the team.~/.claude/CLAUDE.md — Global. Personal preferences that apply to every project../CLAUDE.local.md — Local override. Gitignored. Personal dev preferences for this project.Recommended Structure
Every effective CLAUDE.md contains these six sections in roughly this order:
Example Sections
Identity & Persona
Non-Negotiable Rules
Architecture
Project vs Global CLAUDE.md
Project CLAUDE.md
- →Committed to the repo — shared with all contributors
- →Contains project-specific rules, architecture, and conventions
- →Changes require a PR — keeps rules auditable
- →Lives at
./CLAUDE.md
Global CLAUDE.md
- →Personal — applies to every project on your machine
- →Contains your preferred coding style, tool preferences
- →Never committed — stays on your machine
- →Lives at
~/.claude/CLAUDE.md
Common Mistakes
Get a Battle-Tested CLAUDE.md Template
The AI Starter Package includes a production-ready CLAUDE.md template used across real projects — with all six sections, example rules, and a memory architecture already wired up.