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.
Instalación con revisión previa
Este activo requiere revisión. El prompt copiado pide dry-run, muestra escrituras y continúa solo tras confirmación.
npx -y tokrepo@latest install b152c845-95bc-493e-af27-b7f882e8896b --target codexPrimero dry-run, confirma las escrituras y luego ejecuta este comando.
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.
Preguntas frecuentes
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.
Referencias (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
Relacionados en TokRepo
Fuente y agradecimientos
- Claude Code Docs
- awesome-claude-md — Examples and best practices
Discusión
Activos relacionados
CLAUDE.md Best Practices — Advanced Patterns
Advanced CLAUDE.md patterns for Claude Code power users. Covers hook integration, multi-directory configs, conditional rules, and team workflow optimization techniques.
my-claude-code-setup — CLAUDE.md Memory Bank
my-claude-code-setup is a starter repo for Claude Code with a CLAUDE.md memory-bank system, templates, and a recommended first step: run `/init`.
OOP Architect — Self-Updating UML in CLAUDE.md
Generate and maintain Mermaid UML diagrams inside CLAUDE.md as you code; verified 105★ and installs as a Claude Code skill via marketplace or git clone.
Claude Reflect — Self-Learning for Claude Code
A Claude Code plugin that captures corrections and preferences during development, then syncs learnings to CLAUDE.md automatically. Makes Claude remember across sessions. 870+ stars.