Updated: December 2, 2026.
Claude Code config has two layers, and most "my setting is ignored" bugs come from mixing them up. CLAUDE.md is prose Claude reads at the start of every session. settings.json is JSON the client enforces before Claude gets a vote. Conventions, build commands and project gotchas go in the first. Anything that has to hold even when the model has a bad day goes in the second.
I keep both in every repo I work in, and a year of debugging permission prompts that should not have appeared will give you opinions about which key goes where.
CLAUDE.md is memory, not a policy file
The official memory docs are blunt about this: Claude treats CLAUDE.md files as context, and they "aren't enforced configuration." So "never run migrations against prod" in CLAUDE.md is a request. A permissions.deny rule is a wall. If a mistake would cost you data, put the rule in settings and keep the explanation in CLAUDE.md for the human reading it.
Here is the skeleton I start from in a new repo, either at ./CLAUDE.md or ./.claude/CLAUDE.md:
# Project: acme-api
## Commands
- Install: `pnpm install`
- Dev: `pnpm dev` (port 3000)
- Test: `pnpm test -- --run`
- Lint: `pnpm lint`
- Typecheck: `pnpm tsc --noEmit`
## Conventions
- TypeScript strict, 2-space indent, no default exports
- API handlers live in `src/api/handlers/`
- Zod schemas own validation; handlers never validate inline
- Tests sit next to the file they cover: `foo.test.ts`
## Gotchas
- `pnpm dev` needs Postgres on 5432; `docker compose up -d db`
- Do not edit `src/generated/`; regenerate with `pnpm codegen`
- Migrations are append-only, never rewrite one that has shipped
## Workflow
- Run lint and typecheck before you say a task is done
- One commit per logical change, conventional commit messages
A few rules I follow, all of them from the docs:
- Keep it under 200 lines. Longer files eat context and Claude follows them less reliably.
- Use
@path/to/fileimports to split long instructions, up to four hops deep. - Move narrow instructions into
.claude/rules/*.mdwith apathsfrontmatter list so they only load when matching files are in play. - Run
/initto generate a first draft,/memoryto edit files, and/context allto confirm they loaded. The output lists your memory files; if a file is missing there, Claude cannot see it.
CLAUDE.md also loads from above your working directory and concatenates everything it finds, so a monorepo can inherit parent instructions you did not write. claudeMdExcludes in settings is the escape hatch, usually in .claude/settings.local.json.
The four settings files
Settings live in four places. The one you pick decides who the setting applies to, so pick carefully:
| Level | Path | Committed to git? | Typical use |
|---|---|---|---|
| Enterprise managed | managed-settings.json in a system directory, MDM policy, or server-managed settings | Deployed by your admin | Security policy, model allowlists, keys nobody can override |
| User | ~/.claude/settings.json | No, machine-local | Your theme, default model, personal permission rules |
| Shared project | .claude/settings.json | Yes, commit it | Team permissions, hooks, env vars the project needs |
| Project local | .claude/settings.local.json | No, keep it out of git | Your overrides for one project, plus approvals Claude Code saves for you |
Precedence runs highest to lowest: managed settings, then the command line (--settings), then project local, then shared project, then user. A key set higher up wins. The command line tier is the one people forget: claude --settings '{"model": "opus"}' overrides every file for that one session and writes nothing.
Three details matter in practice.
Lists merge instead of overriding. If your user file allows Bash(npm run lint) and the project file allows Bash(npm run test *), both apply. That is why a permission can feel like it comes from nowhere.
Environment variables are not a level in this stack. When a shell variable and a settings key do the same job, the docs decide the winner per pair, not by file precedence. ANTHROPIC_MODEL in your shell beats the model key in any file.
Project settings are read from your primary working directory, so start Claude Code at the repository root if the team file lives there. Run it from packages/api and you may be reading a different (or no) project file.
The .claude/ folder holds more than settings. agents/, skills/ and rules/ load as context, not enforcement, and they follow the same project-versus-user split. If you are defining reviewers or test writers there, the subagent guide covers the file format.
What goes inside settings.json
Five keys cover most real setups: permissions, env, model, hooks, statusLine. Here is a minimal file I would actually ship as .claude/settings.json:
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"model": "opus",
"permissions": {
"allow": [
"Bash(pnpm lint)",
"Bash(pnpm test *)",
"Bash(pnpm tsc --noEmit)"
],
"ask": [
"Bash(git push *)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)"
]
},
"env": {
"CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD": "1"
},
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/format.sh"
}
]
}
]
},
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh"
}
}
What each block does:
permissionsholdsallow,askanddenyrule lists. Rules areToolorTool(specifier), for exampleBash(npm run test *)orRead(./.env). Hooks accept the same syntax in theiriffield.envsets environment variables for every session started in that scope. Keys you would otherwise export in your shell belong here so they survive a new terminal.modeltakes an alias such asopus,sonnetorhaiku, or a full model ID. It is a starting selection, not a lock. Enforcement is a separate, managed-settings job (availableModels), which is worth knowing before you assume a project file pins the team to one model. If cost is the reason you are touching this key, routing to a cheaper model covers the provider side.hooksmaps lifecycle events likePreToolUse,PostToolUseorSessionStartto matcher groups and command handlers. The same block works from any of the four files, which is how a team can share a formatter hook without anyone installing it by hand.statusLinepoints at a script that receives session JSON on stdin."type": "command"plus a path is the whole configuration;/statuslinecan generate the script for you.
Settings files are strict JSON. No // comments, no trailing commas. A comment is a parse error and shows up as a Settings Error at the next start. The $schema line buys you autocomplete and validation in VS Code or Cursor; keep it.
Permissions evaluate deny, ask, allow
Rules are evaluated in one fixed order: deny, then ask, then allow. The first match wins, and specificity does not change the order. A broad Bash(aws *) in deny beats a narrow Bash(aws s3 ls) in allow.
Two consequences follow.
A bare tool name in deny, like Bash or Read, removes the tool from Claude's context entirely. A scoped rule like Bash(rm *) leaves the tool available and blocks matching calls when they happen. Use the scoped form unless you want the tool gone.
allow rules from a committed project file wait for workspace trust. Until a teammate trusts the folder, they still get prompts, and deny and ask rules apply immediately. That asymmetry explains a lot of "it works on my machine" reports. Open /permissions to see every rule and the file it came from, or /status to see which files loaded.
Mistakes I see in real repositories
Secrets in a committed settings file are the mistake with the highest bill. env values are plain text, and .claude/settings.json is meant to be committed. Tokens go in your shell environment or a credential helper, never in the shared file.
Conflicting user and project permissions waste a lot of afternoons. You add a local allow for a command, get prompted anyway, and blame the tool. The project file, or managed settings, has the same call under ask, and ask wins over allow. Check /permissions before editing anything.
Committing .claude/settings.local.json is common and easy to avoid. It holds your personal overrides and every "don't ask again" approval, which is noise for everyone else. Claude Code adds the file to your global git excludes the first time it writes it. If you created the file by hand, add **/.claude/settings.local.json to .gitignore yourself; the automatic exclude only happens on a write.
Treating CLAUDE.md as enforcement breaks the first time the model gets distracted. If a rule must hold, it belongs in permissions or a PreToolUse hook. CLAUDE.md shapes behavior, and the docs say so directly.
Skipping the debug tools costs more time than reading about them. claude doctor lists rejected settings entries, and /status names every settings source that loaded.
FAQ
What is the difference between CLAUDE.md and settings.json in Claude Code?
CLAUDE.md is natural-language context Claude reads every session; it guides behavior but is not enforced. settings.json is machine config the client applies: permissions, environment variables, model, hooks, status line. If a rule has to hold regardless of what the model decides, it goes in settings.
Which Claude Code settings file wins when the same key appears twice?
Highest to lowest: managed settings, the --settings command line value, .claude/settings.local.json, .claude/settings.json, then ~/.claude/settings.json. List keys such as permissions.allow merge across files instead of replacing each other.
Should I commit .claude/settings.json?
Yes. That is the shared project layer: team permissions, hooks and project env vars. Keep personal overrides in .claude/settings.local.json and leave that file untracked.
Can I put comments in Claude Code settings.json?
No. Settings files are strict JSON, so // comments and trailing commas fail to parse. Add the $schema key for editor autocomplete instead, and use claude doctor to see what was rejected.
How do I stop Claude Code from reading .env files?
Add a deny rule: "deny": ["Read(./.env)", "Read(./.env.*)"]. A Read deny also blocks Edit and Write on the same path, so the file cannot be overwritten either.
How do I check which Claude Code config is actually loaded?
Run /status inside a session. The Setting sources line lists the files that loaded, including managed settings, and /permissions shows each rule with its source file. claude doctor lists entries the parser rejected.



