↓ Skip to main content

Claude Code AI Agents Security

Claude Code settings.local.json vs settings.json, Explained

settings.json is shared and settings.local.json is yours, and "Don't ask again" saves rules there, secrets included. Precedence, privacy, and how to check.

Claude Code settings.local.json vs settings.json, Explained

Claude Code reads its settings from four places. A project’s .claude/settings.json is shared: you commit it so everyone working on the repository gets the same permission rules, hooks and plugins. .claude/settings.local.json is yours alone for that project, and Claude Code keeps it out of git. ~/.claude/settings.json is yours in every project, and managed settings come from your organisation and beat all of them. When you answer a permission prompt with “Yes, and don’t ask again”, the new rule goes into settings.local.json, written exactly as the command was. If the command had a password in it, the password is now sitting in a plain JSON file.

That last part was news this month. On 5 November, Apiiro reported finding 1,122 settings.local.json files in public GitHub repositories that held a real secret, 1,379 distinct ones in total. GitGuardian’s numbers, reported by CSO, are bigger: 31,088 distinct secrets in these files across 23,276 public repositories, 5,343 of them still valid when found. The Hacker News thread was mostly people going to check their own repositories, so I did the same with every settings file on my laptop. The results are further down. First, what each file is for.

Which file is for what
#

FileWho it affectsCommit it?What I keep in it
~/.claude/settings.jsonYou, in every project on this machineNo, it isn’t in a projectDefault model, permission mode, hooks I want everywhere, privacy variables
.claude/settings.jsonEveryone who works in the projectYesThe team’s allow and deny rules, project hooks, plugins, the env the project needs
.claude/settings.local.jsonYou, in this project onlyNo, Claude Code keeps it out of gitPersonal overrides, and every “don’t ask again” approval
Managed settingsEveryone your organisation deploys them toNot yours to editSecurity policy

Claude Code also keeps ~/.claude.json, which holds your account details, MCP server configuration and per-project state such as which folders you’ve trusted. You don’t need to edit it, and it’s not a settings file in the sense above.

The local file is created the first time you give a standing approval. Choose “Yes, and don’t ask again” for a Bash command and Claude Code writes the rule into .claude/settings.local.json at the root of the git repository, even if you started the session in a subfolder.

Which one wins
#

When the same key is set in more than one place, the higher level wins:

  1. Managed settings
  2. --settings on the command line, for that session only
  3. .claude/settings.local.json
  4. .claude/settings.json
  5. ~/.claude/settings.json

So your local file beats the team’s file, and the team’s file beats your personal defaults. That’s the order for single values like model. Lists behave differently. permissions.allow, permissions.deny and the other list keys merge across all the files instead of the highest one replacing the rest, so every file can add rules and none can quietly delete another’s.

Permission rules then have their own order, which matters more than the file order. Claude Code checks deny rules first, then ask rules, then allow rules, and the first match decides. A deny rule anywhere beats an allow rule anywhere, and an allow rule can’t carve an exception out of a deny. The /permissions command shows every rule in effect and which file it came from, which is the quickest way to see what you’ve accumulated.

What “don’t ask again” actually saves
#

For a Bash command, the prompt offers to remember a prefix: “Yes, and don’t ask again for: npm test *”. Approve it and that rule lands in the local file. It’s permanent for that repository until you remove it.

The trouble is that the prefix is whatever came first in the command, and sometimes that includes a secret. Approve this:

PGPASSWORD='s3cret-example' pg_dump -h db.example.com -U app mydb > backup.sql

and the rule that gets saved is along these lines:

{
  "permissions": {
    "allow": [
      "Bash(PGPASSWORD='s3cret-example' pg_dump *)"
    ]
  }
}

The same goes for an API key in a curl header, a token passed as a flag, or a connection string with the password in it. Nothing about the prompt makes that obvious, because you’re looking at the command, not at the JSON it will turn into.

