Skip to main content

What Is Memory?

Memory in Claude Code is persistent context stored in CLAUDE.md files:
  • Project guidance (conventions, architecture, standards)
  • Domain knowledge (how the codebase works)
  • Workflow instructions (testing, deployment, debugging)
  • Rules and constraints (what to avoid, preferred patterns)
CLAUDE.md files are automatically loaded into context, providing Claude with project-specific knowledge without manual prompting.
Memory files use markdown format and are named CLAUDE.md (or CLAUDE.local.md for personal overrides).

Why Memory Matters

Memory enables:
  • Consistent behavior: Claude follows project conventions automatically
  • Reduced repetition: No need to re-explain architecture every session
  • Team alignment: Shared context in version control
  • Monorepo support: Component-specific instructions load on-demand
  • Personal customization: Local overrides for individual preferences
Keep CLAUDE.md under 150 lines for reliable adherence. Claude’s attention to instructions degrades with longer files.

Memory Scopes

Claude Code loads CLAUDE.md files from three scopes:

Global

Location: ~/.claude/CLAUDE.mdScope: All Claude Code sessionsUse for: Personal preferences, coding style

Project

Location: <project>/CLAUDE.mdScope: This project onlyUse for: Team-shared conventions, architecture

Local

Location: <project>/CLAUDE.local.mdScope: This project, you only (git-ignored)Use for: Personal overrides for this project

Loading Behavior

Claude Code uses two mechanisms for loading CLAUDE.md files:

Ancestor Loading (UP)

When you start Claude Code, it walks upward from your current directory to the filesystem root and loads every CLAUDE.md it finds. Loaded at startup: All ancestor CLAUDE.md files

Descendant Loading (DOWN)

CLAUDE.md files in subdirectories below your current directory are NOT loaded at startup. They’re loaded lazily when you read/edit files in those subdirectories. Loaded on-demand: Only when working in that subdirectory
Working directory: /mymonorepo/
Key insight: Ancestors always load at startup. Descendants load lazily. Siblings never load.

Why This Design Works

Root-level CLAUDE.md contains repository-wide conventions, coding standards, and common patterns that apply everywhere.
Frontend developers don’t need backend-specific instructions cluttering their context, and vice versa.
By lazily loading descendant CLAUDE.md files, Claude Code avoids loading potentially hundreds of kilobytes of irrelevant instructions at startup.

Writing a Good CLAUDE.md

1

Keep it under 150 lines

“CLAUDE.md should not exceed 150+ lines.” — Best Practice Repo
Claude’s adherence degrades with longer files. For large projects, use multiple CLAUDE.md files in subdirectories.
2

Structure clearly

Use clear sections:
3

Be specific and actionable

Good:
Bad:
4

Document critical paths

Focus on what Claude needs to know:
  • Where files live
  • How to run/test/deploy
  • What to avoid
  • Team conventions

Humanlayer Guide

Comprehensive guide to writing effective CLAUDE.md files (60 lines recommended)

Real Example from Repository

From CLAUDE.md in the best practice repository:
Task(subagent_type=“agent-name”, description=”…”, prompt=”…”)

Monorepo Structure Example

Root CLAUDE.md (shared across all components):
Frontend CLAUDE.md (loaded when working in frontend/):

Best Practices

Coding standards, commit message formats, PR templates, and repository-wide guidelines.
Framework-specific patterns, component architecture, testing conventions unique to that component.
Add it to .gitignore for instructions that shouldn’t be shared with the team.
CLAUDE.md is for persistent knowledge, not ephemeral tasks. Use /todos or a task management system instead.
Instead of pasting large code blocks, reference files:

Memory vs Rules

Claude Code also supports a CLAUDE.rules file for organizing rules separately: CLAUDE.md (broad context):
CLAUDE.rules (specific constraints):
Both files are loaded into context. Use CLAUDE.rules to separate constraints from general guidance.

Managing Memory

View and edit all memory files (user, project, and local scope).

Troubleshooting

  • Check file size — keep under 150 lines
  • Use clear, imperative language
  • Add “Critical:” or “Important:” prefixes
  • Repeat critical instructions in multiple sections
  • Try /memory to verify file is loaded
  • Ensure file is named exactly CLAUDE.md (case-sensitive)
  • Check file is in project root or ancestor directory
  • Restart Claude Code if you just created it
  • Split into multiple CLAUDE.md files in subdirectories
  • Use CLAUDE.local.md for personal preferences (git-ignored)
  • Remove outdated or unused sections

Settings

Configure memory-related settings

Subagents

Agents can have persistent memory too

Memory Best Practice

Writing good CLAUDE.md files and monorepo patterns

Agent Memory Report

Persistent memory scopes for subagents

Further Reading