What you will be able to do
- Place an instruction at the right CLAUDE.md scope: managed, user, project or local
- Bootstrap a repository with /init and scope instructions to file types with .claude/rules/
- Tell CLAUDE.md apart from auto memory, and configure or turn off auto memory
- Choose the right settings.json scope and work out which value wins when a key is set in several places
Key concept
Layered persistent context — Claude Code starts every session from files on disk, not from earlier chats. You write instructions in CLAUDE.md files at different scopes, and Claude adds its own notes through auto memory. settings.json files then set what the tool is allowed to do.
1.The CLAUDE.md hierarchy
A CLAUDE.md file holds instructions you write, and it loads into every session. The hard part is choosing where to put it. There are four scopes. Each one answers a different question: who should this instruction reach, and should it be committed to git?
| Scope | Location | Shared with |
|---|---|---|
| Managed policy | /Library/Application Support/ClaudeCode/CLAUDE.md (macOS), /etc/claude-code/CLAUDE.md (Linux and WSL) | All users in organization |
| User instructions | ~/.claude/CLAUDE.md | Just you (all projects) |
| Project instructions | ./CLAUDE.md or ./.claude/CLAUDE.md | Team members via source control |
| Local instructions | ./CLAUDE.local.md | Just you (current project) |
CLAUDE.local.md is for personal project-specific preferences, such as your sandbox URLs, and you should add it to .gitignore. The project file is what the team shares. If a repository has an AGENTS.md, Claude reads it only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or any directory above it. Your user-level and managed CLAUDE.md files don't count toward that rule.
Write instructions that are specific. 'Use 2-space indentation' works better than 'Format code properly'. Keep each file under about 200 lines, and group related rules under headers. If two instructions contradict each other, Claude may follow either one. You can split a long file with @path imports, but imports don't make it cheaper: the imported files load at launch too.
See @README for project overview and @package.json for available npm commands for this project.
# Additional Instructions
- git workflow @docs/git-instructions.mdTwo built-in slash commands help when an instruction seems to be ignored. /context lists the memory files that actually loaded. /memory opens those files so you can edit them.
Checkpoint 1 of 6· Check yourself
You want Claude to use your personal staging URL in one repository, and you don't want teammates to see it. Where does the instruction go?
Local instructions cover one project and reach only you. ~/.claude/CLAUDE.md would apply it to every project you open.
“Personal project-specific preferences; add to .gitignore”Source: code.claude.com
Checkpoint 2 of 6· Exam question
A developer wants their project's CLAUDE.md to mention the path to a git workflow guide without pulling its contents into every session's context. They write `` `@docs/git-instructions.md` `` wrapped in backticks inside a paragraph. What happens when Claude Code parses this CLAUDE.md at session start?
Correct answer: A — Claude Code treats the backtick-wrapped path as literal text and skips the import, since import parsing skips code spans and fenced code blocks.
- A. Correct. Import parsing skips Markdown code spans and fenced code blocks, so wrapping a path in backticks keeps it as literal text instead of triggering an import.
- B. Incorrect. Code span skipping happens during import parsing itself, so the backticks do prevent the import rather than being processed afterward.
- C. Incorrect. A backticked reference is simply left as literal text; it does not cause a parse error or block loading the rest of the file.
- D. Incorrect. There is no partial-preview import behavior; backticked text is either imported in full (outside code spans) or left literal (inside them).
Sources1
2.Repository initialization with /init, and path-scoped rules
In a new repository you don't need to write CLAUDE.md from scratch. Run /init and Claude explores the codebase and drafts one, covering build and test commands, a structure overview and any conventions it detects. The draft is only a starting point: review it, delete anything inaccurate, then commit it so the team shares it.
Checkpoint 3 of 6· Put it in order
Put the repository initialization workflow in order
- 1.Commit the file
- 2.Type /init in the project
- 3.Review the draft and remove anything inaccurate
- 4.Claude explores the codebase and drafts a CLAUDE.md
/init produces a draft, and you check it before it becomes the shared project file.
“Review the draft, remove anything inaccurate, and commit it.”Source: support.claude.com
As the project grows, some instructions only matter for part of the code. Put those in Rules: markdown files under .claude/rules/. A rule with a paths frontmatter field loads only when Claude works with files that match its glob patterns, so API conventions don't take up context while Claude edits CSS. You can also keep personal rules in ~/.claude/rules/.
---
paths:
- "src/api/**/*.ts"
---
# API Development Rules
- All API endpoints must include input validation
- Use the standard error response format
- Include OpenAPI documentation commentsCheckpoint 4 of 6· Fill the gap
Which frontmatter field scopes this rule to matching files?
---
? :
- "src/**/*.{ts,tsx}"
- "lib/**/*.ts"
- "tests/**/*.test.ts"
---paths is the only field rules support. It takes glob patterns as a YAML list or a comma-separated string.
3.Agent memory: auto memory alongside CLAUDE.md
CLAUDE.md holds what you tell Claude. Auto memory holds what Claude learns: it writes its own notes when you correct it or confirm an approach that worked. The two systems differ in who writes them, what they hold and how much of them loads.
| Aspect | CLAUDE.md files | Auto memory |
|---|---|---|
| Who writes it | You | Claude |
| Contains | Instructions and rules | Learnings and patterns |
| Scope | Project, user, or org | Per repository, shared across worktrees |
| Loaded into | Every session | Every session (first 200 lines or 25KB) |
Memories are stored under ~/.claude/projects/<project>/memory/. A MEMORY.md index there points to one file per memory. Each memory has a type: user (your role and preferences), feedback (corrections and confirmed approaches), project (ongoing work and decisions that the code doesn't show), or reference (where to find outside information). You control it from settings: autoMemoryDirectory moves the folder, and autoMemoryEnabled turns the feature off.
{
"autoMemoryEnabled": false
}Checkpoint 5 of 6· Match them up
Match each auto memory type to what it records
Tap a term, then the definition that fits it.
These four types decide what auto memory saves and when it is recalled.
“feedback: corrections you give Claude and approaches you confirm”Source: code.claude.com
Sources1
4.settings.json scopes and precedence
CLAUDE.md tells Claude what to do. settings.json controls what Claude Code allows and how it is configured: permissions, hooks, plugins, environment variables and the model. Settings files have four scopes, like CLAUDE.md, but the local scope works differently in git.
| Scope | File | Use it for |
|---|---|---|
| User | ~/.claude/settings.json | Personal preferences across every project |
| Shared project | .claude/settings.json | Team permissions, hooks, plugins, env vars; commit it |
| Project local | .claude/settings.local.json | Personal overrides for one project; kept out of git |
| Managed | managed-settings.json and other managed sources | Organization security and compliance policy |
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(npm run lint)",
"Bash(npm run test *)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)"
]
}
}When the same key is set in more than one place, the highest scope wins. The order is managed settings, then command-line arguments, then project local, then shared project, then user. The --settings flag passes JSON for a single session and sits above all your own files. Nothing you set overrides a managed key. Claude Code creates .claude/settings.local.json itself the first time you give a standing approval on a permission prompt, and keeps it out of your commits. If ~/.claude.json can't be parsed, a -p run prints the error and exits.
Checkpoint 6 of 6· Put it in order
Order these sources from highest to lowest precedence for a key set in all three
- 1.Managed settings
- 2.~/.claude/settings.json
- 3.JSON passed with --settings
--settings overrides your user, project and local files, but it can't override a managed key.
“Claude Code applies it above your user, project, and local files and below managed settings.”Source: code.claude.com
Sources3
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Moving parts of a long CLAUDE.md into @imported files saves context.Why is that wrong?
Imported files also load at launch. They make the file easier to organize but cost the same context. To save context, use path-scoped rules.
Covered in The CLAUDE.md hierarchy
2.Everything auto memory has saved is loaded into each new session.Why is that wrong?
Only the start of the memory index loads at session start: the first 200 lines or 25KB.
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/memoryOfficial docs
“target under 200 lines per CLAUDE.md file. Longer files consume more context and reduce adherence.”
↩︎ The CLAUDE.md hierarchy“if two instructions contradict each other, Claude may pick one arbitrarily.”
↩︎ The CLAUDE.md hierarchy“a CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md in your working directory or any directory above it”
↩︎ The CLAUDE.md hierarchy“Run /context and check the list under Memory files to verify your CLAUDE.md and CLAUDE.local.md files loaded.”
↩︎ The CLAUDE.md hierarchy“Move instructions that matter for only part of the codebase into path-scoped rules, which load only when Claude works with matching files.”
↩︎ Repository initialization with /init, and path-scoped rules“notes Claude writes itself based on your corrections and preferences”
↩︎ Agent memory: auto memory alongside CLAUDE.md“Give Claude persistent instructions with CLAUDE.md or AGENTS.md files, and let Claude accumulate learnings automatically with auto memory.”
↩︎ Key concept“because imported files also load at launch.”
↩︎ Exam trap 1“Every session (first 200 lines or 25KB)”
↩︎ Exam trap 2“Personal project-specific preferences; add to .gitignore”
↩︎ Checkpoint“feedback: corrections you give Claude and approaches you confirm”
↩︎ Checkpoint - 2.https://support.claude.com/en/articles/14553240-give-claude-context-claude-md-and-better-promptsOfficial docs
“In any project, type /init. Claude will explore the codebase and draft a CLAUDE.md for you”
↩︎ Repository initialization with /init, and path-scoped rules“Review the draft, remove anything inaccurate, and commit it.”
↩︎ Checkpoint - 3.https://code.claude.com/docs/en/settingsOfficial docs
“Team permissions, hooks, plugins, and the environment variables the project needs”
↩︎ settings.json scopes and precedence“it takes a key you set here over the same key in local, project, or user settings”
↩︎ settings.json scopes and precedence“Claude Code applies it above your user, project, and local files and below managed settings.”
↩︎ Checkpoint