What you will be able to do
- Place an instruction in the correct CLAUDE.md scope (managed, user, project or local) and predict who will see it
- Predict whether Claude reads AGENTS.md, CLAUDE.md or both in a given repository
- Scope rules to specific file paths with .claude/rules/ and tell auto memory apart from CLAUDE.md
- Choose the right settings.json file and work out which value wins when several files set the same key
- Decide which Claude Code files to commit when setting up a repository for a team
Key concept
Layered configuration scopes — Almost everything that configures Claude Code (instructions, settings, skills, agents) can live at more than one scope: organisation-managed, personal (user), shared project, or personal-per-project (local). The scope a file sits in decides who receives it and which value wins when two files disagree.
1.The CLAUDE.md hierarchy
CLAUDE.md files are instructions you write to give Claude persistent context. They load into every session, so they suit coding standards, workflows and project architecture. Claude Code does not read just one CLAUDE.md. It looks for one at each of four scopes, and each scope reaches a different audience.
| Scope | Location | Shared with | Typical content |
|---|---|---|---|
| Managed policy | /Library/Application Support/ClaudeCode/CLAUDE.md (macOS), /etc/claude-code/CLAUDE.md (Linux and WSL), C:\Program Files\ClaudeCode\CLAUDE.md (Windows) | All users in organization | Company coding standards, security policies, compliance requirements |
| User instructions | ~/.claude/CLAUDE.md | Just you (all projects) | Code styling preferences, personal tooling shortcuts |
| Project instructions | ./CLAUDE.md or ./.claude/CLAUDE.md | Team members via source control | Project architecture, coding standards, common workflows |
| Local instructions | ./CLAUDE.local.md | Just you (current project) | Your sandbox URLs, preferred test data |
IT or DevOps deploys the managed file with configuration management, and it carries organization-wide instructions. The local file is for personal project preferences, and the docs tell you to add it to .gitignore. Specific instructions work better than vague ones: write "Run npm test before committing" rather than "Test your changes". A CLAUDE.md can also pull in other files with @path imports, so a short CLAUDE.md can point to the README, package.json or a separate instructions file.
See @README for project overview and @package.json for available npm commands for this project.
# Additional Instructions
- git workflow @docs/git-instructions.mdSources1
2.AGENTS.md and path-scoped rules
Claude Code can also read a repository's AGENTS.md. By default it reads one or the other, not both. If a CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md exists in the working directory or any directory above it, Claude reads the CLAUDE.md files and skips AGENTS.md. Three kinds of file don't count toward that switch and keep loading alongside AGENTS.md: your ~/.claude/CLAUDE.md, the managed CLAUDE.md, and .claude/rules/ files. A CLAUDE.md that imports AGENTS.md gets both, through the import. AGENTS.local.md, AGENTS.override.md and anything under .agents/ are never read.
| Value | What Claude reads |
|---|---|
| claude-md-or-agents-md (default) | CLAUDE.md files, or AGENTS.md files when there is no CLAUDE.md or CLAUDE.local.md in the working directory or above it |
| claude-md-and-agents-md | Both, with each directory's CLAUDE.md files first and its AGENTS.md after them |
| claude-md | CLAUDE.md files only |
| managed-only | Only the managed CLAUDE.md and auto memory at launch |
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).
Rules are the modular form of project instructions. You split guidance into files under .claude/rules/, such as code-style.md, testing.md and security.md. A rule can use a paths frontmatter field to apply only to matching files. Personal rules live in ~/.claude/rules/, and a shared rule set can be symlinked into .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 commentsSources1
3.Agent memory: what Claude writes for itself
Everything so far is written by you. Auto memory is the counterpart that Claude writes: it takes notes from your corrections and preferences and loads them into later sessions. Use CLAUDE.md for rules the team agrees on. Auto memory captures things such as a correction you would otherwise have to repeat next session.
| Aspect | CLAUDE.md files | Auto memory |
|---|---|---|
| Who writes it | You | Claude |
| What it 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) |
No. Each session loads only the first 200 lines or 25KB of auto memory. CLAUDE.md files load in full into every session.
Sources1
4.settings.json: four files and an order of precedence
CLAUDE.md shapes what Claude is told. settings.json configures how Claude Code itself behaves: permissions, hooks, plugins, environment variables and the model. It uses the same scope pattern as CLAUDE.md.
| Scope | File | Who it affects | Use it for |
|---|---|---|---|
| User | ~/.claude/settings.json | You, in every project on this machine | Theme, editor mode, default model, your own permission rules |
| Shared project | .claude/settings.json | Everyone working in the folder, once committed | Team permissions, hooks, plugins, environment variables |
| Project local | .claude/settings.local.json | You, in this one project only | Personal overrides, testing before you share |
| Managed | managed-settings.json and other managed sources | Everyone your organization deploys it to | Security policy and compliance requirements |
{
"$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 several levels set the same key, precedence from highest to lowest is: managed settings, then command-line arguments (including JSON passed with --settings), then project local, then shared project, then user. The merge works key by key. A higher level wins for the keys it sets, and lower-level values survive for the keys it leaves out. Nothing you set overrides managed settings. A flag such as --model can only pick from the models your organization allows. Some settings can also change mid-session: /model switches the model and /effort changes effort.
Sources2
5.Setting up a repository for Claude Code
The sources for this lesson do not describe a dedicated initialization command, so this section covers what they do say: which files make up a repository's shared Claude Code setup and which stay personal. The shared layer is ./CLAUDE.md (or .claude/CLAUDE.md), .claude/rules/, .claude/settings.json, .claude/skills/ and .claude/agents/. Teammates only get these once they are committed. Until then a file is just something on your disk.
Claude Code creates some personal files for you. The first time you change a /config option that it stores in user settings, it writes ~/.claude/settings.json. The first time you answer "Yes, and don't ask again" to a permission prompt, it writes .claude/settings.local.json. When it creates that local file, it also adds **/.claude/settings.local.json to your global git excludes. If you create the file by hand, you have to add it to .gitignore yourself. While the local file stays untracked, its allow rules apply without the workspace trust step that the committed file needs.
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.CLAUDE.local.md is the project file your team shares through source control.Why is that wrong?
./CLAUDE.md is the shared project file. CLAUDE.local.md holds your personal preferences for one project, and the docs say to keep it out of git.
Covered in The CLAUDE.md hierarchy
2.A repository with both AGENTS.md and CLAUDE.md gives Claude both files by default.Why is that wrong?
Under the default setting, a CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above it makes Claude read the CLAUDE.md files instead of AGENTS.md. Your user CLAUDE.md does not trigger this switch.
Covered in AGENTS.md and path-scoped rules
3.Passing a key with --settings at launch overrides whatever the organization has set.Why is that wrong?
--settings ranks above user, project and local files but below managed settings, so a managed key still wins.
Covered in settings.json: four files and an order of precedence
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
“Organization-wide instructions managed by IT/DevOps”
↩︎ The CLAUDE.md hierarchy“Personal project-specific preferences; add to .gitignore”
↩︎ The CLAUDE.md hierarchy“Your CLAUDE.md files, or your AGENTS.md files when you have no CLAUDE.md or CLAUDE.local.md in your working directory or above it”
↩︎ AGENTS.md and path-scoped rules“Glob patterns that scope the rule to matching files. Accepts a YAML list or a comma-separated string”
↩︎ AGENTS.md and path-scoped rules“notes Claude writes itself based on your corrections and preferences”
↩︎ Agent memory: what Claude writes for itself“Personal project-specific preferences; add to .gitignore”
↩︎ Exam trap 1“Count, so Claude reads them instead of AGENTS.md: a CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md in your working directory or any directory above it”
↩︎ Exam trap 2 - 2.https://code.claude.com/docs/en/settingsOfficial docs
“Claude Code applies it above your user, project, and local files and below managed settings.”
↩︎ settings.json: four files and an order of precedence“nothing you set overrides it, apart from a few security-sensitive exceptions”
↩︎ settings.json: four files and an order of precedence“In a git repository, commit it so teammates get it”
↩︎ Setting up a repository for Claude Code“Everyone working in the folder that contains it. In a git repository, commit it so teammates get it”
↩︎ Key concept“a key you pass with --settings doesn’t override the same managed key”
↩︎ Exam trap 3 - 3.https://code.claude.com/docs/en/skillsOfficial docs
“Sessions in this repository. Commit it so your team gets it too”
↩︎ Setting up a repository for Claude Code