Claude Code CLAUDE.md — Best Practices Template
Production-tested CLAUDE.md template for Claude Code projects. Covers coding conventions, test requirements, git workflow, and project-specific AI instructions.
What it is
CLAUDE.md is a project-level configuration file that tells Claude Code how to work within your specific codebase. This template provides a battle-tested structure covering coding conventions, test requirements, git commit rules, and project-specific AI instructions.
Developers who use Claude Code for daily coding, refactoring, or code review benefit from a well-structured CLAUDE.md. It reduces repeated instructions and ensures consistent behavior across sessions.
How it saves time or tokens
Without a CLAUDE.md, you spend tokens re-explaining project conventions every session. With this template, Claude Code reads your rules once and follows them automatically. The estimated token cost of the template itself is around 3,800 tokens, but it saves multiples of that by eliminating repetitive instructions across dozens of interactions.
The template also prevents common mistakes: wrong test framework, incorrect import style, or commits to the wrong branch.
How to use
- Create a
CLAUDE.mdfile in your project root:
# Project: My App
Tech Stack
- TypeScript, Next.js 14, Tailwind CSS
- PostgreSQL with Prisma ORM
- Jest for unit tests, Playwright for e2e
Coding Conventions
- Use named exports, not default exports
- Prefer async/await over .then() chains
- All components in PascalCase, utilities in camelCase
2. Add test and git rules:
Test Requirements
- Every new function needs a unit test
- Run
npm testbefore committing - Coverage must not drop below 80%
Git Workflow
- Branch from
main, never commit directly - Commit messages:
type(scope): description - Squash merge only
3. Start Claude Code in your project directory. It reads CLAUDE.md automatically.
Example
A complete minimal CLAUDE.md for a Go microservice:
# Project: user-service
Tech Stack
- Go 1.22, Chi router, sqlc for queries
- PostgreSQL 16, Redis for caching
- Docker Compose for local dev
Conventions
- Errors: return (T, error), never panic
- Logging: slog with structured fields
- Tests: table-driven, use testify/assert
Commands
make dev-- start local environmentmake test-- run all testsmake lint-- golangci-lint
Do Not
- Modify generated files in internal/db/
- Add dependencies without checking go.sum
- Use global variables
Related on TokRepo
- AI tools for coding -- More AI-powered development tools and configurations
- Prompt library -- Curated prompts and templates for AI workflows
Common pitfalls
- Making CLAUDE.md too long. Keep it under 4,000 tokens. Claude Code reads it every session, so bloated files waste context window.
- Contradicting rules. If you say 'use default exports' in one section and 'use named exports' in another, Claude Code picks one unpredictably.
- Forgetting to update CLAUDE.md when the tech stack changes. Stale rules cause Claude Code to generate code for the wrong framework version.
Frequently Asked Questions
Place it in the root of your project repository. Claude Code automatically detects and reads CLAUDE.md when you start a session in that directory. You can also place additional CLAUDE.md files in subdirectories for module-specific rules.
Aim for 2,000 to 4,000 tokens (roughly 1-2 pages of text). This is enough to cover tech stack, conventions, test rules, and git workflow without consuming too much of the context window. Prioritize rules that Claude Code frequently gets wrong without guidance.
For recurring rules, yes. Put anything you would repeat across sessions into CLAUDE.md. For one-off requests (like a specific refactoring task), use in-chat instructions. Think of CLAUDE.md as your project constitution and chat messages as individual tasks.
CLAUDE.md is specific to Claude Code (Anthropic). Other tools like Cursor use .cursorrules, and GitHub Copilot uses .github/copilot-instructions.md. The concepts are similar, but the file names and supported features differ.
Start a new Claude Code session and ask it to perform a task covered by your rules (e.g., create a new component). Check whether it follows your conventions without you specifying them. If it does not, your rules may be unclear or contradictory.
Citations (3)
- Anthropic Claude Code Docs— CLAUDE.md is a project-level configuration for Claude Code
- Anthropic Claude Code Overview— Claude Code reads CLAUDE.md automatically from the project root
- Anthropic Prompt Engineering Guide— Context window management best practices for LLM tools
Related on TokRepo
Source & Thanks
- Claude Code Docs
- awesome-claude-md — Examples and best practices
Discussion
Related Assets
Claude-Flow — Multi-Agent Orchestration for Claude Code
Layers swarm and hive-mind multi-agent orchestration on top of Claude Code with 64 specialized agents, SQLite memory, and parallel execution.
ccusage — Real-Time Token Cost Tracker for Claude Code
CLI that reads ~/.claude logs and breaks down Claude Code token spend by day, session, and project — pluggable into your statusline.
SuperClaude — Workflow Framework for Claude Code
Adds 16+ slash commands, 9 cognitive personas, and a smart flag system to Claude Code in one pipx install.