Complete reference for Claude Code's memory management system including all file types, locations, import syntax, and best practices. Use when planning or managing CLAUDE.md and related memory files.
Complete reference for Claude Code's memory management system.
| Memory Type | Location | Purpose | Shared With |
|---|---|---|---|
| Enterprise policy | macOS: /Library/Application Support/ClaudeCode/CLAUDE.mdLinux: /etc/claude-code/CLAUDE.mdWindows: C:\Program Files\ClaudeCode\CLAUDE.md |
Organization-wide standards (IT/DevOps managed) | All org users |
| Project memory | ./CLAUDE.md or ./.claude/CLAUDE.md |
Team-shared project instructions | Team via git |
| Project rules | ./.claude/rules/*.md |
Modular, topic-specific instructions | Team via git |
| User memory | ~/.claude/CLAUDE.md |
Personal preferences for all projects | Just you |
| User rules | ~/.claude/rules/*.md |
Personal modular rules | Just you |
| Project local | ./CLAUDE.local.md |
Personal project-specific preferences | Just you (gitignored) |
Key: Files higher in hierarchy load first; more specific memories take precedence.
Claude Code discovers memory files by:
cwd up to (not including) root /.claude/rules/*.md files loaded with same priority as .claude/CLAUDE.mdView loaded memories: Run /memory command
CLAUDE.md files can import other files using @path/to/file:
# Project Instructions
See @README.md for project overview.
See @docs/architecture.md for system design.
API reference: @docs/api/README.md
# Personal preferences (not in git)
@~/.claude/my-project-prefs.md
Features:
@~/...) for personal preferences.claude/rules/)project/
āāā .claude/
ā āāā CLAUDE.md # Main project instructions
ā āāā rules/
ā āāā code-style.md # Code style guidelines
ā āāā testing.md # Testing conventions
ā āāā security.md # Security requirements
ā āāā api/
ā āāā validation.md # API-specific rules
Use YAML frontmatter to scope rules to specific files:
---
paths: src/api/**/*.ts
---
# API Development Rules
- All endpoints must include input validation
- Use the standard error response format
| Pattern | Matches |
|---|---|
**/*.ts |
All TypeScript files |
src/**/* |
All files under src/ |
*.md |
Markdown files in root |
src/**/*.{ts,tsx} |
TS and TSX in src/ |
{src,lib}/**/*.ts |
TS in src/ or lib/ |
tests/**/*.test.ts |
Test files |
Multiple patterns:
---
paths: {src,lib}/**/*.ts, tests/**/*.test.ts
---
.claude/rules/
āāā frontend/
ā āāā react.md
ā āāā styles.md
āāā backend/
ā āāā api.md
ā āāā database.md
āāā general.md
All .md files discovered recursively.
Share rules across projects:
ln -s ~/shared-claude-rules .claude/rules/shared
ln -s ~/company-standards/security.md .claude/rules/security.md
~/.claude/CLAUDE.md)Personal preferences applying to ALL projects:
~/.claude/rules/)~/.claude/rules/
āāā preferences.md # Personal coding preferences
āāā workflows.md # Preferred workflows
User rules load before project rules; project rules take higher priority.
# ShortcutStart input with #:
# Always use descriptive variable names
Prompts for which memory file to store in.
/memory CommandOpens memory file in system editor for extensive additions.
/init CommandBootstrap a CLAUDE.md for your codebase.
| Scenario | Recommended Location |
|---|---|
| Team coding standards | ./CLAUDE.md |
| Build/test/lint commands | ./CLAUDE.md |
| Topic-specific rules (testing, API, security) | ./.claude/rules/{topic}.md |
| File-type-specific patterns | ./.claude/rules/ with paths: |
| Personal code style | ~/.claude/CLAUDE.md |
| Your local dev URLs/setup | ./CLAUDE.local.md |
| Org-wide compliance | Enterprise policy (IT managed) |
Project Analysis
ā
āā Small project (<500 files, <50 dirs)?
ā āā Single ./CLAUDE.md
ā āā Use @imports for large documentation
ā
āā Medium project with topic diversity?
ā āā ./CLAUDE.md + .claude/rules/
ā āā testing.md
ā āā code-style.md
ā āā {topic}.md
ā
āā Monorepo / microservices?
ā āā Multiple ./CLAUDE.md (one per package/service)
ā āā Each can have own .claude/rules/
ā
āā File-type-specific patterns?
ā āā Path-specific rules with paths: frontmatter
ā
āā Personal dev setup needed?
āā ./CLAUDE.local.md (gitignored automatically)
testing.md, api-design.md, security.mdWhen the same topic is covered in multiple files:
.claude/rules/ (path-specific first)CLAUDE.md~/.claude/rules/~/.claude/CLAUDE.mdCLAUDE.local.md (lowest, but most specific to you)# Project Overview
See @README.md for getting started.
Architecture details: @docs/architecture.md
API reference: @docs/api/README.md
.claude/rules/
āāā testing.md # Test patterns, mocking, coverage
āāā api-design.md # REST conventions, error handling
āāā database.md # Query patterns, migrations
āāā security.md # Auth, validation, secrets
---
paths: src/api/**/*.ts, src/routes/**/*.ts
---
# API Endpoint Rules
- Validate all inputs with zod
- Use consistent error response format
- Include OpenAPI documentation comments
./CLAUDE.local.md:
# My Local Setup
## Dev URLs
- API: http://localhost:3001
- Frontend: http://localhost:3000
- Database: postgresql://localhost:5432/mydb
## Debug Commands
```bash
DEBUG=api:* npm run dev