Guide for creating and maintaining repository-local CLAUDE.md files that capture project-specific context, patterns, and conventions...
Guide for creating and maintaining repository-local CLAUDE.md files that transform Claude Code from a general-purpose assistant into a project-specialized expert.
Repository memory serves as persistent context that:
The global ~/.claude/CLAUDE.md configures Claude's behavior. Repository-local .claude/CLAUDE.md files specialize Claude for specific projects.
Create when:
Update when:
Target under 100 lines for quick AI consumption. Use XML tags for clear section boundaries:
<architecture>
High-level system structure, key modules, data flow
</architecture>
<patterns>
Code patterns, idioms, conventions specific to this project
</patterns>
<conventions>
Naming, formatting, organizational rules
</conventions>
<testing>
Test structure, commands, coverage expectations
</testing>
<deployment>
Build process, deployment steps, environment setup
</deployment>
Tags enable efficient parsing and selective context loading.
architecture: System structure, key modules, service boundaries, data flow patterns. Focus on relationships and responsibilities.
patterns: Project-specific code patterns, idioms, common abstractions. Examples: error handling approach, state management pattern, API response structure.
conventions: Naming rules, file organization, import ordering, comment style. Enforceable through tooling (linters, formatters) but document exceptions.
testing: Test file structure, naming conventions, commands to run tests, coverage expectations. Include mock/fixture patterns if non-standard.
deployment: Build commands, deployment process, environment variables, CI/CD specifics. Focus on developer-facing operations.
Optional sections:
<dependencies>: Key libraries and usage guidelines<troubleshooting>: Common issues and solutions<development>: Setup steps, required tools, local dev workflowUse bullet points: Quick to scan, easy to update, AI-friendly Avoid obvious information: Skip standard practices (e.g., "use descriptive names") Focus on project-specific: Only include what differs from defaults Reference external docs: Link to ADRs, wikis, or detailed guides instead of duplicating Update, don't accumulate: Remove outdated guidance rather than leaving contradictions
Example of concise vs verbose:
Verbose (avoid):
<patterns>
When creating API endpoints, you should follow RESTful conventions.
Use GET for retrieval, POST for creation, PUT for updates, and DELETE
for deletion. Always return appropriate status codes like 200 for success,
404 for not found, and 500 for server errors.
</patterns>
Concise (prefer):
<patterns>
- API responses: { data, error, meta } structure
- Error handling: throw custom AppError subclasses
- Auth: JWT in Authorization header, validated in middleware
</patterns>
Information hierarchy:
CLAUDE.md provides the map. Skills and docs provide the details.
Example reference pattern:
<architecture>
- Microservices: auth, api, worker, notifications
- Event-driven: RabbitMQ for inter-service communication
- See docs/architecture/services.md for detailed flow diagrams
</architecture>
Link to deeper documentation but keep core patterns inline.
Create .claude/skills/ when workflows involve:
Create skills when:
Do NOT create skills for:
Example repository skill structure:
.claude/
├── CLAUDE.md # Core context (<100 lines)
└── skills/
├── release/SKILL.md # Multi-step release workflow
└── migration/SKILL.md # Database migration patterns
Repository-local CLAUDE.md supplements (not replaces) global configuration:
Global (~/.claude/CLAUDE.md):
Repository-local (.claude/CLAUDE.md):
Claude merges both contexts. Repository-local wins for conflicts.
Review cadence:
Monitor for staleness:
Keep lightweight: Remove rather than archive. Git history preserves old decisions.
Realistic ~80-line CLAUDE.md for a Next.js SaaS application:
# MyApp - SaaS Platform
<architecture>
- Next.js 14 (App Router) monorepo
- `/app`: Frontend routes and components
- `/lib`: Shared utilities, API clients, db access
- `/workers`: Background job processors (separate service)
- Postgres (Prisma ORM) + Redis (caching, sessions)
- Deployed on Vercel (frontend) + Railway (workers)
</architecture>
<patterns>
- Server actions: use "use server" for mutations, return { data, error }
- API routes: minimal, only for webhooks or third-party integrations
- Database: single Prisma client instance, exported from lib/db
- Auth: NextAuth v5, session stored in Redis, JWT for API tokens
- Error handling: throw AppError subclasses, caught in error.tsx boundaries
- State: React Query for server state, Zustand for client-only UI state
</patterns>
<conventions>
- Components: PascalCase files in feature directories (e.g., dashboard/UserTable.tsx)
- Utilities: camelCase in lib/ (e.g., lib/formatCurrency.ts)
- Server actions: suffix with "Action" (e.g., updateProfileAction)
- API routes: /app/api/webhooks/* only (prefer server actions)
- Database: snake_case for Postgres, camelCase in Prisma schema
- Env vars: NEXT_PUBLIC_* for client, plain for server
</conventions>
<testing>
- Unit tests: Vitest, colocated as *.test.ts
- Integration: Playwright for critical flows (auth, checkout)
- E2E: tests/e2e/, run via npm run test:e2e
- Coverage: aim for >80% on lib/, >60% on components
- Run: npm test (unit), npm run test:e2e (playwright)
</testing>
<deployment>
- Frontend: auto-deploy from main via Vercel (preview on PRs)
- Workers: Railway deploy via Dockerfile, manual trigger
- Migrations: npm run db:migrate before deploying workers
- Env sync: Vercel CLI for frontend, Railway dashboard for workers
- Staging: branch "staging" deploys to staging.myapp.com
</deployment>
<dependencies>
- shadcn/ui: component library, add via npm run add-component
- Prisma: ORM, schema in prisma/schema.prisma
- React Query: server state, configured in lib/query-client.ts
- NextAuth: authentication, config in lib/auth.ts
- Stripe: payments, webhook handling in app/api/webhooks/stripe/
</dependencies>
<troubleshooting>
- Hydration errors: check for window/localStorage in server components
- Prisma errors: ensure migrations run, check DATABASE_URL env var
- Auth loops: clear cookies, verify NEXTAUTH_SECRET is set
- Build fails: check for TypeScript errors in server actions
</troubleshooting>
This example demonstrates:
Adapt sections to your project's needs. Remove sections that don't apply.