CLAUDE.md Guide
Templates and examples for writing effective Claude Code instructions
What Is CLAUDE.md?
CLAUDE.md is a Markdown file in your project’s root directory that tells Claude Code how to work on your codebase. It contains your project’s build commands, architecture overview, coding conventions, and constraints — everything Claude needs to write code that fits your project.
Claude Code reads CLAUDE.md automatically at the start of every session. Instead of repeating “we use TypeScript strict mode” or “run npm test before committing” in every prompt, you write it once in CLAUDE.md.
Think of it as onboarding documentation for AI: the same information you’d give a new developer on their first day, but optimized for an AI agent’s context window.
Quick Start
Create a CLAUDE.md file in your project root. Here is the minimum viable version:
This 10-line file already prevents the most common issues: wrong test command, wrong coding style, leaked secrets.
CLAUDE.md Template
A comprehensive template covering everything Claude Code needs. Copy this and fill in your project details:
CLAUDE.md Examples by Stack
Ready-to-use templates for common tech stacks:
Python / Django
Go / Chi
Swift / iOS
File Hierarchy
Claude Code reads CLAUDE.md files at three levels. Instructions merge together, with more specific files taking precedence:
- Project root (
./CLAUDE.md) — global project instructions, always loaded when Claude works in this project - Subdirectories (
./app/CLAUDE.md,./backend/CLAUDE.md) — module-specific context, loaded when Claude works in that directory - User-level (
~/.claude/CLAUDE.md) — personal preferences that apply across all projects (e.g., preferred coding style, editor settings)
A typical monorepo might have:
./CLAUDE.md— shared commands, Git conventions, CI requirements./frontend/CLAUDE.md— React patterns, component naming, Tailwind setup./backend/CLAUDE.md— API conventions, database patterns, error handling./infra/CLAUDE.md— Terraform style, deployment constraints
CLAUDE.md vs AGENTS.md
CLAUDE.md is specific to Claude Code. It can reference Claude-specific features: memory system, custom slash commands, hooks, and MCP servers.
AGENTS.md is a cross-tool convention — any AI coding agent can read it. It contains universal instructions: architecture, conventions, and constraints that apply regardless of which AI tool your team uses.
When to use which:
- Claude Code only? — use CLAUDE.md
- Multiple AI tools on the team? — use AGENTS.md for shared instructions + CLAUDE.md for Claude-specific settings
- Not sure? — start with CLAUDE.md (Claude Code reads it natively). You can always split later.
Claude Code reads both files. Instructions from CLAUDE.md and AGENTS.md are merged.
Writing Tips
- Be concise — Claude reads the entire file into its context window. Every line reduces the space available for code. Aim for 50–200 lines.
- Commands, not descriptions — “
npm test -- --watch” beats “we use Jest with watch mode for development testing.” - Constraints are the most valuable section — “Do not modify
lib/auth/” prevents an entire class of mistakes. “Noanytype” is more actionable than “we prefer strong typing.” - Link, don’t duplicate — “See
docs/api.mdfor API design guide” keeps CLAUDE.md lean. Claude reads linked files on demand. - Update in the same PR — when you rename a directory, change a convention, or switch a dependency, update CLAUDE.md in the same pull request.
- Test your instructions — start a fresh Claude session and ask it to make a small change. If Claude gets it right without additional prompting, your CLAUDE.md is working.
Common Mistakes
- Too long — a 500-line CLAUDE.md wastes tokens. If it’s long, split into subdirectory files or link to separate docs.
- Duplicating README.md — Claude already reads your README. CLAUDE.md should contain operational instructions (commands, constraints, patterns) not project marketing.
- Too vague — “write clean code” tells an AI nothing. “Max 30 lines per function, early returns, no nested ternaries” is actionable.
- Missing constraints — the “do not” rules prevent the most expensive mistakes. List modules Claude should not touch, dependencies it should not add, patterns it should avoid.
- Stale instructions — CLAUDE.md describing last month’s architecture actively causes wrong code. Review it when the project changes.
Other Markdown Files Claude Code Uses
Beyond CLAUDE.md, Claude Code reads and works with several Markdown files in your project:
- README.md — project overview, always read for initial context
- AGENTS.md — cross-agent instructions (read alongside CLAUDE.md)
- CONTRIBUTING.md — contribution guidelines, PR conventions
- CHANGELOG.md — version history, used when making releases
- docs/*.md — documentation files, read on demand when relevant
The entire AI coding workflow — from context to output — runs on Markdown. For more on why, see Why AI Tools Use Markdown.
Related Guides
- AGENTS.md Guide — cross-tool agent context files
- Why AI Tools Use Markdown — token efficiency and format comparison
- Markdown vs JSON for AI — when to use which format
- ChatGPT Markdown Output — saving and viewing AI responses
- View Markdown from AI Tools — reading AI-generated content
View CLAUDE.md with MDViewer
MDViewer renders CLAUDE.md with full formatting — headings, code blocks, syntax highlighting, and links. See your AI instructions the way Claude Code sees them. Edit inline, preview changes, and keep your context files accurate.
Requires macOS 13.0 or later. Intel and Apple Silicon.