Skip to main content

Memory and Rules

Claude Code remembers your project in two ways. CLAUDE.md files hold instructions that you write. Auto memory holds notes that Claude writes. Rules in .claude/rules/ split instructions by topic and by file path. Claude treats all of these as context, not as enforced configuration. The text arrives as a user message after the system prompt.

At a Glance​

QuestionAnswer
Can you use it?✅ Yes. Write CLAUDE.md in your project, or run /memory.
Can you change it?✅ Yes. Edit the files, or set autoMemoryEnabled, autoMemoryDirectory, and claudeMdExcludes.
Can you turn it on or off?autoMemoryEnabled, CLAUDE_CODE_DISABLE_AUTO_MEMORY=1, and CLAUDE_CODE_DISABLE_CLAUDE_MDS=1.
Where does it live?~/.claude/CLAUDE.md, ./CLAUDE.md, .claude/rules/, and ~/.claude/projects/<project>/memory/.
StatusDocumented Undocumented Differs

Example​

CLAUDE.md
# Project Notes
Use bun, not npm.
Run `bun test` before you say a task is done.
@docs/architecture.md
.claude/rules/api.md
---
paths:
- "src/api/**/*.ts"
---
Every handler returns a typed error object. Never throw a plain string.

The first file loads in every session and imports docs/architecture.md. The second loads only after Claude touches a file that matches src/api/**/*.ts.

Instruction File Locations​

The list runs in load order, broad scope first. A later file sits later in the context. Official page: How Claude Remembers Your Project.

