📄 What It Is and Why It Exists
🧠 Imagine It This Way: CLAUDE.md is like an operations manual you leave on the new employee's desk. Every time Claude Code opens a session, it reads this file first. It's how you tell the agent: "this is how this project works; follow these rules".
O CLAUDE.md is a Markdown file that Claude Code reads automatically at the beginning of each session. It works as a system prompt persistent: everything you write there will influence how Claude behaves in your project. It's not a suggestion; it's an instruction. The model treats the contents of CLAUDE.md as high-priority guidance.
Without CLAUDE.md, Claude Code is generic. It doesn’t know your project uses TypeScript, that you prefer tabs over spaces, or that you have a specific naming convention. With CLAUDE.md makes it a specialist in your project from the very first message. The difference is dramatic: instead of asking "what framework do you use?", it already knows and acts accordingly.
The mechanism is simple: when you start a session with claude, the agent looks for CLAUDE.md files in your environment, reads their contents, and injects them as part of the system prompt. This happens before you type anything. It’s like an automatic briefing the agent receives every morning before starting work.
💡 Practical Analogy
Think of CLAUDE.md as a team's onboarding document. When a new developer joins, you don't explain everything from scratch every time. You give them the onboarding doc. CLAUDE.md is exactly that, but for the AI agent. The difference is that the "new developer" needs this document every session, because every session starts fresh.
In one sentence: CLAUDE.md = a persistent system prompt that turns Claude Code from a generalist into a specialist in your project.
🏗️ Hierarchy: Global, Project, and Folder
🧠 Imagine It This Way: Imagine three layers of instructions stacked on top of each other. The bottom one (global) applies to everything. The middle one (project) is specific. The top one (folder) is highly specific. Each layer refines the previous one without overriding it.
Claude Code reads CLAUDE.md from three locations, in this order: ~/.claude/CLAUDE.md (global, applies to all projects), ./CLAUDE.md (at the project root) and subdir/CLAUDE.md (in any subfolder where you're working). All three are read and concatenated to form the full context.
The cascade works by addition: the content of each level builds on the previous one. The global file sets personal preferences (“never use em dashes,” “prefer TypeScript”). The project file sets the stack and conventions. The folder file sets rules specific to that area of the code. Together, all three form the full context the agent receives.
This hierarchy is powerful because it allows for separation of responsibilities. You define your personal preferences once (globally) and never have to repeat them in each project. Each project defines its own rules without interfering with the others. And special subfolders (such as src/api/) can have additional rules without cluttering the main CLAUDE.md.
~/.claude/CLAUDE.md ← global (todas as sessoes) ./CLAUDE.md ← projeto (raiz do repo) ./src/CLAUDE.md ← pasta (regras do /src) ./src/api/CLAUDE.md ← subpasta (regras do /api) # Todos sao lidos e somados. Mais especifico refina o geral.
In one sentence: three levels (global > project > folder) combine to form the complete context.
✏️ Effective Syntax and Conventions
🧠 Imagine It This Way: Writing a CLAUDE.md is like writing a brief for a competent professional. Be direct, use lists, and give concrete examples. Claude follows clear instructions; it ignores vague ones.
The format is plain Markdown. Use headings (## Stack, ## Convencoes), bulleted lists, and code blocks for examples. The ideal tone is imperative and concrete: “Always use async/await” works better than “it would be good to consider using async/await when possible.” The model follows direct instructions much more consistently than vague suggestions.
Some conventions that work well: group by section (Stack, Conventions, Prohibitions), use bold for emphasis, include code examples when the rule is technical, and keep the file between 50 and 200 lines. Beyond that, the returns diminish and you use context unnecessarily. Every line in CLAUDE.md consumes tokens from the context window.
Avoid repeating what the model already knows. There’s no need to say "write readable code" or "use best practices." Claude already does that by default. CLAUDE.md should contain what is different in this project or in the way you work. If the default works, don't waste lines on it.
✓ Good CLAUDE.md
- • Clear headings: ## Stack, ## Rules
- • Imperative tone: "Always use..."
- • Concrete code examples
- • 50-200 lines, focused
- • Explicit prohibitions in ALL CAPS
✗ Bad CLAUDE.md
- • Unstructured prose
- • Vague tone: "maybe consider..."
- • No practical examples
- • 500+ lines (clogs the context)
- • Repeats what the model already knows
# Projeto XYZ ## Stack - Next.js 14 (App Router) - TypeScript strict - Tailwind CSS - Prisma ORM + PostgreSQL ## Convencoes - Arquivos: kebab-case (user-profile.ts) - Componentes: PascalCase (UserProfile.tsx) - NUNCA usar `any`. Sempre tipar explicitamente. ## Proibicoes - NUNCA deletar arquivos sem confirmar - NUNCA commitar .env ou secrets - NUNCA usar console.log em producao
In one sentence: be direct, use headings + lists + examples, and keep it between 50-200 lines.
🎯 Instructions That Make a Difference
🧠 Imagine It This Way: not all instructions change behavior. The ones that work are the ones that describe what to do differently from the default. If the standard already works, don’t spend lines on it.
The types of instructions that have the greatest impact are: stack and technologies ("this project uses Next.js 14 with App Router"), code conventions ("file names in kebab-case"), explicit prohibitions ("NEVER delete files without confirming"), and project patterns ("use the service layer pattern in src/services/").
Uppercase prohibitions (NEVER, ALWAYS) are followed more consistently. This isn't superstition: the model gives more weight to emphatic tokens. Use them sparingly so they don't become noise, but don't hesitate when the rule is critical. A well-placed "NEVER use sudo" can prevent serious accidents.
Another powerful category: workflow instructions. “Always run tests before committing,” “ask for confirmation before deleting,” “use git commit with Portuguese messages.” These instructions shape how the agent works, not just what it produces. They turn Claude from a passive tool into a disciplined coworker.
Stack and technologies
Defines what the project uses. The agent chooses the right APIs and conventions from the first response.
Coding conventions
Naming, formatting, folder organization. Ensures consistency across all generated code.
Explicit prohibitions
NEVER and ALWAYS in uppercase. Prevents critical errors and ensures safety.
Project patterns
Architecture patterns (service layer, repository, etc.). The agent replicates the existing structure.
Workflow instructions
How the agent works: tests, confirmations, commits. Turns Claude into a disciplined colleague.
## Stack - Next.js 14 (App Router) - TypeScript strict - Tailwind CSS - Prisma ORM + PostgreSQL ## Convencoes - Arquivos: kebab-case (user-profile.ts) - Componentes: PascalCase (UserProfile.tsx) - NUNCA usar any. Sempre tipar explicitamente. - Testes: colocar em __tests__/ ao lado do arquivo. ## Padroes - API routes usam o pattern em src/app/api/[resource]/route.ts - Validacao com Zod em todo input de API ## Workflow - Sempre rode npm test antes de commitar - Commit messages em portugues, imperativo
In one sentence: Focus on the stack, conventions, prohibitions, patterns, and workflow; Claude already handles the rest on its own.
📂 Real Examples of Good CLAUDE.md Files
🧠 Imagine It This Way: the best way to learn is to see real examples. Open source projects and Anthropic's own repositories publish CLAUDE.md files that you can study and copy.
Good CLAUDE.md examples share a few characteristics: they’re short (rarely over 150 lines), focus on what is different in that project (they don't repeat generic knowledge), and include at least one section of explicit prohibitions. Studying real examples is the fastest shortcut to writing an effective CLAUDE.md.
A common anti-pattern is a CLAUDE.md that tries to teach the model programming ("use good coding practices"). Claude already knows good practices. What it needs to know is what the your specific practices. Another anti-pattern: copying the entire framework documentation. The model already knows React, Next.js, etc. Tell it which version you use and how you use it, not what it is.
An excellent example is the CLAUDE.md in Anthropic's own Claude Code repository. It's concise, focuses on internal conventions (how to run tests, how to commit, which architectural patterns to follow), and has clear prohibitions. Another good example: popular open source projects that have adopted the practice and publish their CLAUDE.md files on GitHub.
SaaS project
Stack, auth pattern, database schema conventions, API response format. ~80 lines.
CLI Tool
Build system, flag conventions, error handling pattern, release workflow. ~60 lines.
Monorepo
Package structure, shared types, dependency rules, per-package CLAUDE.md files in subfolders. ~120 lines.
📊 Where to Find Examples
Search for "CLAUDE.md" on GitHub. Projects like Anthropic’s own claude-code, along with popular repos that have adopted the practice, are good references. Copy the structure and adapt the content to your project. Don’t reinvent the wheel.
In one sentence: Study real examples, copy the structure, and adapt it to your project.
🔄 Maintenance and Versioning
🧠 Imagine It This Way: CLAUDE.md is a living document. Commit it to git, review it monthly, and use /memory as a quick supplement between reviews. An outdated document is worse than none at all.
The CLAUDE.md should go in the git, along with the code. This ensures anyone (or any agent) who clones the repo gets the context automatically. Treat it like a config file: versioned, reviewed, and updated along with the project. Pull requests that change the stack or conventions should include the corresponding update to CLAUDE.md.
A healthy routine: review the CLAUDE.md once a month or when something significant changes in the project (a new lib, a new pattern, a new team member). Between reviews, use /memory to add quick notes that persist without editing the file directly. /memory is the shortcut; CLAUDE.md is the canonical source.
An outdated CLAUDE.md is worse than none at all, because the agent will confidently follow incorrect instructions. If you removed a library from the project but CLAUDE.md still says "use lib X," Claude will try to use it and fail. If you changed ORMs, update CLAUDE.md. If you changed naming conventions, update it. The rule is simple: if it changed in the code, change it in CLAUDE.md.
⚠️ Outdated and Dangerous CLAUDE.md
Outdated instructions in CLAUDE.md cause systematic bugs. The agent follows what's written, not what's in your head. Keep it up to date or delete sections that have changed. An empty CLAUDE.md is better than a misleading CLAUDE.md.
Manutencao do CLAUDE.md: [ ] Commitar no git junto com o codigo [ ] Revisar mensalmente ou ao mudar stack [ ] Remover instrucoes obsoletas imediatamente [ ] Usar /memory pra notas rapidas entre revisoes [ ] Incluir atualizacao em PRs que mudam convencoes [ ] Manter entre 50-200 linhas (nao deixar inchar)
In one sentence: commit to git, review monthly, and remember: outdated is worse than nonexistent.
🧾 Module Summary
Next module:
1.4 — Advanced Configuration: settings.json, permissions, and providers.