Two other details are worth knowing. Approving a compound command such as git status && npm test saves a separate rule for each part that needed approval, not one rule for the whole line. And “don’t ask again” for file edits isn’t permanent at all. It lasts until the end of the session.

Why “don’t ask again” sometimes doesn’t stick
#

If you approved something and Claude Code keeps asking, the usual cause is an ask rule somewhere else. Ask rules are checked before allow rules, so an ask rule in the project’s or your organisation’s settings prompts even though your local file allows the command.

The next most likely is that the command doesn’t match the saved prefix. npm test * doesn’t cover npx jest, and a rule for pnpm build doesn’t cover cd web && pnpm build unless cd web is allowed too, because every part of a compound command has to be allowed. If it was a file edit, the approval ended with the session. And sometimes the prompt never offered a standing approval in the first place: Claude Code only shows “don’t ask again” when the prompt can show everything the rule would allow, and otherwise you get a one-time yes.

People searching for how to “allow all” in settings.local.json will find that you can’t any more. bypassPermissions and auto as a defaultMode don’t take effect from project or local settings. Set them in ~/.claude/settings.json, or pass --permission-mode for one session. I wrote about which mode I use and why last month.

What I found on my own laptop
#

I wrote a short script to read every Claude Code settings file under my home folder and count, without printing the rules themselves:

  • 21 settings files across my projects and my home folder.
  • 395 allow rules, 9 deny rules and no ask rules. All nine deny rules are in one project, added this month, and they stop the agent editing its own settings and instructions.
  • 26 allow rules let through a whole interpreter or network tool, such as python3, curl, ssh or docker. As I said in the agent security post, an allowlist with an interpreter in it is an allow-all with extra steps.
  • 3 rules held a database password inline, two different passwords, all in my estimating app’s project. Two more rules matched the word “secret” but were only fly secrets list, which is why it’s worth reading what a grep finds rather than trusting the count.
  • Every settings.local.json inside a git repository was ignored by git, and none had ever been committed.

When I wrote that security post in October, I found and removed two rules with credentials in them. This check found three more. The approvals happen in the middle of real work, one click at a time, and the file is never somewhere you look. I’ve since moved both passwords into ~/.pgpass, and the rules now read Bash(pg_dump *).

The session logs are the other half. Claude Code keeps each session’s transcript in plain text under ~/.claude/projects/, for 30 days by default (cleanupPeriodDays changes that). A crude grep flagged 41 of the 210 transcripts on my laptop, but almost all of those were placeholders like password in example connection strings. With those excluded, 4 still held something that looks like a real credential: three database passwords and a GitHub token. That’s fewer than I feared. The logs don’t leave the machine on their own, but anything else running on it can read them.

Where the gitignore safeguard doesn’t reach
#

The first time Claude Code writes settings.local.json in a repository that doesn’t already ignore it, it adds **/.claude/settings.local.json to your global git excludes file, which is ~/.config/git/ignore unless you’ve set core.excludesFile. That’s why none of mine were committed. You can see which line is doing the ignoring:

$ git check-ignore -v .claude/settings.local.json
/Users/me/.config/git/ignore:1:**/.claude/settings.local.json	.claude/settings.local.json

But that line only affects git, and only on your machine. I tested two other ways a project folder leaves a laptop, in a throwaway folder with a fake password in the rule.

npm pack --dry-run (npm 11.6.2) listed .claude/settings.local.json in the package. npm reads a package’s own .gitignore or .npmignore, not your global excludes file, so a package published from that folder would have shipped the file.

docker build with COPY . /app copied it into the image too. Docker only reads .dockerignore. That one isn’t hypothetical: GitGuardian found 613 distinct secrets from Claude Code settings files in public Docker Hub images.

The other gaps are the ones the docs mention: a settings.local.json you created by hand doesn’t get the global excludes line until Claude Code writes to it, and git add -f adds it regardless. So I’d ignore it in the project as well:

# .gitignore and .dockerignore
.claude/settings.local.json

For an npm package, a files list in package.json is the safer fix, because it’s an allowlist and nothing outside it gets published.