ItemStatusWhat it doesHow it worksWhere to set it
Managed CLAUDE.mdDocumentedOrganization instructions/Library/Application Support/ClaudeCode/CLAUDE.md (macOS), /etc/claude-code/CLAUDE.md (Linux and WSL), C:\Program Files\ClaudeCode\CLAUDE.md (Windows). Cannot be excludedMachine
claudeMd settingDocumentedManaged CLAUDE.md text inside managed settingsSame precedence as the managed file. Honored only from managed settingsmanaged-settings.json
~/.claude/CLAUDE.mdDocumentedPersonal instructionsLoads for all projects. Imports in it need no approval dialogUser
~/.claude/rules/*.mdDocumentedPersonal rulesLoad before project rules. No override between the two setsUser
./CLAUDE.md or ./.claude/CLAUDE.mdDocumentedProject instructionsFiles in the working directory and each directory above it load at launchProject
./CLAUDE.local.mdDocumentedPrivate project notesAppended after CLAUDE.md in the same directory. Add it to .gitignoreProject
Subdirectory CLAUDE.mdDocumentedLazy instructionsLoads once after Claude reads, writes, or edits a file in that subdirectoryProject
AGENTS.md, .claude/AGENTS.mdDocumentedRead when no CLAUDE.md or CLAUDE.local.md is in or above the working directoryNeeds 2.1.277. AGENTS.local.md, AGENTS.override.md, and .agents/ are not readProject
.claude/rules/**/*.mdDocumentedProject rulesFound recursively. Rules without paths load at launch with the priority of .claude/CLAUDE.mdProject
--add-dir directoriesDocumentedExtra directoriesMemory files load only when CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1. Loads CLAUDE.md, .claude/CLAUDE.md, .claude/rules/*.md, CLAUDE.local.mdCLI

Imports and Rule Files​

ItemStatusWhat it doesHow it worksWhere to set it
@path/to/fileDocumentedImports a file at launchRelative paths resolve from the importing file. Maximum depth is four hops. Put a backslash before each space in the path. Quoted paths do not import. Code spans and fenced blocks are skippedAny memory file
External importDocumentedAn import that resolves outside the working directoryA dialog asks once per project. If declined, they stay off. User-scope files skip the dialogProject files
paths frontmatter in a ruleDocumentedScopes a rule to filesYAML list or comma string of globs. Loads when Read, Write, or Edit (or a Bash read like cat) touches a match. Brace expansion budget: 1,000 patterns and 4 MiB per rule.claude/rules/*.md
Other rule frontmatter keysDocumentedIgnoredpaths is the only key read. Bad YAML loads the rule without paths.claude/rules/*.md
HTML block commentsDocumentedStripped before injectionComments in code blocks stayAny CLAUDE.md
Symlinks in .claude/rules/DocumentedShare rules across projectsA target outside the working directory counts as an external import. Network paths do not load.claude/rules/
claudeMdExcludesDocumentedSkips files by globAbsolute paths with picomatch. Arrays merge across scopes. User, project, and local files onlyAny settings scope
Project instructions (/config)DocumentedChooses claude-md-or-agents-md (default), claude-md-and-agents-md, claude-md, or managed-onlyStored in pluginConfigs["cc-plugin-agents-md@builtin"].options.instructionFiles. Read from user, --settings, and managed settings. agents-md@builtin also works from 2.1.285User, managed
includeGitInstructionsDocumentedRemoves built-in commit and PR instructionsDefault true. Env CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 winsSettings
CLAUDE_CODE_DISABLE_CLAUDE_MDSDocumentedNo CLAUDE.md files in context1 disables user, project, and auto memory filesEnv

Auto Memory​

Auto memory is a folder of notes that Claude writes for itself. MEMORY.md is the index.

ItemStatusWhat it doesHow it worksWhere to set it
autoMemoryEnabledDocumentedTurns auto memory on or offDefault on in local sessions. /memory toggle writes it to user settingsAny settings scope
CLAUDE_CODE_DISABLE_AUTO_MEMORYDocumentedEnv switch1 disables. 0 forces on even with --bare or autoMemoryEnabled: falseEnv
autoMemoryDirectoryDocumentedMemory locationAbsolute path or ~/. Default ~/.claude/projects/<project>/memory/. Ignored in checked-in project settings in the schema text. The docs say project scope works after trustSettings
autoMemoryDirectory scopeDiffersThe schema says project settings are ignored. How Claude Remembers Your Project says project and local scopes work under workspace trustDocs and schema text differSettings
MEMORY.mdDocumentedIndex fileThe first 200 lines or 25KB load at each session start. Topic files load on demandMemory directory
Memory typesDocumenteduser, feedback, project, reference in the type frontmatterClaude writes a modified ISO 8601 field (since 2.1.214)Memory files
/memoryDocumentedLists memory files, toggles auto memory, opens the folderEditor opens a fileInteractive
autoDreamEnabledUndocumentedBackground memory consolidation (auto-dream)Overrides the server defaultSettings
/pause-memoryUndocumentedPauses memory for the sessionOnly the user can turn it back on. Text memory access blocked by /pause-memoryInteractive
CLAUDE_CODE_REMOTE_MEMORY_DIR, CLAUDE_CODE_POST_TURN_MEMORY, CLAUDE_COWORK_MEMORY_*, CLAUDE_MEMORY_STORESUndocumentedCloud, Cowork, and post-turn memoryUse not verifiedEnv
Subagent memory fieldDocumentedA separate memory directory for a subagentSee SubagentsAgent frontmatter

Limits​

ItemStatusWhat it doesHow it worksWhere to set it
CLAUDE.md sizeDocumentedFiles over 4 MiB are skippedA warning shows for files over 200 lines, and for a combined sizeInstruction files
MEMORY.md sizeDocumented200 lines or 25KBA write over the limit succeeds but returns an error that asks for a rewriteMemory
CompactionDocumentedProject-root CLAUDE.md is re-read after /compactNested files and paths rules load again on demand. InstructionsLoaded shows load_reason compactContext

The InstructionsLoaded Hook​

The hook fires when an instruction file enters context. It runs async and has no decision control. It does not fire for an AGENTS.md that loads through the Project instructions setting. The matcher runs on load_reason. Official page: Hooks Reference.

ItemStatusWhat it doesHow it worksWhere to set it
file_pathDocumentedAbsolute path of the fileStringHook input
memory_typeDocumentedScopeUser, Project, Local, ManagedHook input
load_reasonDocumentedWhy it loadedsession_start, nested_traversal, path_glob_match, include, compactHook input
globs, trigger_file_path, parent_file_pathDocumentedExtra contextglobs only for path_glob_match. parent_file_path for includeHook input
InstructionFileKindUndocumentedTiers managed, user, project, local, memoryUsed by the Mod APIMod API

How It Works​

Instruction files do not go into the system prompt. Claude Code reads them at launch, walks up from the working folder, and adds the text as a user message. Nested CLAUDE.md files and paths rules load later, when Claude reads a matching file. After /compact, the project-root CLAUDE.md is read again. See The System Prompt and Context and Compaction.

Not Verified

The size at which the combined-size warning for instruction files appears. The use of the cloud, Cowork, and post-turn memory variables (CLAUDE_CODE_REMOTE_MEMORY_DIR, CLAUDE_CODE_POST_TURN_MEMORY).