CLAUDE.md Mastery Intermediate
The CLAUDE.md file is the single most impactful thing you can create for Claude Code productivity. It provides persistent project context that is read at the start of every session, dramatically improving the quality and speed of every interaction.
What to Include
| Section | Why It Matters | Example |
|---|---|---|
| Project overview | Claude understands the domain and purpose | "E-commerce API for selling digital products" |
| Tech stack | Claude uses the right libraries and patterns | "Node.js 20, Fastify, PostgreSQL, Prisma" |
| Key commands | Claude can run tests, build, lint correctly | "pnpm test, pnpm dev, pnpm db:migrate" |
| Coding conventions | Claude matches your team's style | "Use barrel exports, error classes in src/errors/" |
| File structure | Claude knows where to find and create files | "Routes in src/routes/, services in src/services/" |
| Testing instructions | Claude writes tests the right way | "Use Jest, mock database with src/test/db-mock.ts" |
What NOT to Include
- Obvious things: "JavaScript is a programming language" wastes context.
- Entire API documentation: Too long. Reference the file path instead.
- Secrets or credentials: Never put API keys or passwords in CLAUDE.md.
- Frequently changing data: Version numbers that change weekly add maintenance burden.
- Generic advice: "Write clean code" is not actionable. Be specific.
Project-Level vs User-Level
| Type | Location | Purpose |
|---|---|---|
| Project-level | CLAUDE.md in project root |
Shared team conventions, project-specific context |
| User-level | ~/.claude/CLAUDE.md |
Personal preferences that apply to all projects |
# Personal Claude Code Preferences - Always use TypeScript strict mode - Prefer functional programming patterns - Write tests for every new function - Use descriptive variable names (no single letters except loop indices) - When creating commits, use conventional commit format
Real-World Examples
Node.js/Express API
# ShopAPI - E-Commerce Backend
## Stack
Node.js 20, Express 4, TypeScript 5.3, PostgreSQL 16, Knex.js, Jest
## Commands
- `npm run dev` - Start with hot reload (port 3000)
- `npm test` - Run Jest tests
- `npm run migrate` - Run database migrations
- `npm run seed` - Seed test data
- `npm run lint` - ESLint
## Structure
- src/routes/ - Express route handlers (one file per resource)
- src/services/ - Business logic (called by routes)
- src/models/ - Knex query builders
- src/middleware/ - Auth, validation, error handling
- src/types/ - TypeScript interfaces
- migrations/ - Knex migration files
## Conventions
- All routes return { success: boolean, data?: any, error?: string }
- Use the AppError class from src/errors/AppError.ts for all errors
- Database queries go in models/, never in routes or services
- All dates stored as UTC timestamps
- Pagination uses cursor-based (not offset) - see src/utils/pagination.ts
Python/Django Project
# DataPortal - Analytics Dashboard ## Stack Python 3.12, Django 5.0, PostgreSQL, Celery + Redis, pytest ## Commands - `python manage.py runserver` - Dev server - `pytest` - Run all tests - `pytest -x --tb=short` - Stop on first failure - `python manage.py makemigrations` - Create migrations - `celery -A config worker` - Start background workers ## Structure - apps/dashboard/ - Main dashboard app - apps/api/ - REST API (DRF) - apps/analytics/ - Data processing - config/ - Django settings - tasks/ - Celery tasks ## Conventions - Use class-based views for API endpoints - Type hints on all function signatures - Docstrings in Google style - Tests mirror the app structure in tests/
React Frontend
# StoreFront - E-Commerce UI ## Stack React 18, TypeScript, Vite, TailwindCSS, React Query, Zustand ## Commands - `pnpm dev` - Dev server (port 5173) - `pnpm test` - Vitest - `pnpm build` - Production build - `pnpm storybook` - Component playground ## Structure - src/components/ - Reusable UI components (each in own folder with index.tsx, styles, tests) - src/pages/ - Route-level components - src/hooks/ - Custom React hooks - src/stores/ - Zustand state stores - src/api/ - React Query hooks for API calls - src/types/ - TypeScript types ## Conventions - Components are functional with hooks (no class components) - Use Tailwind for styling (no CSS modules) - State: Zustand for global, useState for local, React Query for server - Every component folder has: index.tsx, ComponentName.test.tsx, ComponentName.stories.tsx
Updating CLAUDE.md Iteratively
Your CLAUDE.md should evolve with your project:
# Ask Claude to update CLAUDE.md based on recent changes > We just added Redis caching to the project. Update CLAUDE.md to include: > - Redis in the tech stack > - The cache utility location (src/utils/cache.ts) > - Caching conventions (TTL defaults, cache key patterns) # Periodic review > Review our CLAUDE.md and suggest improvements. What's missing? > What's outdated? What could be more specific?
Try It Yourself
Create or update your CLAUDE.md using one of the templates above as a starting point. Customize it for your specific project. Notice the immediate improvement in Claude Code's understanding. Next: debugging and troubleshooting.
Next: Debugging & Troubleshooting →Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX