Your Claude Code settings.json, explained

settings.json is the rulebook Claude Code checks before it runs a command or reads a file. Learn what goes in it and why it matters, then set it up so Claude can move fast without touching your secrets.

Time: 25 minYou need: Claude Code installed and a project folder to try it in

The Claude logo above a settings.json card, with allow, ask and deny on one side and the user, project and local files on the other
Watch the whole idea in 49 seconds, then follow the steps below.

Understand it

What settings.json is

Before Claude Code runs a command, edits a file or reads something, it checks a rulebook. That rulebook is settings.json. Each rule says one of three things: go ahead, ask me first, or never.

Claude Code runs a command, settings.json checks its rules, and the answer is allow, ask or deny
Every action passes through your rules first.
  • allow: Claude does it without asking. Good for safe, boring commands like running your tests.
  • ask: Claude stops and asks you. Good for pushing code or merging.
  • deny: Claude cannot do it, even if you click yes out of habit. Good for secrets and anything destructive.

Without these rules you approve prompts all day, and nothing stops Claude from reading your .env file. With them, the safe things run on their own and the risky things wait for you.

WHAT YOU SHOULD SEEYou may not have a settings file yet. That is normal: Claude Code does not create one until you change a setting or approve a rule. Step 4 makes one.

Understand it

Know where the files live

There is not one settings file. There are four places, and each one decides who the rules apply to.

The four settings files: user, shared project, project local and managed, with their paths
Same format everywhere. Only the location, and who it affects, changes.
  • ~/.claude/settings.json is yours, in every project. Put personal habits here.
  • .claude/settings.json inside a project is shared with everyone who works there, once it is committed to git.
  • .claude/settings.local.json is yours, in that one project. Claude Code keeps it out of git.
  • Managed settings are set by an organization admin. Most people on their own have none.
WHAT YOU SHOULD SEENot sure which files you have? Run /status inside Claude Code. The Setting sources line lists every file it loaded.

Understand it

Know which file wins

When two files set the same thing, the higher one wins. From the top: managed, then the command line for one session, then project local, then shared project, then your user file.

Five settings levels from managed at the top to user at the bottom, higher wins
Higher beats lower. Lists are the exception: they combine.

Lists are the exception. The allow, ask and deny rules from every file are combined, so one file can add rules without removing another file's.

  • Put your personal habits in the user file.
  • Put team rules in the shared project file.
  • Put your own exceptions for one project in the local file.
GUARDRAILA shared project file beats your user file. If your team sets a model, you get theirs in that project until you override it in your local file.

Write the rules

Create your first file

Make the file by hand, or ask Claude Code to make it. Start small: a $schema line so your editor checks the file as you type, and an empty permissions block you will fill in over the next steps.

A settings.json file with permissions, model, env and hooks, each explained
You will mostly work in permissions. The other keys are there when you need them.
~/.claude/settings.json
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "allow": [],
    "ask": [],
    "deny": []
  }
}
  • Save it as ~/.claude/settings.json for rules that follow you into every project.
  • It must be strict JSON: no // comments and no trailing commas, or Claude Code reports a Settings Error.
  • Most edits apply to a running session, so you do not need to restart.
WHAT YOU SHOULD SEEOpen the file in VS Code or Cursor. The $schema line gives you autocomplete, and a wrong key gets a warning underline.

Write the rules

Allow only what you name

allow rules let a command run with no prompt, so keep them narrow. Name the exact command, not a whole tool.

Three allow rules from too wide to just right
A star matches anything after it, so every extra word you name makes the rule safer.
  • Good: Bash(npm run lint) and Bash(npm run test *).
  • Too wide: Bash(npm *) also allows npm publish.
  • Never: Bash(*). It hands Claude your whole shell.
  • Every time you pick “Yes, and don't ask again” on a prompt, Claude Code adds an allow rule to .claude/settings.local.json. They pile up, which is why step 11 audits them.
GUARDRAILA pattern like npm run test * may not match npm run test:unit, because of the colon. Give scripts with a colon their own rule.

Write the rules

Protect your secrets with deny

deny is your safety net. A deny rule beats any allow rule, so it still holds when your allow list grows. Start with the files that hold secrets.