How to check your own repositories
#

Find every settings file:

find ~ -path '*/.claude/settings*.json' -not -path '*/node_modules/*' 2>/dev/null

In each repository, check whether the local file is tracked now or was ever committed:

git ls-files -- '*.claude/settings.local.json'
git log --all --oneline -- '*.claude/settings.local.json'

And look for rules that carry a secret:

jq -r '.permissions.allow[]?' .claude/settings.local.json \
  | grep -Ei 'pass(word)?=|token|secret|api[_-]?key|bearer|://[^/@ ]+:[^/@ ]+@'

If anything turns up in a repository that’s public, or ever was, rotate the credential first. Removing the file from the next commit doesn’t remove it from history, and anyone who cloned the repository already has it. After rotating, git rm --cached .claude/settings.local.json, add it to .gitignore, and rewrite history if you need the old commits clean.

Keep the secret out of the command
#

The real fix is to never type a credential into a command an agent runs, so there’s nothing for a rule to capture. For Postgres, a ~/.pgpass file (mode 600) means pg_dump finds the password itself, and the rule becomes Bash(pg_dump *). For everything else, load secrets as environment variables from a secrets manager or the system keychain before the session starts, and refer to them by name. A rule that says curl -H "Authorization: Bearer $API_TOKEN" is harmless, and one with the token pasted in isn’t.

Then stop Claude Code reading the files where secrets live. These rules go in ~/.claude/settings.json so they apply in every project:

{
  "permissions": {
    "deny": [
      "Read(**/.env)",
      "Read(**/.env.*)",
      "Read(**/secrets/**)",
      "Read(~/.pgpass)"
    ]
  }
}

Bare patterns like **/.env match under whichever project you start Claude Code in, which is what you want here. A Read deny rule covers Claude’s file tools (Read, Grep, Glob), not whatever a shell command opens, so it won’t stop cat .env on its own. Keep cat and interpreters out of your allow rules too, or run with the sandbox on.

Privacy settings worth knowing
#

What happens to your conversations depends on the account. On a consumer plan (Free, Pro, Max and Ultra), Anthropic may use your chats and coding sessions to train future models if the “help improve Claude” setting is on. You change it at claude.ai/settings/data-privacy-controls. With it on, data is kept for five years; with it off, 30 days. On Team, Enterprise or the API, Anthropic doesn’t train on your code or prompts unless your organisation opts in, and standard retention is 30 days.

Separately, Claude Code sends operational telemetry: usage metrics, and error reports on Pro, Max and Ultra sign-ins. The data usage page says metrics never include code, prompts or file paths, and error reports are redacted before they leave. You can switch them off in the env block of your user settings:

{
  "env": {
    "DISABLE_TELEMETRY": "1",
    "DISABLE_ERROR_REPORTING": "1"
  }
}

CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 turns off both, plus the feedback survey, in one go. Turning telemetry off also turns off feature flags, which can make features such as Remote Control unavailable. And /feedback sends a copy of the conversation, code included, so check what’s in a session before you report a bug from it.

The other story this month was an open GitHub issue reporting that Claude Code put the user’s account email address in the User-Agent header of requests to third-party websites. Anthropic replied that a built-in mod blocks it from version 2.1.317, on by default and visible under /plugins, and a later comment reported a gap with curl run from Bash. If that matters to you, check the issue for the current state before relying on either.

The short version
#

settings.json in a project is the team’s file and belongs in git. settings.local.json is yours, stays out of git, and collects every “don’t ask again” approval word for word, including any password that was in the command. Lists such as permissions.allow merge across files, deny beats ask beats allow, and /permissions shows the lot. Git’s global excludes keep the local file out of commits, but not out of npm packages or Docker images, so ignore it in the project too. Keep secrets out of commands entirely, deny reads of the files that hold them, and check the privacy setting on your account rather than assuming you know what it is.

Further reading
#

On this site:

Elsewhere:

Comments

Comments are moderated.