Effective settings across five scopes
Merge five sample settings files (managed, --settings, local, project and user) the way Claude Code does, with the source of every value, the documented exceptions, and a verdict for sample tool calls under the merged rules. It's the worked example for the Settings topic: files and precedence, permission rules, and the mode a session starts in.
- Python 3.9+
- standard library only
- offline: the files in
core-2/samples/settings/
python3 core-2/settings_resolver.py
The sample files are written so that every documented exception shows up once. The working directory (/work/acme-app) and home (/home/learner) are virtual, and the resolver never reads your own ~/.claude/settings.json unless you pass it with --user.
┌─────────────────────────────────────────────────────────┐
│ Settings resolver · interactive session, folder trusted │
└─────────────────────────────────────────────────────────┘
[1] Files, highest precedence first [https://code.claude.com/docs/en/settings#settings-precedence]
level plays the role of leaf keys sample file
────────────── ───────────────────────────────────────────────────────────── ───────── ────────────────────────────────────────────────────────
Managed /Library/Application Support/ClaudeCode/managed-settings.json 8 core-2/samples/settings/managed/managed-settings.json
--settings /work/acme-app/ci/cli-settings.json 3 core-2/samples/settings/repo/ci/cli-settings.json
Project local /work/acme-app/.claude/settings.local.json 3 core-2/samples/settings/repo/.claude/settings.local.json
Shared project /work/acme-app/.claude/settings.json 17 core-2/samples/settings/repo/.claude/settings.json
User /home/learner/.claude/settings.json 9 core-2/samples/settings/home/.claude/settings.json
working directory /work/acme-app, home /home/learner (virtual, so the output is the same on every machine)
[2] Effective values (scalars: the highest level that sets the key wins)
key value from shadowed note
──────────────────────────────────────── ─────────────────── ────────────── ──────────────────────────────── ──────────────────────────────────────────────
disableClaudeAiConnectors true Shared project Managed=false stricter value honored: true from any scope
env.CLAUDE_CODE_ENABLE_TELEMETRY 1 Managed -
env.DISABLE_AUTO_COMPACT 0 User -
env.MCP_TIMEOUT 20000 Project local Shared project=10000, User=5000
env.OTEL_METRICS_EXPORTER otlp Managed -
fallbackModel ["sonnet", "haiku"] Shared project User=["haiku"] taken whole from the highest file that sets it
model haiku --settings Shared project=sonnet, User=opus
permissions.disableBypassPermissionsMode disable Managed -
spinnerTipsEnabled false Project local Shared project=true, User=false
useAutoModeDuringPlan true Managed -
[3] Merged lists (each entry keeps its source) [https://code.claude.com/docs/en/settings#lists-merge-instead-of-overriding]
autoMode.environment
$defaults User
Source control: github.com/acme-corp and all its repos User
built-in environment rules: kept, spliced in where "$defaults" sits
autoMode.soft_deny
$defaults --settings
Never touch the production database --settings
built-in soft_deny rules: kept, spliced in where "$defaults" sits
availableModels
opus Managed
sonnet Managed
haiku Managed
hooks.PostToolUse
{"matcher": "Edit|Write", "hooks": [{"type": "command", "command": "\… Shared project
hooks.PreToolUse
{"matcher": "Bash", "hooks": [{"type": "command", "command": "/opt/ac… Managed
permissions.additionalDirectories
../shared-docs/ Shared project
permissions.allow
Bash(git push *) Project local
Bash(npm run *) Shared project
Bash(python3 -m unittest *) Shared project
Edit(/src/**) Shared project
Bash(git status) User
Read(/notes/**) User
permissions.ask
Bash(git push *) Shared project
permissions.deny
Bash(curl *) Managed
Read(//etc/ssl/private/**) Managed
WebFetch --settings
Read(./.env) Shared project
Read(./secrets/**) Shared project
Read(~/.ssh/**) User
[4] Ignored or overridden by a rule (why each value doesn't apply)
- Shared project $schema = https://json.schemastore.org/claude-cod…
editor hint for JSON validation, not a setting [https://code.claude.com/docs/en/settings]
- Shared project allowManagedHooksOnly = false
scope is Managed only; a Shared project file can't set it [https://code.claude.com/docs/en/settings-reference#settings-index]
- Shared project autoMode.allow = ["Anything this repository asks for is …
scope is User or managed only; a Shared project file can't set it [https://code.claude.com/docs/en/settings-reference#settings-index]
- Shared project env.CLAUDE_CONFIG_DIR = /tmp/somewhere-else
a repository's settings can't set this variable; use your shell, user or managed settings [https://code.claude.com/docs/en/settings-reference#variables-claude-code-ignores-in-env]
- Shared project modelPicker = {"options": [{"model": "haiku", "label"…
scope is User or managed only; a Shared project file can't set it [https://code.claude.com/docs/en/settings-reference#settings-index]
- Shared project permissions.defaultMode = bypassPermissions
`bypassPermissions` doesn't take effect from project or local settings, and the session starts in Manual mode (v2.1.257+; earlier versions honored it from any file); set it in ~/.claude/settings.json or pass --permission-mode [https://code.claude.com/docs/en/permission-modes#which-mode-a-session-starts-in]
- User permissions.defaultMode = acceptEdits
not used: the Shared project file's `bypassPermissions` doesn't take effect and lower files don't fill in for it, so the session starts in Manual mode (`default`) [https://code.claude.com/docs/en/permission-modes#which-mode-a-session-starts-in]
- Shared project useAutoModeDuringPlan = false
scope is User, local, or managed only; a Shared project file can't set it [https://code.claude.com/docs/en/settings-reference#settings-index]
[5] Effective permissions [https://code.claude.com/docs/en/permissions#settings-precedence]
start mode: default (the Shared project file sets bypassPermissions, which doesn't take effect there: the session starts in Manual mode, not in the user file's mode)
deny: Bash(curl *) [Managed], Read(//etc/ssl/private/**) [Managed], WebFetch [--settings], Read(./.env) [Shared project], Read(./secrets/**) [Shared project], Read(~/.ssh/**) [User]
ask: Bash(git push *) [Shared project]
allow: Bash(git push *) [Project local], Bash(npm run *) [Shared project], Bash(python3 -m unittest *) [Shared project], Edit(/src/**) [Shared project], Bash(git status) [User], Read(/notes/**) [User]
additionalDirectories: ../shared-docs/ [Shared project]
Rules are evaluated deny -> ask -> allow; the first match wins, and specificity doesn't change the order.
[6] Hooks that would run
PostToolUse matcher='Edit|Write' "$CLAUDE_PROJECT_DIR"/.claude/hooks/format.sh [Shared project] -> runs
PreToolUse matcher='Bash' /opt/acme/claude-guard.sh [Managed] -> runs
Hooks merge across files. One run with them off: --settings '{"disableAllHooks": true}' [https://code.claude.com/docs/en/settings-reference#disableallhooks]
[7] Tool calls in mode default
call outcome decided by why
──────────────────────────────────── ─────── ─────────────────────────── ───────────────────────────────────────────────────────────
Bash: npm run test allow allow rule / read-only 'npm run test' by Bash(npm run *)
Bash: python3 -m unittest -v allow allow rule / read-only 'python3 -m unittest -v' by Bash(python3 -m unittest *)
Bash: git push origin main prompt ask rule (Shared project) matches Bash(git push *); no mode auto-approves an ask rule
Bash: curl https://example.com deny deny rule (Managed) matches Bash(curl *)
Bash: rm -rf build prompt mode shell commands outside the read-only set ask
Read: .env deny deny rule (Shared project) matches Read(./.env)
Read: ~/.ssh/id_ed25519 deny deny rule (User) matches Read(~/.ssh/**)
Read: ~/.claude/notes/todo.md allow allow rule (User) matches Read(/notes/**)
Read: ~/notes/todo.md prompt mode reads outside the working directories ask
Edit: src/app.ts allow allow rule (Shared project) matches Edit(/src/**)
WebFetch: https://docs.python.org/3/ deny deny rule (--settings) matches WebFetch
Verify in a real session: /status lists the setting sources it loaded; `claude doctor` lists what it rejected.
- Most scalars come from the highest file that sets them, but a few security keys honor the stricter value from any scope: the project's
truebeats managed'sfalse. - The
--settingsfile winsmodel. The project'ssonnetand youropusare listed as shadowed, so you can see what lost and where. - A repository can't start you in bypassPermissions: from project or local settings it doesn't take effect (v2.1.257+). Use your user file or
--permission-mode. - The session starts in Manual (
default), not in your user file'sacceptEdits: lower files don't fill in for an ignored value. - Your local allow for
git pushloses to the project's ask rule. Rules evaluate deny, then ask, then allow, whichever file they come from. - A
/pathrule in user settings anchors at~/.claude, soRead(/notes/**)covers~/.claude/notes, not~/notes. Write~/notes/**or//home/…for that.
The same files for a claude -p run in that repository, in a folder you never trusted. A -p run never shows the workspace-trust dialog:
┌─────────────────────────────────────────────────────────┐
│ Settings resolver · claude -p in a folder never trusted │
└─────────────────────────────────────────────────────────┘
…
- Shared project permissions.additionalDirectories = ["../shared-docs/"]
claude -p never shows the trust dialog, so in a folder you never trusted these aren't used (stderr: `this workspace has not been trusted`) [https://code.claude.com/docs/en/permissions#what-runs-before-you-trust-a-folder]
- Shared project permissions.allow = ["Bash(npm run *)", "Bash(python3 -m un…
claude -p never shows the trust dialog, so in a folder you never trusted these aren't used (stderr: `this workspace has not been trusted`) [https://code.claude.com/docs/en/permissions#what-runs-before-you-trust-a-folder]
…
[5] Effective permissions [https://code.claude.com/docs/en/permissions#settings-precedence]
start mode: default (the Shared project file sets bypassPermissions, which doesn't take effect there: the session starts in Manual mode, not in the user file's mode)
deny: Bash(curl *) [Managed], Read(//etc/ssl/private/**) [Managed], WebFetch [--settings], Read(./.env) [Shared project], Read(./secrets/**) [Shared project], Read(~/.ssh/**) [User]
ask: Bash(git push *) [Shared project]
allow: Bash(git push *) [Project local], Bash(git status) [User], Read(/notes/**) [User]
additionalDirectories: (none)
…
[6] Hooks that would run
PostToolUse matcher='Edit|Write' "$CLAUDE_PROJECT_DIR"/.claude/hooks/format.sh [Shared project] -> runs, even though -p never asked you to trust this folder
PreToolUse matcher='Bash' /opt/acme/claude-guard.sh [Managed] -> runs
…
[7] Tool calls in mode default (claude -p: a call that needs approval is denied)
call outcome decided by why
──────────────────────────────────── ─────── ────────────────────────── ────────────────────────────────────────────────────────────────────────────
Bash: npm run test deny mode shell commands outside the read-only set ask (headless: no one to ask, so d…
Bash: python3 -m unittest -v deny mode shell commands outside the read-only set ask (headless: no one to ask, so d…
Bash: git push origin main deny ask rule (Shared project) matches Bash(git push *); no mode auto-approves an ask rule (headless: no o…
Bash: curl https://example.com deny deny rule (Managed) matches Bash(curl *)
Bash: rm -rf build deny mode shell commands outside the read-only set ask (headless: no one to ask, so d…
Read: .env deny deny rule (Shared project) matches Read(./.env)
Read: ~/.ssh/id_ed25519 deny deny rule (User) matches Read(~/.ssh/**)
Read: ~/.claude/notes/todo.md allow allow rule (User) matches Read(/notes/**)
Read: ~/notes/todo.md deny mode reads outside the working directories ask (headless: no one to ask, so deni…
Edit: src/app.ts deny mode default asks before file edits (headless: no one to ask, so denied)
WebFetch: https://docs.python.org/3/ deny deny rule (--settings) matches WebFetch
The repository's permissions.allow rules weren't used in this -p run [https://code.claude.com/docs/en/permissions#what-runs-before-you-trust-a-folder]
…
- In a folder you never trusted, the project's allow rules aren't used:
-pnever shows the trust dialog, so it can't ask. - Its hooks still run. That's why the labs' real runs pass
--settings '{"disableAllHooks": true}'. - Without
Bash(npm run *)the test command would prompt, and with no one to ask it's denied. - User settings don't wait for trust, so your own rules still apply.
- If a headless run needs a command, pass it with
--allowedToolsrather than relying on the repository's file.
--permission-mode default --call "Bash: npm run lint": one call, allowed by the project'sBash(npm run *).--session interactive-untrusted --local-tracked: before you accept the trust dialog, the project's allow rules andadditionalDirectorieswait, and asettings.local.jsontracked in git waits with them; hooks still run.--disallowed-tools "Bash(rm *)" --allowed-tools Bash: the flag'sBashallows every command, butrm -rf buildis denied by the flag's deny rule andgit pushstill prompts on the project's ask rule.--self-testasserts 15 start-mode cases (one marked as a lab assumption), fromproject bypassPermissions over user acceptEdits -> Manualtonothing set, interactive -> auto (v2.1.283+).--jsonalso writes the merged result tocore-2/out/effective-settings.json.- Break it:
--project core-2/samples/settings/broken/settings-with-comment.jsonexits 2: settings files are strict JSON, so a//comment is a syntax error.
- Precedence answers "which value", but the exceptions decide most surprises: stricter-value keys, keys a repository can't set, and modes a repository can't start you in.
- Rules from every file merge into one list, and deny, then ask, then allow decides. The file a rule sits in doesn't make it stronger.
- In a real session,
/statuslists the setting sources that loaded.
A CLAUDE.md linter
Lint an instruction stack the way the docs describe it: resolve @ imports (relative to the importing file, four hops at most, never inside quotes or code), total what loads, and flag files over 200 lines, vague rules, emphasis on too many lines, content Claude can derive, procedures that want to be skills, and must-rules, each with the hook or deny rule that would enforce it. It's the check for the Memory topic.
- Python 3.9+
- standard library only
- offline: the good and bloated samples in
core-2/samples/claudemd/
python3 core-2/claudemd_lint.py
Token counts are the lab's estimate, characters divided by 2.5 (the course-wide ratio) with block HTML comments removed. Use /context for real numbers.
┌──────────────────────────────────────────────────────────────────────┐
│ CLAUDE.md lint · good sample: core-2/samples/claudemd/good/CLAUDE.md │
└──────────────────────────────────────────────────────────────────────┘
loads at launch hop imported by lines tokens (est.)
──────────────────────────────────────────── ─── ────────────────────────────────────── ───── ─────────────
core-2/samples/claudemd/good/CLAUDE.md 0 - 34 ~475
core-2/samples/claudemd/good/docs/testing.md 1 core-2/samples/claudemd/good/CLAUDE.md 5 ~100
context at launch: 39 lines, ~575 tokens (chars/2.5 estimate; imports don't reduce it)
INFO L007 core-2/samples/claudemd/good/CLAUDE.md:5 1 line(s) of block HTML comments are stripped before injection
-> Fine for maintainer notes: they cost no context (comments inside code blocks are kept)
https://code.claude.com/docs/en/memory#how-claude-md-files-load
┌────────────────────────────────────────────────────────────────────────────┐
│ CLAUDE.md lint · bloated sample: core-2/samples/claudemd/bloated/CLAUDE.md │
└────────────────────────────────────────────────────────────────────────────┘
loads at launch hop imported by lines tokens (est.)
──────────────────────────────────────────────────── ─── ──────────────────────────────────────────────────── ───── ─────────────
core-2/samples/claudemd/bloated/CLAUDE.md 0 - 212 ~2,529
core-2/samples/claudemd/bloated/docs/style.md 1 core-2/samples/claudemd/bloated/CLAUDE.md 4 ~26
core-2/samples/claudemd/bloated/Design Docs/api.md 1 core-2/samples/claudemd/bloated/CLAUDE.md 3 ~22
core-2/samples/claudemd/bloated/docs/chain/level1.md 2 core-2/samples/claudemd/bloated/docs/style.md 3 ~16
core-2/samples/claudemd/bloated/docs/chain/level2.md 3 core-2/samples/claudemd/bloated/docs/chain/level1.md 3 ~16
core-2/samples/claudemd/bloated/docs/chain/level3.md 4 core-2/samples/claudemd/bloated/docs/chain/level2.md 3 ~16
context at launch: 228 lines, ~2,625 tokens (chars/2.5 estimate; imports don't reduce it)
WARN L004 core-2/samples/claudemd/bloated/CLAUDE.md:3 emphasis (IMPORTANT/MUST/NEVER/ALWAYS/CRITICAL) on 7 lines: 3, 17, 18, 20, 21, 211, 212
-> Current models "follow a plainly worded line, and piling on emphasis mostly makes Claude over-apply the rule": write the lines plainly, and enforce the hard ones with hooks or deny rules
https://code.claude.com/docs/en/best-practices#what-you-can-stop-doing
…
WARN L005 core-2/samples/claudemd/bloated/CLAUDE.md:20 must-rule in prose (file Claude must never read or change); CLAUDE.md is context, not enforcement
-> Enforce it with permissions.deny: ["Read(./.env)", "Read(./secrets/**)"] (a Read deny also blocks Edit and Write on the path)
https://code.claude.com/docs/en/permissions#read-and-edit
WARN L005 core-2/samples/claudemd/bloated/CLAUDE.md:21 must-rule in prose (step that must run before Claude stops); CLAUDE.md is context, not enforcement
-> Gate it in CI, or with a PreToolUse hook on Bash(git commit *) that runs the tests and exits 2 when they fail. A Stop hook is only a nudge: with the stop_hook_active guard it blocks once and lets Claude stop on the next attempt, and a crashing Stop hook fails open (onFailure has no effect on Stop)
https://code.claude.com/docs/en/hooks#stop-decision-control
WARN L005 core-2/samples/claudemd/bloated/CLAUDE.md:22 must-rule in prose (action that must follow every edit); CLAUDE.md is context, not enforcement
-> Enforce it with a PostToolUse hook with matcher "Edit|Write" that runs the formatter on tool_input.file_path
https://code.claude.com/docs/en/hooks-guide#auto-format-code-after-edits
…
ERROR L009 core-2/samples/claudemd/bloated/CLAUDE.md:29 relies on .claudeignore, which has no effect in Claude Code
-> Move its entries into Read deny rules, e.g. permissions.deny: ["Read(./secrets/**)"]
https://code.claude.com/docs/en/permissions#read-and-edit
ERROR L002 core-2/samples/claudemd/bloated/CLAUDE.md:36 @docs/old-notes.md doesn't exist, so nothing is imported
-> Fix the path: it's relative to the file that contains the import
https://code.claude.com/docs/en/memory#import-additional-files
ERROR L002 core-2/samples/claudemd/bloated/CLAUDE.md:37 "@docs/release-checklist.md" is in quotes, so it isn't imported at all
-> Drop the quotes (escape spaces as `\ `), or wrap it in backticks to keep it literal
https://code.claude.com/docs/en/memory#import-additional-files
…
ERROR L002 core-2/samples/claudemd/bloated/docs/chain/level3.md:3 @level4.md would be hop 5; imports stop at four hops, so it never loads
-> Flatten the chain, or import the deep file from a shallower one
https://code.claude.com/docs/en/memory#import-additional-files
…
[summary]
file lines loaded tokens (est.) errors warnings info
───────────────────────────────────────── ──────────── ───────────── ────── ──────── ────
core-2/samples/claudemd/good/CLAUDE.md 39 ~575 0 0 1
core-2/samples/claudemd/bloated/CLAUDE.md 228 ~2,625 4 26 4
Check in a real session: /context lists the memory files that loaded; /doctor proposes trims.
- The good sample passes. Its maintainer comment is a block HTML comment, stripped before injection, so it costs no context.
- The bloated file plus its imports: 228 lines at launch. Imports organize a file but don't reduce what it costs, because they load with the file that imports them.
- "Never read
.env" in prose is context, not enforcement. The linter names the deny rule that makes it true. - A "run the tests before you stop" rule: gate it in CI or a PreToolUse hook. A Stop hook guarded by
stop_hook_activeblocks once, and a crashing one fails open. - An error, not a warning:
.claudeignorehas no effect in Claude Code, so the rule it implies doesn't exist. Move its entries intoReaddeny rules. - Two imports that never load: a path in quotes isn't an import, and
@level4.mdwould be hop 5.
--path core-2/samples/claudemd/good/CLAUDE.md --strictexits 0; that's the CI form.- Break it:
--path core-2/samples/claudemd/bloated/CLAUDE.md --strictexits 1 on the bloated sample's 4 errors. --repo common/samples/tiny-applints the sample repo the other labs use: 27 lines,no findings.- Point
--repoat your own repository. It readsCLAUDE.md,.claude/CLAUDE.md,CLAUDE.local.mdandAGENTS.mdat the root, plus what they import.
- Every must-rule in prose is a request. If breaking it would hurt, it belongs in a deny rule, a hook or CI.
- The cost at launch is the file plus every import it reaches within four hops. The docs' target is under 200 lines per file.
- Layout trees, dependency lists and file-by-file tours are content Claude derives itself;
/doctorproposes cutting them.
Which rules load for a path
Resolve a sample project's .claude/rules/ and a sample home's ~/.claude/rules/: what loads at launch, in context order, and which path-scoped rules each file Claude touches pulls in. It covers the glob edge cases of the Memory topic's path-scoped rules: brace expansion and its budget, bracket expressions, comma-separated paths, and frontmatter that doesn't parse.
- Python 3.9+
- standard library only
- offline:
core-2/samples/rules-project/andrules-home/
python3 core-2/rules_match.py
┌────────────────────────────────────────────────────────────┐
│ Rules loader · sample project core-2/samples/rules-project │
└────────────────────────────────────────────────────────────┘
[1] Rule files found (user rules load before project rules) [https://code.claude.com/docs/en/memory#organize-rules-with-claude/rules/]
scope file loads paths
─────── ──────────────────────────────────── ─────────── ────────────────────────────────────────────────────────────
user ~/.claude/rules/preferences.md at launch -
user ~/.claude/rules/python.md path-scoped **/*.py
project .claude/rules/api.md path-scoped src/api/**/*.{ts,tsx}
project .claude/rules/assets.md path-scoped assets/photos [2024/**, assets/*.svg
project .claude/rules/broken.md at launch -
project .claude/rules/code-style.md at launch -
project .claude/rules/docs.md path-scoped *.md, docs/**/*.md
project .claude/rules/frontend/components.md path-scoped src/components/*.tsx
project .claude/rules/generated.md path-scoped {a,b,c,d,e,f}/{a,b,c,d,e,f}/{a,b,c,d,e,f}/{a,b,c,d,e,f}/*.p…
project .claude/rules/infra.md path-scoped infra/**
project .claude/rules/testing.md path-scoped tests/**/*.py, **/test_*.py
note .claude/rules/assets.md: 'assets/photos [2024/**': invalid: 'assets/photos [2024/**': '[' starts a bracket expression that never closes; it matches nothing (the rule's other patterns keep working)
note .claude/rules/broken.md: frontmatter doesn't parse (line 2: unclosed [); ignored, so the rule loads at launch
note .claude/rules/generated.md: '{a,b,c,d,e,f}/{a,b,c,d,e,f}/{a,b,c,d,e,f}/{a,b,c,d,e,f}/*.py': 1,296 expansions would exceed the 1,000-pattern budget: used unexpanded, so its literal braces match no file
note .claude/rules/infra.md: field(s) owner ignored: `paths` is the only field a rule reads
note packages/web/.claude/rules/: a nested .claude/rules/ directory. The docs say such rules load on demand but don't document how their paths anchor, so this lab lists them without matching.
[2] Loaded at launch, in context order
1. ~/.claude/rules/preferences.md no paths Personal preferences
2. .claude/rules/broken.md frontmatter error Release notes
3. .claude/rules/code-style.md no paths Code style
Same priority as .claude/CLAUDE.md; re-injected from disk after compaction.
[3] Path-scoped rules that load when Claude reads, writes or edits each file [https://code.claude.com/docs/en/memory#path-specific-rules]
file Claude touches rule that loads matching pattern
────────────────────────────── ──────────────────────────────────── ────────────────────────────────────────────
src/api/users.ts .claude/rules/api.md src/api/**/*.{ts,tsx} (as src/api/**/*.ts)
src/api/v2/orders.tsx .claude/rules/api.md src/api/**/*.{ts,tsx} (as src/api/**/*.tsx)
src/components/Button.tsx .claude/rules/frontend/components.md src/components/*.tsx
src/components/forms/Input.tsx nothing extra
tests/test_cart.py ~/.claude/rules/python.md **/*.py
.claude/rules/testing.md tests/**/*.py
tests/api/test_orders.py ~/.claude/rules/python.md **/*.py
.claude/rules/testing.md tests/**/*.py
README.md .claude/rules/docs.md *.md
web/README.md nothing extra
docs/guide/setup.md .claude/rules/docs.md docs/**/*.md
infra/terraform/main.tf .claude/rules/infra.md infra/**
assets/logo.svg .claude/rules/assets.md assets/*.svg
a/b/c/d/gen.py ~/.claude/rules/python.md **/*.py
lib/util.py ~/.claude/rules/python.md **/*.py
[4] What to remember
trigger: Read, Write or Edit on a matching file, or a Bash read such as cat/head of one file
compaction: rules without paths are re-injected; path-scoped rules reload only when a matching file is touched again [https://code.claude.com/docs/en/context-window#what-survives-compaction]
check it: /context lists what loaded; an InstructionsLoaded hook logs each load and its reason [https://code.claude.com/docs/en/hooks#instructionsloaded]
- Meant to be path-scoped, but its YAML doesn't parse, so Claude Code ignores the frontmatter and
broken.mdloads at launch for every file. - Four brace groups of six expand to 1,296 patterns, over the 1,000-pattern budget. The pattern is used unexpanded and matches nothing.
- An unclosed
[makes one pattern invalid, while the rule's other pattern,assets/*.svg, keeps working. src/components/*.tsxdoesn't reachforms/Input.tsx:*doesn't cross a/. Usesrc/components/**/*.tsx.*.mdmeans Markdown in the project root, soweb/README.mdgets nothing.- After compaction, unscoped rules come back from disk; a path-scoped rule returns only when Claude touches a matching file again.
--path src/api/v2/orders.tsx --show-expansions: one file, andapi.md's pattern printed after brace expansion (src/api/**/*.ts, src/api/**/*.tsx).--no-home --path tests/test_cart.py --path lib/util.py: without the sample home'spython.md,lib/util.pyloads nothing extra and the test file loads onlytesting.md.- Break it:
--path ../outside.pyisoutside the project: no rule matches; rules match only files under the project. --project ~/code/my-app --home ~ --path src/app.pyruns it on your repository and your real~/.claude/rules/, read-only. Without--home ~it never reads your home.
- A rule meant to be path-scoped that loads at launch is almost always a frontmatter error.
claude --debugshows the parse error. - Project patterns anchor at the folder that holds
.claude, and*stops at/. - In a real session,
/contextlists what loaded, and anInstructionsLoadedhook logs each load and its reason.