Expert guidance for creating, updating, and maintaining CLAUDE.md memory files following best practices for hierarchical memory, structure, content organization, and team collaboration
npx playbooks add skill agdev/claude-code --skill managing-claude-memory
CLAUDE.md files are persistent memory documents that help Claude understand codebases, preferences, and working patterns across sessions. They serve as a bridge between sessions, maintaining context and enforcing guidelines.
Claude searches for CLAUDE.md files in a hierarchical memory system with four levels (highest to lowest priority):
/etc/claude-code/CLAUDE.md on Linux, /Library/Application Support/ClaudeCode/CLAUDE.md on macOS)./CLAUDE.md or ./.claude/CLAUDE.md)~/.claude/CLAUDE.md)./CLAUDE.local.md)CLAUDE.md supports importing other files using @path/to/import syntax:
## Architecture
@./docs/architecture-guide.md
## Testing Standards
@./specs/testing-requirements.md
Features:
# [Project Name]
[One-sentence description]
## Quick Reference (Optional: for files >150 lines)
## Commands
## Project Structure
## Code Style
## Architecture Patterns
## Critical Rules
## Environment Variables
## Common Pitfalls
## Testing
## Additional Resources
#, ##, ###) to organize information.claude/settings.json insteadRule: Keep CLAUDE.md files concise. Every line consumes tokens on every request.
❌ Too verbose:
This project uses TypeScript with strict mode enabled, which means that
all code must be properly typed and we don't allow the use of the 'any'
type anywhere in the codebase because it defeats the purpose.
✅ Concise:
- **TypeScript strict mode** - No implicit any, strict null checks
- **No any types** - Use `unknown` if type is truly unknown
Rule: Use emphasis markers (IMPORTANT, ALWAYS, NEVER, MUST) for critical rules.
Example:
## Critical Rules
- **IMPORTANT:** All imports MUST include `.js` extension (ES modules)
- **NEVER delete users** - Use `active: false` for soft delete
- **ALWAYS validate requests** with Zod schemas before controllers
Rule: Document mistakes with ❌ (wrong) and ✅ (correct) code examples.
Example:
### Import Extensions
❌ `import { User } from './models/user'`
✅ `import { User } from './models/user.js'`
### Error Handling
❌ `throw 'User not found'`
✅ `throw new NotFoundError('User not found')`
Rule: Group commands by purpose with comments explaining when to use.
Example:
### Development
npm run dev # Start server with hot reload on port 4000
npm run typecheck # Type check without emit (run before commits)
npm run lint:fix # Auto-fix linting issues
Rule: Root CLAUDE.md provides overview, subdirectory files provide specifics.
Example:
## Monorepo Structure
**Directory-specific guidance:**
- See `client/CLAUDE.md` for React/Vite patterns
- See `server/CLAUDE.md` for Express/Node patterns
- See `shared/CLAUDE.md` for shared library development
Rule: For complex projects (>150 lines), start with Quick Reference.
Example:
## Quick Reference
**Full Documentation:**
- **API Reference:** `README.md` (1,663 lines)
- **Migration Guide:** `docs/MIGRATION.md` (1,051 lines)
**Package:** `@app-master/auth@0.1.0`
**Test Coverage:** 96.73% (329 passing tests)
Rule: Use @path/to/file syntax to help Claude discover related docs.
Example:
## Common Workflows
- **Modify AI Behavior**: @server/systemInstructions/CLAUDE.md
- **Add New Tags**: @docs/tag-system.md
- **Database Schema**: @docs/database.md
User-level (~/.claude/CLAUDE.md):
Project-level (./CLAUDE.md):
Rule: Never duplicate content. Keep project-specific rules at project level only.
Use when: Small projects, prototypes, POCs, simple utilities
# [Project Name]
[One-sentence description]
## Tech Stack
- [Framework/Language with version]
- [Key dependencies]
## Commands
### Development
[start command] # [Description]
[test command] # [Description]
## Project Structure
[directory tree with brief descriptions]
## Code Style
- [Import style]
- [Naming conventions]
- [File organization]
## Critical Rules
- **IMPORTANT:** [Critical constraint]
- **NEVER** [Common mistake to avoid]
- **ALWAYS** [Essential practice]
Use when: Most full-featured applications, team projects
# [Project Name]
[2-3 sentence description including purpose and key features]
## Tech Stack
- [Framework versions]
- [Key dependencies]
## Commands
### Development
[commands with inline comments]
### Testing
[test commands]
### Production
[build/deploy commands]
## Project Structure
[directory tree with purpose explanations]
**Key Files:**
- `[file]` - [Purpose]
- `[file]` - [Purpose]
## Code Style
### Import/Export
- [Style with examples]
### Naming Conventions
- [Pattern] - [Use case]
### TypeScript/Type System
- [Key rules]
## Architecture Patterns
### [Pattern Category 1]
[Brief explanation with code example]
### [Pattern Category 2]
[Brief explanation]
## Critical Rules
- **IMPORTANT:** [Critical rule]
- **NEVER** [Anti-pattern]
- **ALWAYS** [Best practice]
## Environment Variables
### Required
- `[VAR]` - [Description]
### Optional
- `[VAR]` - [Description with default]
## Common Pitfalls
### [Category]
❌ [Wrong way with code]
✅ [Right way with code]
## Testing
- **Framework:** [Tool]
- **Coverage:** [Target]
- **Commands:** [Key commands]
## Additional Resources
- **[Doc Category]:** [Path] - [Description]
Use when: Multiple related projects in one repository
# [Monorepo Name]
[Description of overall system]
## Monorepo Structure
project-root/
├── [package1]/ - [Description] (see [package1]/CLAUDE.md)
├── [package2]/ - [Description] (see [package2]/CLAUDE.md)
└── [shared]/ - [Description] (see [shared]/CLAUDE.md)
**Directory-specific guidance:**
- See `[package1]/CLAUDE.md` for [topic]
- See `[package2]/CLAUDE.md` for [topic]
## Development
### Terminal Setup
[command]
[command]
### Testing
[command]
[command]
## Cross-Cutting Patterns
- **[Pattern]** - [Description]
## Monorepo Conventions
### Package Management
- **[Approach]** - [Explanation]
## Critical Business Rules
- **NEVER** [Global rule]
- **ALWAYS** [Global rule]
## Git Workflow
- **Main branch:** [branch]
- **Feature branches:** [pattern]
## Common Pitfalls
### Monorepo Management
❌ [Wrong approach]
✅ [Right approach]
Use when: Reusable packages/libraries consumed by multiple projects
# [Library Name]
[One-line description of library purpose]
## Quick Reference
**Full Documentation:**
- **API Reference:** `README.md` - [Brief description]
**Package:** `[package-name]@[version]`
**Test Coverage:** [percentage]
## Installation
### Build the Library
[build commands]
### Add to Consuming Project
{
"dependencies": {
"[package-name]": "[path or version]"
}
}
## Common Usage Patterns
### [Pattern Category]
[Code example with explanation]
## Library Structure
src/
├── [module]/ - [Purpose]
## Common Patterns
### Backend
[Example]
### Frontend
[Example]
## Testing
- **Framework:** [Tool]
- **Coverage:** [Target]
- **Commands:** [List]
## Critical Rules
- **IMPORTANT:** [Key rule]
- **NEVER** [Anti-pattern]
- **ALWAYS** [Best practice]
## Common Pitfalls
### [Category]
❌ **WRONG:** [Code example]
✅ **CORRECT:** [Code example]
## Performance
- [Bundle size info]
- [Tree-shaking guidance]
Use when: Personal preferences across all projects
# Personal Claude Code Preferences
## Model Usage
### Planning Mode
[Preferred model]
### Execution Mode
[Preferred model]
## Project Structure Conventions
- [Universal folder patterns]
- [Backup file locations]
## Code Style
- [Naming preferences]
- [Comment style]
- [Import organization]
## Documentation Guidelines
### When to Create Documentation
- **NEVER** create documentation files unless explicitly requested
- Only create when user specifically asks
### Documentation Structure
- [Folder organization if you create docs]
## Design Principles
- [Your coding philosophy]
- [Simplicity vs complexity preferences]
## Git Conventions
- [Commit message style]
- [Never commit without explicit instruction]
Use when: Educational repositories, course materials, learning resources
# [Course/Tutorial Name]
[Description of learning objectives]
## Repository Structure
### Core Directories
- `[dir]/` - [Purpose and what learners do]
- `[subdir]/` - [Purpose]
### Key File Patterns
- `[filename]` - [What it demonstrates]
## Development Setup
### Environment Setup
[Setup commands with explanations]
### [Technology] Server
[How to run required services]
## Common Development Commands
### [Task Category]
[command] # [Explanation]
## [Technology] Architecture Patterns
### Core Components
- **[Component]** - [What it does and how to use it]
## Dependencies
Key packages:
- `[package]` - [Purpose]
## Development Environment
This repository works with:
- **[Environment 1]** - [Special notes]
- **[Environment 2]** - [Special notes]
# App Master - Internal user and application management system
Monorepo with React frontend and Express backend.
## Monorepo Structure
project-root/
├── client/ - React 19 + Vite + TypeScript (port 3000)
├── server/ - Express + TypeScript + MongoDB (port 4000)
└── docs/ - PRD and documentation
**Directory-specific guidance:**
- See `client/CLAUDE.md` for React/Vite patterns
- See `server/CLAUDE.md` for Express/Node patterns
## Critical Business Rules
- **NEVER delete users/applications** - Set `active: false` for soft delete
- **NEVER commit .env files** - Use .env.sample templates
- **ALWAYS validate inputs** - Both frontend and backend
Why this is good:
## Code Style
### Import/Export
- **ES modules only** - All imports require `.js` extension
- **Path aliases** - Use `@/` for `src/`
- **No default exports** - Use named exports
### Error Handling
- **Use AppError classes** - NotFoundError, ValidationError, etc.
- **Wrap async routes** - Use `asyncHandler()`
- **Never throw strings** - Always throw Error instances
## Common Pitfalls
### Import Extensions
❌ `import { User } from './models/user'`
✅ `import { User } from './models/user.js'`
### Async Routes
❌ `router.get('/users', async (req, res) => { ... })`
✅ `router.get('/users', asyncHandler(async (req, res) => { ... }))`
## Quick Reference
**Full Documentation:**
- **API Reference:** `README.md` (1,663 lines)
- **Migration Guide:** `docs/MIGRATION.md` (1,051 lines)
**Package:** `@app-master/auth@0.1.0`
**Test Coverage:** 96.73% (329 passing tests)
## Common Usage Patterns
### Subpath Imports (Recommended for Tree-Shaking)
**IMPORTANT:** Use subpath imports to minimize bundle size
// Types
import { User, UserRole } from '@app-master/auth/types';
// Validation schemas
import { loginSchema } from '@app-master/auth/schemas';
## Common Pitfalls
### Importing Entire Package
❌ **WRONG (imports everything):**
import { User, loginSchema } from '@app-master/auth';
✅ **CORRECT (granular imports):**
import { User } from '@app-master/auth/types';
import { loginSchema } from '@app-master/auth/schemas';
Problem:
# Project CLAUDE.md that duplicates user-level content
# Model usage
## Planning mode
Opus when available
## Execution mode
Sonnet
[... exact copy of user-level CLAUDE.md ...]
Why this is bad:
Correct approach:
# Project Name
[Only project-specific content here]
# User-level CLAUDE.md already provides model selection
Problem:
## Project Structure [in ~/.claude/CLAUDE.md]
- Place all test files in 'test-ground' folder at root
Why this is bad:
Correct approach:
Problem:
- Follow project-specific CLAUDE.md in backend/ subdirectory
Why this is bad:
Correct approach:
- **Backend:** @backend/CLAUDE.md - FastAPI patterns, Burr workflows
Problem:
- `src/api/client.ts` - Axios instance (to be created)
Why this is bad:
Correct approach:
**Planned (Not Yet Implemented):**
- `src/api/client.ts` - Axios instance with httpOnly cookies
Problem:
Correct approach:
Before committing CLAUDE.md, verify:
Structure & Organization:
Content Quality:
Technical Accuracy:
Token Efficiency:
Security:
Completeness:
Hierarchy:
# key during conversation/init command for auto-generation/memory commandWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.