Securing AI agents, part 6 of 6

Claude Code secrets in your allow list: how they get there, and the fix

Clicked "don't ask again" on a command with a password in it? Here's where Claude Code saves that rule, when it reaches git, and the fixes.

10 min · 2026-11-10 · Watch on YouTube · Subscribe

After this video

You can keep secrets out of your coding agent's saved approvals, check that its local settings file never reaches git, and know what to do if a secret already leaked

The short version

In Manual mode, answering a Claude Code permission prompt with "Yes, and don't ask again" saves an allow rule in .claude/settings.local.json, and a rule for one exact command keeps the full command text, so a password typed into that command sits on disk in plain text. The file is meant to stay local, and Claude Code adds it to your global git excludes the first time it writes it; it still reaches git when the file was made by hand, copied into another folder or container without that ignore, committed before it was ignored, or (one user reported, on an older version) written to the shared settings.json, and even outside git it travels with backups and screen shares. Command text also lands in transcripts, shell history and the process list, so the fix is to pass secrets by name through a script and deny the agent reading .env, approve narrow patterns instead of one-off commands (auto mode, the default since v2.1.283, drops broad ones), check the file with git check-ignore and git ls-files, scan for secrets (free on public repos, a paid add-on on private ones) and rotate any that got out.

The saved rule

"Yes, and don't ask again" on a Bash prompt saves an allow rule in .claude/settings.local.json at the repo root, and it applies to every later session in that repo. A rule with no * matches one exact command, written out in full, so a one-off command is saved with everything in it.

A password in a rule. Approve a psql command with the connection string inline, and the saved rule holds the connection string, password included.

Meant to stay local

