What is CLAUDE.md and How to Write One That Actually Works

You installed Claude Code. You ran a few prompts. The results were... fine. Maybe it suggested installing a package you already have. Maybe it used CommonJS when your whole project is ESM. Maybe it wrote tests in Mocha when you use Vitest.
The problem is not Claude Code. The problem is that Claude Code knows nothing about your project until you tell it.
That is what CLAUDE.md is for. It is a plain markdown file that sits in your repository root and gives Claude Code the context it needs to work effectively in your specific codebase. Think of it as onboarding documentation -- not for a new hire, but for an AI that can read your entire codebase in seconds but still needs to know the unwritten rules.
This guide covers everything: what CLAUDE.md is, how to structure one that actually works, real examples for different project types, mistakes to avoid, and how to iterate on it over time.
Table of Contents
- What is CLAUDE.md?
- Why CLAUDE.md Matters More Than You Think
- Anatomy of a Good CLAUDE.md
- Real Examples by Project Type
- Anti-Patterns: What Not to Do
- How to Iterate on Your CLAUDE.md
- How SuperBuilder Helps
- FAQ
What is CLAUDE.md?
CLAUDE.md is a configuration file for Claude Code -- Anthropic's AI coding agent that runs in your terminal. When Claude Code starts a session in a directory, it automatically reads the CLAUDE.md file at the project root to understand your codebase conventions, architecture, and preferences.
It is not a rigid configuration format. There is no schema, no required fields, no validation. It is plain markdown. You write whatever context would help an intelligent agent work more effectively in your project.
Here is a minimal example:
That is 12 lines. It takes two minutes to write. And it prevents dozens of wrong assumptions.

Where CLAUDE.md Files Live
Claude Code reads CLAUDE.md files from multiple locations, merged in order of precedence:
~/.claude/CLAUDE.md-- Global preferences that apply to all projects (your personal coding style, preferred tools)CLAUDE.mdin the project root -- Project-level conventions shared by the teamCLAUDE.mdin subdirectories -- Scoped instructions for specific parts of a monorepo or codebase
This layered approach means you can set global defaults and override them per project or per directory.
Why CLAUDE.md Matters More Than You Think
Claude Code is powerful. It can read files, run commands, edit code, and execute multi-step plans. But power without context leads to plausible-looking code that misses the mark.
Without a CLAUDE.md, Claude Code will:
- Guess your stack. It might suggest
jestwhen you usevitest, oraxioswhen you use the nativefetchAPI. - Ignore project conventions. Your team puts all database queries in a
repositories/folder? Claude does not know that. - Use wrong patterns. Your React app uses server components exclusively? Claude might default to
"use client"on everything. - Miss build steps. If your project needs
npm run codegenbefore tests pass, Claude will not know unless you tell it.
With a well-written CLAUDE.md, Claude Code becomes a team member who actually read the onboarding docs. It follows your patterns, uses your preferred libraries, and understands the architecture.
The difference is dramatic. Teams that maintain a good CLAUDE.md report that Claude Code gets things right on the first try 2-3x more often compared to prompting without one.
Anatomy of a Good CLAUDE.md
After reviewing hundreds of CLAUDE.md files from open-source projects and our own users, a clear structure emerges. The best files share these sections:
1. Project Overview (2-3 lines)
State what the project is and the core technology stack. Be specific about versions when it matters.
2. Key Commands
List the commands a developer (or AI) needs to build, test, lint, and run the project. This is the single highest-value section because it prevents Claude Code from guessing.
3. Architecture and File Layout
Describe where things live. This saves Claude Code from scanning your entire tree to understand the structure.
4. Coding Conventions
This is where you encode the unwritten rules. The things a new team member learns in their first week.
5. Important Constraints
Things Claude Code should never do, or must always do.
6. Testing Patterns
If your testing setup has specific conventions, spell them out.

Real Examples by Project Type
Theory is fine, but you need something you can copy and adapt. Here are five CLAUDE.md files for common project types, based on patterns from real-world projects.
Example 1: React + TypeScript App
Example 2: Python API (FastAPI)
Example 3: Monorepo (Turborepo)
Example 4: CLI Tool (Go)
Example 5: Mobile App (React Native)

Anti-Patterns: What Not to Do
A bad CLAUDE.md can be worse than no CLAUDE.md because it gives Claude Code confident but wrong context. Here are the most common mistakes.
1. The Novel (Too Long)
If your CLAUDE.md is over 500 lines, it is too long. Claude Code processes the entire file at the start of each session, and an overly long file dilutes the important information with noise.
Bad:
Better: Link to the docs instead.
2. The Vague Handwave (Too Generic)
Instructions that could apply to any project are wasted space.
Bad:
Better: Be specific to your project.
3. The Contradiction
When your CLAUDE.md says one thing but your codebase does another, Claude Code gets confused.
Bad:
...but half the codebase uses CSS Modules.
Better: Acknowledge reality.
4. The Stale Artifact
A CLAUDE.md written six months ago that references packages since removed, build commands that changed, or architecture that was restructured.
Fix: Treat CLAUDE.md as living documentation. Update it when you change your stack or conventions.
5. The Prompt Injection
Some developers try to use CLAUDE.md as a prompt engineering playground, stuffing it with elaborate system-prompt-style instructions.
Bad:
Better: CLAUDE.md is for project context, not personality instructions. Focus on facts about your codebase.

