Claude Code

Memory and rules

How Claude Code reads CLAUDE.md, auto memory, and .claude/rules, with compatibility guidance for AGENTS.md projects.

Each Claude Code session starts with a new context window. Two mechanisms preserve project knowledge: the CLAUDE.md instructions you maintain and the auto memory Claude accumulates.

#CLAUDE.md and auto memory

MechanismAuthorContentsBest for
CLAUDE.mdYou or your teamExplicit instructions, directories, commands, conventionsVerifiable long-term rules
Auto memoryClaudePatterns learned from correctionsRecurring preferences and project experience

Both are context, not enforced permissions. Use permission rules or hooks to enforce restrictions.

#File locations

ScopeLocationPurpose
Managed policymacOS /Library/Application Support/ClaudeCode/CLAUDE.md, Linux /etc/claude-code/CLAUDE.md, Windows C:\Program Files\ClaudeCode\CLAUDE.mdOrganization instructions
User~/.claude/CLAUDE.mdPersonal preferences across projects
Project./CLAUDE.md or ./.claude/CLAUDE.mdShared project rules
Local./CLAUDE.local.mdPrivate project-specific rules; add to gitignore
Rules./.claude/rules/*.mdModular rules, optionally loaded by path

Claude searches upward from the current directory for CLAUDE.md and CLAUDE.local.md. Content closer to the working directory enters context later and is more specific. Subdirectory CLAUDE.md files load as Claude reads relevant files.

your-project/
├── CLAUDE.md
└── .claude/
    ├── settings.json
    └── rules/
        ├── testing.md
        ├── api.md
        └── frontend.md

Use CLAUDE.md for the overall structure:

CLAUDE.md
# Project conventions

- Package manager: pnpm
- Run `pnpm lint` after changes, and `pnpm typecheck` for type-related changes
- Do not put .env files, keys, or production configuration in documentation or commits

## Directories

- Pages: `src/app`
- Components: `src/components`
- Documentation: `content/docs`

## Working process

- Propose a plan before large changes
- Check light and dark modes after UI changes
- Include validation commands in the final report

#Shorter rules are easier to follow

Aim for fewer than 200 lines. Long files consume context and are more likely to contain contradictions.

Effective rules tend to be:

  • Specific: say pnpm lint, not “run necessary checks.”
  • Verifiable: say “do not commit .env,” not “be careful with security.”
  • Organized by topic: separate build, testing, directories, and style.

If a rule applies only to certain directories, put it in .claude/rules/ with paths instead of adding it to the root CLAUDE.md.

#Import other files

CLAUDE.md supports @path imports. Relative paths resolve from the containing CLAUDE.md directory, with up to four levels of recursive imports.

CLAUDE.md
@README.md
@docs/development.md

## Claude Code additions

- Prefer existing components
- Avoid unrelated refactoring

To display the string literally, wrap it in backticks, such as ` @README.md `.

The first import of a file outside the project requires confirmation. A rejected import does not automatically prompt again; adjust it manually if needed.

#Projects using AGENTS.md

For installations using CLAUDE.md rather than native AGENTS.md loading, an existing AGENTS.md can be imported:

CLAUDE.md
@AGENTS.md

## Claude Code

- Use plan mode before broad changes
- Check mobile, light, and dark layouts after UI changes

A symlink is another option, but the @AGENTS.md import is easier on Windows. Check the current official memory documentation for your version's native AGENTS.md support before keeping both mechanisms enabled.

#.claude/rules/

Rule files provide more granular CLAUDE.md guidance. Rules without frontmatter load at startup:

.claude/rules/testing.md
# Testing rules

- Run the relevant unit tests after fixing a bug
- Do not skip failing tests

Rules with paths load when matching files are accessed:

.claude/rules/api.md
---
paths:
  - "src/api/**/*.ts"
  - "app/api/**/*.ts"
---

# API rules

- Validate all inputs
- Return a consistent `{ code, message }` error shape
- Never put server secrets in the client bundle

This is especially useful in large repositories, reducing irrelevant context and cache invalidation.

#Auto memory

Auto memory records lessons Claude learns from corrections and shares them across sessions for a repository. It is useful for project-specific experience such as build commands, test prerequisites, and recurring failure causes.

Common controls:

NeedAction
Temporarily disable auto memorySet CLAUDE_CODE_DISABLE_AUTO_MEMORY=1
Diagnose why memory did not applyInspect loaded content with /context
Make a class of rules more reliablePromote it from auto memory to CLAUDE.md

#Troubleshooting

SymptomPossible causeCheck
Current session ignores a CLAUDE.md editRoot instructions were loaded at startup/clear, /compact, or restart
Subdirectory rule does not applyClaude has not read a matching fileExplicitly reference it with @file
Rules conflictMultiple instruction files overlapInspect load order in /context
AGENTS.md does not applyVersion or configuration does not load it nativelyUse a CLAUDE.md import or check native support
Too many rules in a large repositoryInstructions fill the contextSplit into path-scoped rules

#Official references

Support

Need help?

For setup, billing, or model issues, email us. Check the status page for uptime.

WeChat / QQ support is available at the bottom right.