Claude Code is blocked from .env files and the SSH and AWS folders, while .env.example stays readable
Block the real secret files. Leave the example file readable.
permissions.deny
"deny": [
  "Read(./.env)",
  "Read(./.env.local)",
  "Read(./.env.production)",
  "Read(~/.ssh/**)",
  "Read(~/.aws/**)"
]
  • List each real .env file by name.
  • Do not deny .env.example. It holds names only, and Claude needs it to know what a project expects.
  • A wide pattern like .env.* would block .env.example too, because deny beats allow.
GUARDRAILA path starting with ./ is relative to the folder you start Claude in, so .env files in subfolders need their own rules.

Write the rules

Ask before the risky things

Between allow and deny sits ask. Use it for actions you want to see before they happen, so you decide each time.

Allow, ask first and deny columns with example commands
Reading is fine. Pushing, merging and deleting should ask first or be denied.
  • Pushing code: Bash(git push *).
  • Merging: Bash(gh pr merge *).
  • Database changes, and anything that touches money or live data.
permissions.ask
"ask": [
  "Bash(git push *)",
  "Bash(gh pr merge *)"
]
WHAT YOU SHOULD SEEA prompt every time Claude tries to push or merge. Allow it once, or say no.

Check and keep it safe

Know what deny cannot catch

Rules match the text of a command, so a reworded command can slip past a rule written for the original. A deny rule for git push --force origin main does not match git push origin main --force.

A deny rule blocks one spelling of a force push but two reworded versions slip through, with a hook as backstop
Treat deny as a strong fence, not a vault.
  • Deny the dangerous flag, like Bash(git push --force *), instead of one exact command.
  • Write a rule for each common spelling of a command you really care about.
  • For a hard guarantee, add a PreToolUse hook: a small script that checks the real command before it runs and can refuse it.
GUARDRAILPut the one or two rules that must never break in a hook as well as in deny.

Check and keep it safe

Share the team file, keep yours local

Commit .claude/settings.json so everyone who clones the project gets the same rules. Keep your personal exceptions in .claude/settings.local.json, which Claude Code keeps out of git.

The shared settings.json is committed for teammates while settings.local.json stays on your machine
One file for the team, one for you.
  • If you create the local file by hand, add it to .gitignore yourself.
  • A teammate's allow rules from the shared file wait until they trust the folder. deny and ask rules apply right away.
  • Some keys, like defaultMode set to auto, only work from your user file, not from a project file.
WHAT YOU SHOULD SEEA new teammate clones the project and Claude Code already asks before a push. Nobody had to explain the rules.

Check and keep it safe

Check that it loaded

A typo can quietly drop a rule. Check after every edit.

Save the file, run /status to see loaded files, run claude doctor to see rejected keys
Two commands tell you what Claude Code actually read.
  • Run /status inside Claude Code. The Setting sources line lists each file it loaded.
  • Run claude doctor in your terminal to see any key or rule it rejected.
  • If a whole file is broken, Claude Code shows a Settings Error when a session starts and offers to fix it with you.
WHAT YOU SHOULD SEEYour user file appears under Setting sources, and claude doctor reports no rejected entries.

Check and keep it safe

Audit it with the free prompt

Rules drift. You approve things in a hurry, a teammate adds a key, a connector gets renamed. The free audit prompt reviews your own settings files and tells you what to fix, the way a careful reviewer would.

Paste the prompt, Claude reads your files, you get a ranked report, you approve each fix
You stay in charge of every change.
  • Paste it into Claude Code. Claude reads your settings files itself, on your computer. Nothing is uploaded.
  • It reports key names only, never secret values.
  • It ranks what it finds High, Medium and Low, with the exact fix for each.
  • It backs up the file and shows you a diff before any change, and changes nothing without your yes.
GUARDRAILKeep the backup until you have run a few sessions. Settings control what Claude may do, so you want a way back.

Get the free audit prompt and starter file

Paste the prompt into Claude Code and it reviews your own settings files and tells you what to fix. Next, see how to keep keys working everywhere in the environment variables guide.

  • Audit promptPaste into Claude Code. It checks your settings files and ranks what to fix.
  • Starter settings.jsonSafe defaults: secrets blocked, risky actions ask first.
Get the free audit prompt →