How to Iterate on Your CLAUDE.md
Your first CLAUDE.md will not be perfect. That is fine. Here is a practical process for improving it over time.
Start Small
Begin with just three sections: project overview, key commands, and conventions. That covers 80% of the value. You can always add more later.
Watch for Repeated Corrections
Every time you find yourself correcting Claude Code with the same feedback -- "no, we use pnpm not npm" or "put that in the services layer" -- add it to your CLAUDE.md. These corrections are your best source of what to include.
Review Monthly
Set a calendar reminder. Read through your CLAUDE.md once a month. Remove anything outdated. Add anything you have been repeatedly telling Claude Code in prompts.
Ask Claude Code to Help
You can literally ask Claude Code to suggest improvements to your CLAUDE.md:
Claude Code will scan your project and suggest conventions it notices -- import patterns, file naming, test structures, and more. This is a great way to capture implicit conventions you might not think to document.
Use Per-Directory CLAUDE.md for Large Projects
If your project has distinct sections with different conventions (a frontend and a backend in the same repo, for example), use nested CLAUDE.md files:

How SuperBuilder Helps
SuperBuilder is a desktop app built on top of Claude Code that makes managing your AI coding workflow easier -- including your CLAUDE.md.
Visual CLAUDE.md Editor
Instead of manually editing a markdown file, SuperBuilder provides a structured editor that organizes your CLAUDE.md into sections. Add commands, conventions, and architecture notes through a clean interface, and SuperBuilder generates the properly formatted markdown.
Template Suggestions
When you open a new project in SuperBuilder, it scans your package.json, pyproject.toml, go.mod, or other manifest files and suggests a CLAUDE.md template tailored to your stack. A React + Vite + Vitest project gets different suggestions than a Django + PostgreSQL project.
Memory System
SuperBuilder maintains a persistent memory across sessions that works alongside CLAUDE.md. As you work with Claude Code through SuperBuilder, it remembers corrections and preferences, building up context that complements your static CLAUDE.md file. Think of CLAUDE.md as the team documentation and SuperBuilder's memory as your personal notes.
Debug Mode Integration
When Claude Code is debugging an issue, SuperBuilder logs hypotheses, test results, and findings. This debug context works with your CLAUDE.md -- the architecture and conventions you document help Claude Code form better hypotheses about where bugs might live.

Putting It All Together
Here is a checklist for writing your CLAUDE.md today:
- State your stack in 2-3 lines at the top (framework, language, key libraries)
- List every command a developer needs (dev, test, lint, build, migrate)
- Map your file structure -- where do components, services, tests, and configs live?
- Write down your conventions -- the unwritten rules your team follows
- Add constraints -- things Claude Code should never do in your project
- Keep it under 200 lines for most projects (500 max for large monorepos)
- Commit it to version control so the whole team benefits
- Review it monthly and update when your stack or patterns change
The best CLAUDE.md files are not works of art. They are practical, specific, and current. They take 15 minutes to write and save hours of correcting AI-generated code that does not match your project.
If you are using Claude Code without a CLAUDE.md, you are using it at a fraction of its potential. Write one today. Start small, iterate, and watch the quality of AI-generated code in your project jump dramatically.
FAQ
How long should a CLAUDE.md be?
For most projects, 50-200 lines is ideal. Monorepos might stretch to 300-500 lines. If you are over 500 lines, you are probably including information that belongs in separate documentation files.
Should I commit CLAUDE.md to version control?
Yes. The project-level CLAUDE.md should be in your repo so every team member and CI environment benefits from it. Your personal ~/.claude/CLAUDE.md stays local.
Does CLAUDE.md work with other AI tools?
CLAUDE.md is specific to Claude Code (and tools built on it, like SuperBuilder). However, similar conventions exist for other tools -- Cursor uses .cursorrules, GitHub Copilot uses .github/copilot-instructions.md. The content is often transferable even if the file format differs.
Can I have multiple CLAUDE.md files?
Yes. Claude Code reads CLAUDE.md files from your home directory, project root, and any subdirectory you are working in. They are merged together, with more specific files taking precedence.
What if my CLAUDE.md contradicts the code?
Claude Code will generally follow your CLAUDE.md instructions, but it also reads your actual code. If there is a contradiction, it may get confused or ask for clarification. The fix is to keep your CLAUDE.md in sync with reality -- document what is, and note planned changes separately.
Should I include API keys or secrets in CLAUDE.md?
Never. CLAUDE.md is committed to version control and should contain no secrets. Use environment variable names instead: "Set DATABASE_URL in .env for local development."
How is CLAUDE.md different from a README?
A README is for human developers and usually covers setup, usage, and contribution guidelines. CLAUDE.md is optimized for AI consumption -- it focuses on conventions, constraints, and patterns that an AI agent needs to generate correct code. There is some overlap, but the audiences and goals differ.

Want to get more out of Claude Code? SuperBuilder gives you a visual interface for managing CLAUDE.md, persistent memory across sessions, and powerful debugging tools. Download it free at superbuilder.sh.