from line 1
11# How Claude remembers your project
22
3> Give Claude persistent instructions with CLAUDE.md files, and let Claude accumulate learnings automatically with auto memory.
3> Give Claude persistent instructions with CLAUDE.md or AGENTS.md files, and let Claude accumulate learnings automatically with auto memory.
44
55Each Claude Code session begins with a fresh context window. Two mechanisms carry knowledge across sessions:
66
7* **CLAUDE.md files**: instructions you write to give Claude persistent context
7* **CLAUDE.md files**: instructions you write to give Claude persistent context. Claude can also read a repository's [`AGENTS.md` files](#agents-md), on their own or alongside CLAUDE.md
88* **Auto memory**: notes Claude writes itself based on your corrections and preferences
99
1010This page covers how to:
1111
1212* [Write and organize CLAUDE.md files](#claude-md-files)
13* [Use an existing AGENTS.md](#agents-md) as your project instructions, on its own or alongside CLAUDE.md
1314* [Scope rules to specific file types](#organize-rules-with-claude/rules/) with `.claude/rules/`
1415* [Configure auto memory](#auto-memory) so Claude takes notes automatically
1516* [Troubleshoot](#troubleshoot-memory-issues) when instructions aren't being followed
from line 33
3233
3334## CLAUDE.md files
3435
35CLAUDE.md files are markdown files that give Claude persistent instructions for a project, your personal workflow, or your entire organization. You write these files in plain text; Claude reads them at the start of every session.
36CLAUDE.md files are markdown files that give Claude persistent instructions for a project, your personal workflow, or your entire organization. You write these files in plain text; Claude reads them at the start of every session. If your repository uses `AGENTS.md` instead, see [AGENTS.md](#agents-md).
3637
3738### When to add to CLAUDE.md
3839
from line 54
5354| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------------- | ------------------------------- |
5455| **Managed policy** | • macOS: `/Library/Application Support/ClaudeCode/CLAUDE.md`<br />• Linux and WSL: `/etc/claude-code/CLAUDE.md`<br />• Windows: `C:\Program Files\ClaudeCode\CLAUDE.md` | Organization-wide instructions managed by IT/DevOps | Company coding standards, security policies, compliance requirements | All users in organization |
5556| **User instructions** | `~/.claude/CLAUDE.md` | Personal preferences for all projects | Code styling preferences, personal tooling shortcuts | Just you (all projects) |
56| **Project instructions** | `./CLAUDE.md` or `./.claude/CLAUDE.md` | Team-shared instructions for the project | Project architecture, coding standards, common workflows | Team members via source control |
57| **Project instructions** | `./CLAUDE.md` or `./.claude/CLAUDE.md`. See [AGENTS.md](#agents-md) for when `./AGENTS.md` loads instead of or alongside them | Team-shared instructions for the project | Project architecture, coding standards, common workflows | Team members via source control |
5758| **Local instructions** | `./CLAUDE.local.md` | Personal project-specific preferences; add to `.gitignore` | Your sandbox URLs, preferred test data | Just you (current project) |
5859
5960CLAUDE.md and CLAUDE.local.md files in the directory hierarchy above the working directory are loaded at launch. Files in subdirectories load on demand when Claude reads files in those directories. See [How CLAUDE.md files load](#how-claude-md-files-load) for the full resolution order.
from line 121
120121 In Cowork sessions on your desktop, Claude Code skips any import in a user-scope file that resolves to a path outside the session's working directory and loads the rest of the file. In those sessions it also skips a `~/.claude/CLAUDE.md` that is itself a symlink or hard link, and a symlinked `~/.claude/rules/` directory or rule file that points outside the working directory.
121122</Warning>
122123
123### AGENTS.md
124
125Claude Code reads `CLAUDE.md`, not `AGENTS.md`. If your repository already uses `AGENTS.md` for other coding agents, create a `CLAUDE.md` that imports it so both tools read the same instructions without duplicating them. You can also add Claude-specific instructions below the import. Claude loads the imported file at session start, then appends the rest:
126
127```markdown CLAUDE.md theme={null}
128@AGENTS.md
129
130## Claude Code
131
132Use plan mode for changes under `src/billing/`.
133```
134
135A symlink also works if you don't need to add Claude-specific content:
136
137```bash theme={null}
138ln -s AGENTS.md CLAUDE.md
139```
140
141The command prints no output on success. In your next session, run `/context` and confirm `CLAUDE.md` appears under **Memory files**.
142
143On Windows, creating a symlink requires Administrator privileges or Developer Mode, so use the `@AGENTS.md` import instead.
144
145Running [`/init`](/docs/en/commands) reads Cursor rules, in `.cursor/rules/` or `.cursorrules`, and Copilot rules, in `.github/copilot-instructions.md`, and incorporates the relevant parts into the generated `CLAUDE.md`. With `CLAUDE_CODE_NEW_INIT=1` set, `/init` also reads `AGENTS.md`, `.devin/rules/`, `.windsurf/rules/` or `.windsurfrules`, and `.clinerules`.
146
147You can also run [`/import`](/docs/en/commands) to bring a supported coding agent's configuration into Claude Code, which appends a one-time copy of instruction files such as `AGENTS.md` to the matching `CLAUDE.md` and carries over MCP servers, commands, subagents, and skills. Requires Claude Code v2.1.213 or later.
148
149124### How CLAUDE.md files load
150125
151126Claude Code loads `CLAUDE.md` and `CLAUDE.local.md` from your current working directory and every directory above it. Run Claude Code in `foo/bar/` and it loads instructions from `foo/bar/CLAUDE.md`, `foo/CLAUDE.md`, and any `CLAUDE.local.md` files alongside them.
from line 312
337312
338313Managed policy CLAUDE.md files cannot be excluded. This ensures organization-wide instructions always apply regardless of individual settings.
339314
315## AGENTS.md
316
317If your repository already has an `AGENTS.md` and no `CLAUDE.md`, Claude reads it as your project instructions and you don't need to add a `CLAUDE.md`, an import, or a setting. `AGENTS.md` is a markdown file of project instructions you write for AI coding agents. If you also have a `CLAUDE.md` in your working directory or a directory above it, Claude reads that instead by default; to have Claude read both files, [change the **Project instructions** setting](#choose-which-instruction-files-load). If your `CLAUDE.md` already [imports `AGENTS.md`](#share-one-file-with-other-coding-tools), you don't need to change anything.
318
319<Note>
320 Reading `AGENTS.md` directly requires Claude Code v2.1.277 or later. In some sessions, such as those on Amazon Bedrock or with telemetry disabled, Claude [can't read `AGENTS.md`](#when-agents-md-support-is-unavailable), so [import it from a `CLAUDE.md`](#share-one-file-with-other-coding-tools) there instead.
321</Note>
322
323### When Claude Code reads AGENTS.md
324
325By default, Claude checks your working directory and every directory above it, up to the filesystem root, before deciding what to read:
326
327* **You have a `CLAUDE.md`, `.claude/CLAUDE.md`, or `CLAUDE.local.md` there**: Claude reads your `CLAUDE.md` files as described in [How CLAUDE.md files load](#how-claude-md-files-load) and ignores every `AGENTS.md`.
328* **You have none of those**: Claude reads every `AGENTS.md` and `.claude/AGENTS.md` in your working directory and the directories above it. In an interactive session you see a line such as `no CLAUDE.md found; AGENTS.md loaded: /home/you/repo/AGENTS.md` in the conversation. When Claude later reads a file in a subdirectory that has its own `AGENTS.md` and no `CLAUDE.md`, it picks up that `AGENTS.md` too.
329
330Your `~/.claude/CLAUDE.md`, your organization's managed `CLAUDE.md`, and your `.claude/rules/` files don't affect this check, and Claude keeps reading them alongside `AGENTS.md`. Keep personal instructions that apply to every project in `~/.claude/CLAUDE.md`.
331
332A `CLAUDE.local.md` does affect the check. If you add one for private notes in a project that relies on `AGENTS.md`, Claude stops reading `AGENTS.md` for you. To get both, set **Project instructions** to [`claude-md-and-agents-md`](#choose-which-instruction-files-load).
333
334Once Claude reads your `AGENTS.md`, you can treat it as you would a project `CLAUDE.md`:
335
336* Use [`@path` imports](#import-additional-files) in it
337* Exclude it with [`claudeMdExcludes`](#exclude-specific-claude-md-files)
338* Expect subagents that [skip project instructions](/docs/en/sub-agents#what-loads-at-startup) to skip it too
339
340### Choose which instruction files load
341
342To change which files Claude reads, type `/config` in a Claude Code session to open the settings panel, then set **Project instructions** to one of these values:
343
344| Value | What Claude reads |
345| :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
346| `claude-md-or-agents-md` | Your `CLAUDE.md` files, or your `AGENTS.md` files when you have no `CLAUDE.md` in your working directory or above it. This is the default |
347| `claude-md-and-agents-md` | Your `CLAUDE.md` and `AGENTS.md` files together, each directory's `AGENTS.md` after its `CLAUDE.md` |
348| `claude-md` | Your `CLAUDE.md` files only |
349| `managed-only` | Only your organization's managed `CLAUDE.md` and [auto memory](#auto-memory) at launch. Your project, local, and user `CLAUDE.md` files, your `.claude/rules/` files, and every `AGENTS.md` are left out |
350
351Two of these values have details worth knowing before you pick them:
352
353* With `claude-md-and-agents-md`, if your `CLAUDE.md` already imports or symlinks to the `AGENTS.md` beside it, you get that content once, not twice.
354* With `managed-only`, Claude still reads a subdirectory's `CLAUDE.md` and `.claude/rules/` files when it reads a file in that subdirectory, and still applies [path-scoped rules](#path-specific-rules).
355
356You can also set the value in a settings file instead of `/config`. Add it under the built-in `agents-md` plugin's ID in [`pluginConfigs`](/docs/en/settings-reference#pluginconfigs), in `~/.claude/settings.json`, a `--settings` file, or [managed settings](/docs/en/managed-settings). Claude Code ignores it in project and local settings files. This example has Claude read both files:
357
358```json settings.json theme={null}
359{
360 "pluginConfigs": {
361 "agents-md@builtin": {
362 "options": { "instructionFiles": "claude-md-and-agents-md" }
363 }
364 }
365}
366```
367
368Your change applies from the next message you send and in every new session.
369
370### When AGENTS.md support is unavailable
371
372In these sessions Claude reads `CLAUDE.md` files only, and you won't see **Project instructions** in the `/config` settings panel:
373
374* You're on a Claude Code version before v2.1.277
375* Your session doesn't [fetch feature flags from Anthropic](/docs/en/env-vars#features-that-need-feature-flag-fetching), for example because you use Amazon Bedrock or another third-party provider, or you disabled telemetry. The linked section has the full list
376* It's your [first session after you install or upgrade](/docs/en/env-vars#first-session-after-an-install-or-upgrade) to a version with `AGENTS.md` support. Claude reads `AGENTS.md` from your next session on
377* You or your organization set [`disableAllHooks`](/docs/en/settings-reference#disableallhooks) or [`allowManagedHooksOnly`](/docs/en/settings-reference#allowmanagedhooksonly), or you disabled the built-in `agents-md` plugin in `/plugin`
378
379To give Claude your `AGENTS.md` in these sessions, [import it from a `CLAUDE.md`](#share-one-file-with-other-coding-tools).
380
381### Where AGENTS.md differs from CLAUDE.md
382
383An `AGENTS.md` that Claude reads through the **Project instructions** setting differs from a `CLAUDE.md` in these ways:
384
385* You won't see it in `/memory` or in the **Memory files** list in `/context`. To confirm Claude read it, look for the [`AGENTS.md loaded` line](#when-claude-code-reads-agents-md) or ask Claude what its project instructions say. With `claude-md-and-agents-md` there's no such line, so ask Claude
386* Your [`InstructionsLoaded` hooks](/docs/en/hooks#instructionsloaded) don't fire when Claude reads it directly. They fire as usual when a `CLAUDE.md` imports or symlinks to it
387* If you set [`CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD`](#load-from-additional-directories), Claude reads the `CLAUDE.md` from each directory you add with `--add-dir`, but not its `AGENTS.md`
388* If your `AGENTS.md` imports a file outside your working directory with `@path`, Claude reads that file only if you already approved [external imports](#import-additional-files) for this project. You aren't prompted to approve it from `AGENTS.md`
389
390### Remove an earlier AGENTS.md workaround
391
392If you set Claude Code up to read `AGENTS.md` before it did so on its own, here's what to do with each common setup:
393
394* **A `CLAUDE.md` containing `@AGENTS.md`**: nothing. It keeps working, and it's still the right setup if some of your sessions [can't load `AGENTS.md`](#when-agents-md-support-is-unavailable). If the file holds nothing else and all your sessions can load `AGENTS.md`, you can delete it.
395* **A `CLAUDE.md` that tells Claude in words to read `AGENTS.md`**: Claude sees `AGENTS.md` only if it decides to open the file. Delete the `CLAUDE.md` so Claude reads `AGENTS.md` directly, or replace the sentence with an `@AGENTS.md` import.
396* **A `CLAUDE.md` symlinked to `AGENTS.md`**: nothing, or delete the symlink. Either way Claude reads the content once.
397* **A `SessionStart` hook that prints `AGENTS.md`**: remove it. Once Claude reads `AGENTS.md` directly, the hook adds a second copy to the context.
398
399### Share one file with other coding tools
400
401When Claude isn't reading your `AGENTS.md` directly, you can still keep it as the one file every tool shares by putting an `@AGENTS.md` import in a `CLAUDE.md` next to it. Do this when your project also has a `CLAUDE.md`, when you've set **Project instructions** to `claude-md`, or in sessions that [can't load `AGENTS.md`](#when-agents-md-support-is-unavailable). Add any Claude-specific instructions below the import, and Claude reads the imported file first, then the rest:
402
403```markdown CLAUDE.md theme={null}
404@AGENTS.md
405
406## Claude Code
407
408Use plan mode for changes under `src/billing/`.
409```
410
411If you don't need Claude-specific content, a symlink also works:
412
413```bash theme={null}
414ln -s AGENTS.md CLAUDE.md
415```
416
417The command prints no output on success. On Windows, creating a symlink requires Administrator privileges or Developer Mode, so use the `@AGENTS.md` import instead.
418
419With either approach, run `/context` in your next session and confirm `CLAUDE.md` appears under **Memory files**.
420
421### Migrate instructions from other tools
422
423Running [`/init`](/docs/en/commands) reads other tools' instruction files and incorporates the relevant parts into the generated `CLAUDE.md`:
424
425* Cursor rules in `.cursor/rules/` or `.cursorrules`
426* Copilot rules in `.github/copilot-instructions.md`
427* With `CLAUDE_CODE_NEW_INIT=1` set: `AGENTS.md`, `.devin/rules/`, `.windsurf/rules/` or `.windsurfrules`, and `.clinerules`
428
429You can also run [`/import`](/docs/en/commands) to bring a supported coding agent's configuration into Claude Code, which appends a one-time copy of instruction files such as `AGENTS.md` to the matching `CLAUDE.md` and carries over MCP servers, commands, subagents, and skills. Requires Claude Code v2.1.213 or later.
430
340431## Auto memory
341432
342433Auto memory lets Claude accumulate knowledge across sessions without you writing anything. As it works, Claude saves four kinds of notes for itself. Claude records the kind as a `type` field in the memory file's frontmatter:
from line 509
418509
419510## View and edit with `/memory`
420511
421The `/memory` command lists your CLAUDE.md, CLAUDE.local.md, and other memory file locations across user and project scopes, including user and project CLAUDE.md entries for files that don't exist yet. It also lets you toggle auto memory on or off and provides an option to open the auto memory folder. Select any file to open it in your editor; selecting one that doesn't exist yet creates it first. To check which files actually loaded into the current session, run `/context`.
512The `/memory` command lists your CLAUDE.md, CLAUDE.local.md, and other memory file locations across user and project scopes, including user and project CLAUDE.md entries for files that don't exist yet. It also lets you toggle auto memory on or off and provides an option to open the auto memory folder. Select any file to open it in your editor; selecting one that doesn't exist yet creates it first. To check which `CLAUDE.md` and rules files loaded into the current session, run `/context`.
422513
423514GUI editors such as VS Code open the file in a separate window, and you can keep using the session while it's open. Before v2.1.216, `/memory` waited for you to close the file before responding. Terminal editors such as Vim take over the terminal until you exit.
424515
from line 525
434525
435526To debug:
436527
437* Run `/context` and check the list under **Memory files** to verify your CLAUDE.md and CLAUDE.local.md files loaded. If a file is missing there, Claude can't see it. Use `/memory` to open and edit the files.
528* Run `/context` and check the list under **Memory files** to verify your CLAUDE.md and CLAUDE.local.md files loaded. If a `CLAUDE.md` file is missing there, Claude can't see it. An `AGENTS.md` appears there only when a `CLAUDE.md` imports it, not when Claude [reads it directly](#where-agents-md-differs-from-claude-md). Use `/memory` to open and edit the files.
438529* Check that the relevant CLAUDE.md is in a location that gets loaded for your session (see [Choose where to put CLAUDE.md files](#choose-where-to-put-claude-md-files)).
439530* Make instructions more specific. "Use 2-space indentation" works better than "format code nicely."
440531* Look for conflicting instructions across CLAUDE.md files. If two files give different guidance for the same behavior, Claude may pick one arbitrarily.
from line 535
444535For instructions you want at the system prompt level, use [`--append-system-prompt`](/docs/en/cli-reference#system-prompt-flags). You pass it at launch, so it's better suited to scripts and automation than interactive use. For how it behaves when you resume a conversation, see [System prompt flags in resumed conversations](/docs/en/cli-reference#system-prompt-flags-in-resumed-conversations).
445536
446537<Tip>
447 Use the [`InstructionsLoaded` hook](/docs/en/hooks#instructionsloaded) to log exactly which instruction files are loaded, when they load, and why. This is useful for debugging path-specific rules or lazy-loaded files in subdirectories.
538 Use the [`InstructionsLoaded` hook](/docs/en/hooks#instructionsloaded) to log which `CLAUDE.md` and rules files are loaded, when they load, and why. This is useful for debugging path-specific rules or lazy-loaded files in subdirectories.
448539</Tip>
540
541### My AGENTS.md isn't loading
542
543If your repository has an `AGENTS.md` and Claude doesn't seem to know what it says, the usual cause is a `CLAUDE.md` somewhere on the project path. By default Claude reads `AGENTS.md` only when you have no `CLAUDE.md` in your working directory or above it. Check these in order:
544
5451. Look for a `CLAUDE.md`, `.claude/CLAUDE.md`, or `CLAUDE.local.md` in your working directory or any directory above it, other than your `~/.claude/CLAUDE.md`. If you find one, Claude reads it instead of `AGENTS.md` unless you set **Project instructions** to `claude-md-and-agents-md`.
5462. Run `claude --version` and confirm v2.1.277 or later.
5473. Check whether your session is one that [can't load `AGENTS.md`](#when-agents-md-support-is-unavailable), such as a session on a third-party provider or with telemetry disabled.
5484. Type `/config` in your session to open the settings panel and confirm **Project instructions** isn't set to `claude-md` or `managed-only`. If you don't see the setting there at all, your session is one that [can't load `AGENTS.md`](#when-agents-md-support-is-unavailable).
549
550You won't see `AGENTS.md` in `/memory` or `/context` when Claude reads it directly, so check for the `AGENTS.md loaded` line or ask Claude what its project instructions say instead. If you want to keep the `CLAUDE.md` you found, or your session can't load `AGENTS.md`, [add a `CLAUDE.md` next to your `AGENTS.md` that imports it](#share-one-file-with-other-coding-tools).
449551
450552### I don't know what auto memory saved
451553