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/file imports to split long instructions, up to four hops deep.
  • Move narrow instructions into .claude/rules/*.md with a paths frontmatter list so they only load when matching files are in play.
  • Run /init to generate a first draft, /memory to edit files, and /context all to 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:

LevelPathCommitted to git?Typical use
Enterprise managedmanaged-settings.json in a system directory, MDM policy, or server-managed settingsDeployed by your adminSecurity policy, model allowlists, keys nobody can override
User~/.claude/settings.jsonNo, machine-localYour theme, default model, personal permission rules
Shared project.claude/settings.jsonYes, commit itTeam permissions, hooks, env vars the project needs
Project local.claude/settings.local.jsonNo, keep it out of gitYour 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:

  • permissions holds allow, ask and deny rule lists. Rules are Tool or Tool(specifier), for example Bash(npm run test *) or Read(./.env). Hooks accept the same syntax in their if field.
  • env sets 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.
  • model takes an alias such as opus, sonnet or haiku, 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.
  • hooks maps lifecycle events like PreToolUse, PostToolUse or SessionStart to 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.
  • statusLine points at a script that receives session JSON on stdin. "type": "command" plus a path is the whole configuration; /statusline can 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.

Sources