The local file is for personal overrides, and Claude Code adds **/.claude/settings.local.json to your global git excludes the first time it writes it. It still reaches git if you made the file by hand, if the folder was copied or the agent runs in a container without that ignore, if it was committed before it was ignored (ignore rules don't affect tracked files), or if approvals land in the shared settings.json, as one user reported on an older version.

Command text spreads

A secret typed into a command also lands in Claude Code's local transcripts (plain text, 30 days by default), in your shell history, and in the process list, where on Linux other users can read it by default.

Four places. Allow list, transcripts, shell history and /proc/<pid>/cmdline: one inline password, four copies.

Names, not values

Keep the value in a gitignored .env (or a secrets manager in production) and pass it by name. A small TypeScript script reads process.env.DATABASE_URL, node --env-file=.env loads it, and an npm script wraps it, so the approved command and the saved rule hold no secret. The agent can still open .env itself, so add a deny rule, Read(./.env).

The boring rule. The agent asks to run npm run db:check, and the saved rule is Bash(npm run db:check).

Patterns, not commands

Exact rules pile up and rarely match again. A * after the subcommand covers a family (Bash(npm run *) allows npm run build and npm run test but not npm install; Bash(git *) allows every git command), but wide patterns mean more unreviewed commands. Keep a few narrow rules on scripts, like Bash(npm run db:check). Auto mode, the default since v2.1.283, sends whatever your rules don't cover to a second model and sets broad rules aside while narrow ones stay; your saved rules still sit in the file.

Check, scan, rotate

git check-ignore -v shows whether the file is ignored and git ls-files .claude shows whether it is tracked; git rm --cached stops tracking it. A pre-commit scanner such as gitleaks and GitHub secret scanning (free on public repos, a paid add-on for organizations' private ones) and push protection catch secrets on the way out; connection strings need generic patterns switched on. If a secret leaked, rotate it first: deleting the commit doesn't remove it from history or clones.

The code

The script the agent runs instead of an inline password
// scripts/db-check.ts  (package.json: "type": "module")
import pg from "pg";

const db = new pg.Client({ connectionString: process.env.DATABASE_URL });
await db.connect();
const { rows } = await db.query("select count(*) from orders");
console.log(rows[0]);
await db.end();

Run with: node --env-file=.env scripts/db-check.ts (Node runs erasable TypeScript directly).

The npm script and the allow rule it needs
// package.json
"scripts": { "db:check": "node --env-file=.env scripts/db-check.ts" }

// .claude/settings.local.json
{ "permissions": { "allow": ["Bash(npm run db:check)"] } }

The rule names a script, so no secret is ever saved in it.

Before you push
git check-ignore -v .claude/settings.local.json   # prints the matching rule if ignored
git ls-files .claude                              # lists what git already tracks
git rm --cached .claude/settings.local.json       # stop tracking, keep the file

Then add the file to .gitignore, and rotate any secret that was ever in a pushed file.

Check yourself

  1. You approve a one-off database command with the password inline and choose "Yes, and don't ask again". Where does the password end up, and why?

    In .claude/settings.local.json at the repo root: the approval is saved as an allow rule, and a rule for one exact command holds the full command text, password included.

  2. Your .gitignore already lists .claude/settings.local.json, but git ls-files .claude still shows it. Is it safe, and what do you do?

    No: ignore rules don't affect files git already tracks, so every change rides along in the next commit. Run git rm --cached on it (it stays on disk), keep it in .gitignore, and rotate any secret it ever held.

  3. How do you let the agent check the staging database without a secret ever appearing in its command or saved rule?

    Keep DATABASE_URL in a gitignored .env (or a secrets manager), read it via process.env in a small script run with node --env-file=.env, wrap it as npm run db:check, and approve a narrow rule for that script, like Bash(npm run db:check).

Sources

Every claim in this video was checked against these pages. Open one to see the claims it backs and the exact words they rest on.

  • code.claude.com/…/settings 5 claims
    • In Claude Code, choosing "Yes, and don't ask again" on a Bash permission prompt saves that approval as an allow rule in .claude/settings.local.json.
      when claude asks permission to run a bash command and you choose "yes, and don't ask again", claude code saves that approval as an allow rule in .claude/settings.local.json
    • The first time Claude Code writes settings.local.json in a git repository that doesn't already ignore it, it adds **/.claude/settings.local.json to your global git excludes file, so it stays out of your commits.
      the first time claude code writes the file in a git repository that doesn't already ignore it, it adds **/.claude/settings.local.json to your global git excludes file, so the file stays out of your commits in every repository.
    • If you create settings.local.json by hand, you must add it to .gitignore yourself.
      if you create the file by hand, add it to .gitignore yourself
    • The local settings file is for personal overrides for one project.
      personal overrides for one project, and testing before you share
    • The shared .claude/settings.json is the file a team commits so teammates get it.
      in a git repository, commit it so teammates get it
  • code.claude.com/…/permissions 7 claims
    • The saved rule goes to .claude/settings.local.json at the root of the git repository and applies to future sessions anywhere in that repository.
      claude code saves the rule to .claude/settings.local.json at the root of the git repository, resolved through worktrees to the main checkout. the rule applies to future sessions anywhere in that repository
    • Bash commands need approval (except a built-in set of read-only commands), and "don't ask again" for them is permanent per repository and command.
      bash commands shell execution yes, except a built-in set of read-only commands permanently per repository and command
    • A Bash rule names the command in brackets, e.g. Bash(npm run build); a * matches any text, and a rule with no * matches one exact command.
      a * in a bash rule matches any text, including spaces, so one rule covers a family of commands. a rule with no * matches one exact command.
    • The permission dialog can also save a prefix rule (space-separated form, e.g. Bash(ls *)) when you choose don't ask again for a command prefix; a rule saved from a prompt covers only what its option named.
      the permission dialog writes the space-separated form when you select "yes, and don't ask again" for a command prefix.
    • Everything before the first * limits a Bash rule: Bash(git log *) allows only git log commands, Bash(git *) allows every git command.
      claude code matches everything before the first * as written, so those words are what limit the rule: bash(git log *) allows only git log commands, and bash(git *) allows every git command.
    • Bash(npm run *) matches npm run build and npm run test --watch, and does not match npm install.
      bash(npm run *) npm run build , npm run test --watch , npm run npm install
    • A Read deny rule such as Read(./.env) stops Claude Code's file tools and recognised Bash file commands (cat, head, tail...) from reading the file; scripts that open it indirectly are not covered.
      read and edit deny rules apply to claude's built-in file tools, to file commands claude code recognizes in bash, such as cat
  • api.github.com/…/issues 2 claims
    • A user reported (Claude Code 2.1.228, issue #86151) that the "don't ask again for similar commands" option appended the verbatim command string, absolute paths included, to permissions.allow.
      it appends the verbatim command string, absolute paths included, to permissions.allow.
    • In the same report, one session produced about 20 prompts and about 20 saved rules, none of which matched again.
      one session: ~20 prompts, ~20 rules, none of which ever matched again.
  • news.ycombinator.com/item 6 claims
    • When the approved command holds a secret, the saved allow rule holds the whole command, secret included (the security write-up's description, as quoted in the Hacker News thread).
      pick "yes, and don't ask again" and it saves that exact command, secret included, to .claude/settings.local.json inside the project folder.
    • A security write-up, discussed on the Hacker News front page, reported Claude Code's "Don't Ask Again" exposing passwords in public GitHub files.
      claude code's "don't ask again" exposes passwords in 1,122 public github files
    • The Claude Code team replied that settings.local.json is meant to stay local, is gitignored automatically when Claude Code creates it, and that the leaked files were created by hand and checked in.
      .claude/settings.local.json is meant to stay local. this is not a file you should check into source control. we automatically gitignore it when claude creates the file, so in this case the files were manually created and checked in
    • The Claude Code team recommends auto mode over maintaining permission rules.
      permission rules are old hat. everyone should be using auto mode instead.
    • Claude Code has historically not scrubbed secrets, and its team said they are looking into preventing this.
      historically claude code has not done secret scrubbing (there are many good tools for that), but we are looking into what we can do to prevent this.
    • The write-up's author said the file gets committed on a new machine or container without the global ignore, in a copied project folder, or once it has been committed.
      it happens on a new machine or container without the global ignore, in a copied project folder, or once the file has been committed, since ignore rules don't apply to tracked files.
  • git-scm.com/…/gitignore 2 claims
    • Git's global excludes (core.excludesFile) live in the user's own config, while patterns meant for everyone who clones go in a .gitignore file in the repo.
      patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that all developers will want to ignore) should go into a .gitignore file.
    • gitignore rules do not affect files git already tracks.
      files already tracked by git are not affected
  • api.github.com/…/issues 1 claim
    • A user reported (Claude Code 2.1.170, issue #77530, closed as not planned) that "don't ask again" approvals were written to the project-shared .claude/settings.json instead of settings.local.json.
      claude code writes the new allow-rule to the project-shared **`.claude/settings.json`** instead of the project-local, gitignored **`.claude/settings.local.json`**.
  • code.claude.com/…/data-usage 1 claim
    • Claude Code stores session transcripts locally in plaintext under ~/.claude/projects/ for 30 days by default.
      claude code clients store session transcripts locally in plaintext under ~/.claude/projects/ for 30 days by default to enable session resumption.
  • api.github.com/…/issues 1 claim
    • Transcripts keep tool calls verbatim: a user found a token from a command in session files, history and logs (issue #95680).
      the blocked `tool_use` was still persisted verbatim
  • gnu.org/…/Bash-Variables 1 claim
    • If HISTCONTROL is unset (or has no valid value), bash saves all lines read by the shell parser on the history list.
      histcontrol is unset, or does not include a valid value, bash saves all lines read by the shell parser on the history list
  • man7.org/…/proc_pid_cmdline.5 1 claim
    • On Linux, /proc/[pid]/cmdline holds the complete command line of a running process.
      this read-only file holds the complete command line for the process
  • man7.org/…/proc.5 1 claim
    • By default (hidepid=0, the default when the mount option isn't given), every user may access all /proc/[pid] directories.
      everybody may access all /proc/ pid directories. this is the traditional behavior, and the default if this mount option is not specified.
  • nodejs.org/…/process 1 claim
    • process.env in Node returns an object holding the user environment (environment variables).
      the process.env property returns an object containing the user environment.
  • nodejs.org/…/cli 1 claim
    • node --env-file loads environment variables from a file, making them available on process.env.
      loads environment variables from a file relative to the current directory, making them available to applications on process.env
  • nodejs.org/…/typescript 1 claim
    • By default Node.js runs TypeScript files that contain only erasable TypeScript syntax (type stripping, stable since v25.2.0 / v24.12.0).
      by default node.js will execute typescript files that contains only erasable typescript syntax.
  • cheatsheetseries.owasp.org/…/Secrets_Management_Cheat_Sheet 1 claim
    • Environment variables are generally accessible to all processes and may end up in logs or system dumps (OWASP Secrets Management Cheat Sheet).
      environment variables are generally accessible to all processes and may be included in logs or system dumps.
  • git-scm.com/…/git-check-ignore 1 claim
    • git check-ignore outputs a path if it is excluded by .gitignore or other exclude files, and outputs nothing for a path that is not ignored.
      if no pattern matches a given path, nothing will be output for that path; this means that path will not be ignored.
  • git-scm.com/…/git-ls-files 1 claim
    • git ls-files shows the files tracked in git's index by default.
      --cached show all files cached in git's index, i.e. all tracked files. (this is the default if no -c/-s/-d/-o/-u/-k/-m/--resolve-undo options are specified.)
  • git-scm.com/…/git-rm 1 claim
    • git rm --cached removes a file from the index only, keeping it on disk.
      allowing the file to be removed from just the index.
  • docs.github.com/…/about-secret-scanning 2 claims
    • GitHub secret scanning scans the entire git history on all branches for hardcoded credentials such as API keys, passwords and tokens.
      secret scanning scans your entire git history on all branches of your repository for hardcoded credentials, including api keys, passwords, tokens, and other known secret types.
    • On public repositories, GitHub secret scanning runs automatically for free.
      public repositories : secret scanning runs automatically for free.
  • docs.github.com/…/about-push-protection 2 claims
    • GitHub push protection blocks pushes that contain secrets before they reach the repository.
      push protection blocks pushes that contain secrets before they reach your repository.
    • Database connection strings are generic (non-provider) secrets: push protection blocks them only when generic-pattern scanning and push protection are enabled for the repository.
      github blocks pushes containing structured secrets that are not tied to a specific provider, such as private keys and database connection strings. scanning for generic patterns and push protection must be enabled
  • docs.github.com/…/push-protection-for-users 1 claim
    • Push protection for users is on by default for public repositories.
      push protection for users is on by default for public repositories
  • raw.githubusercontent.com/…/README.md 1 claim
    • Gitleaks, a secret scanner, can run as a pre-commit hook in your repo or as a GitHub Action.
      gitleaks can be implemented as a pre-commit hook directly in your repo or as a github action
  • docs.github.com/…/removing-sensitive-data-from-a-repository 1 claim
    • For a leaked secret, GitHub's first step is to revoke or rotate it; once revoked or rotated it can no longer be used, which may be enough without rewriting history.
      as a first step you need to revoke and/or rotate that secret. once the secret is revoked or rotated, it can no longer be used for access, and that may be sufficient to solve your problem.
  • veracode.com/…/genai-code-security-report 2 claims
    • In that test, 45% of code samples failed security tests and introduced OWASP Top 10 vulnerabilities.
      45% of code samples failed security tests and introduced owasp top 10 security vulnerabilities into the code.
    • Over the models tested, newer models got better at writing working code but no better at writing secure code.
      while the models got better at writing functional or syntactically correct code, they were no better at writing secure code
  • arxiv.org/…/2108.09293 1 claim
    • Code models are trained on large amounts of unvetted public code, so they learn from exploitable, buggy code too.
      given the vast quantity of unvetted code that copilot has processed, it is certain that the language model will have learned from exploitable, buggy code.
  • node-postgres.com/…/queries 2 claims
    • Concatenating parameters into SQL query text can, and often does, lead to SQL injection.
      string concatenating parameters into the query text directly. this can (and often does) lead to sql injection vulnerabilities.
    • node-postgres parameterized queries ($1, $2 placeholders) send the query text and the values separately, and the server substitutes the values safely.
      node-postgres supports parameterized queries, passing your query text unaltered as well as your parameters to the postgresql server where the parameters are safely substituted
  • code.claude.com/…/permission-modes 8 claims
    • With Claude Code v2.1.283 or later, auto mode is the built-in starting permission mode for interactive terminal and VS Code sessions.
      with claude code v2.1.283 or later, auto mode is the built-in starting permission mode for interactive terminal and vs code sessions.
    • In Manual mode, Claude Code stops and asks before most actions that edit files, run shell commands, or reach the network.
      in manual mode, claude code stops and asks you before most actions that edit files, run shell commands, or reach the network.
    • In auto mode, a second model, the classifier, reviews actions instead of you.
      a second model, the classifier, reviews actions instead of you
    • In auto mode, actions matching your allow, ask or deny rules resolve first; everything else goes to the classifier.
      actions matching your allow, ask, or deny rules resolve immediately
    • On entering auto mode, broad allow rules that grant arbitrary code execution, including package-manager run commands, are dropped.
      on entering auto mode, broad allow rules that grant arbitrary code execution are dropped
    • In auto mode, narrow rules like Bash(npm test) stay in effect.
      narrow rules like bash(npm test) stay in effect.
    • If the auto-mode classifier blocks an action 3 times in a row or 20 times in total, auto mode pauses and Claude Code goes back to prompting.
      if the classifier blocks an action 3 times in a row or 20 times total, auto mode pauses and claude code resumes prompting.
    • In auto mode you get fewer prompts, but allow rules you saved stay in the settings file (they resolve first; broad ones are set aside while auto mode is on and restored when you leave it).
      claude code restores the dropped rules when you leave auto mode.
  • docs.github.com/…/about-github-advanced-security 1 claim
    • To run GitHub secret scanning on private or internal repositories you must buy the relevant GitHub Advanced Security product (Secret Protection); on public repositories it is free and automatic (claim 40).
      to run the feature on your private or internal repositories, you must purchase the relevant github advanced security product.
  • arxiv.org/…/2305.03111 1 claim
    • Text-to-SQL benchmarks built on schemas with few rows miss real-world problems; the BIRD benchmark shows models must understand the database values (dirty contents, external knowledge), not only the schema, to write accurate SQL.
      to solve these problems, text-to-sql models must feature database value comprehension in addition to semantic parsing.
  • postgresql.org/…/functions-comparison 2 claims
    • In SQL (PostgreSQL), ordinary comparison operators yield null (unknown), not true or false, when either input is null.
      ordinary comparison operators yield null (signifying " unknown " ), not true or false, when either input is null.
    • IS DISTINCT FROM is 'not equal' with null treated as a comparable value: 1 IS DISTINCT FROM NULL is true.
      not equal, treating null as a comparable value.
  • postgresql.org/…/sql-select 1 claim
    • WHERE keeps only rows for which the condition returns true; any other row is eliminated.
      any row that does not satisfy this condition will be eliminated from the output. a row satisfies the condition if it returns true when the actual row values are substituted for any variable references.
  • anthropic.com/…/tracing-thoughts-language-model 2 claims
    • An AI model is trained on text, not equipped with mathematical algorithms; it wasn't designed as a calculator (Anthropic, on Claude).
      claude wasn't designed as a calculator-it was trained on text, not equipped with mathematical algorithms.
    • Asked how it added 36+59, Claude describes the standard carry-the-1 algorithm, which is not what it does internally.
      if you ask how it figured out that 36+59 is 95, it describes the standard algorithm involving carrying the 1.
  • arxiv.org/…/2410.05229 1 claim
    • In the GSM-Symbolic study, every model's performance declined when only the numbers in a grade-school math question were changed.
      the performance of all models declines when only the numerical values in the question are altered in the gsm-symbolic benchmark.
  • ai-sdk.dev/…/tools 1 claim
    • In the AI SDK, a tool has an optional async execute function, called with the arguments from the model's tool call; your code computes the result.
      execute : an optional async function that is called with the arguments from the tool call.

Spotted a mistake? Say so in the video's comments. Fixes are listed on corrections.