Check your AI coding agent's saved approvals for secrets
Developer security / Part 4 of 4, Secret management for developers
CTO
- Published
- Reading time
- 15 min read
How a password typed into one approved command ended up in an AI coding agent's allow list, what Claude Code changed in November 2026, how to list what is already saved on a machine, and the shell pattern and team settings that keep secrets out.
In Part 1 we took API keys out of shell configuration files, because an AI coding agent runs in the same shell and reads the same files. One more place needs the same treatment, and it is a file the agent writes itself: its list of saved approvals.
In November 2026, Apiiro published research on Claude Code settings files in public GitHub repositories, and Ars Technica reported on it. Apiiro counted 104,185 public copies of .claude/settings.local.json and found a real secret in 1,122 of them: database passwords, API tokens, SSH logins. Apiiro traced them to one mechanism: a command with a credential in it was approved with “Yes, and don’t ask again”, and the whole command was saved. We read both pages on November 30, 2026, and every figure in this post that is attributed to Apiiro comes from its page as it stood that day.
Claude Code has changed since. Version 2.1.323, published on November 12, 2026, no longer saves an approval that looks like it holds a secret. The change applies to new approvals. The rules that were saved before it are still on disk, a developer on an older version still gets the old behavior, and Claude Code is one of several assistants that keep such a list. This post covers what the file can hold, how to check it, and how to keep secrets out of it whatever the assistant does.
How a password got into an allow list
In Manual mode, Claude Code asks before it runs most shell commands, and one of the answers is “Yes, and don’t ask again”. The permissions documentation says what happens next: Claude Code saves the approval as an allow rule in .claude/settings.local.json. In a git repository that file sits at the repository root, and the rule applies to every later session in that repository. Outside a git repository, on Windows and in a few other documented cases, the file stays in the project’s own .claude directory.
Sometimes the saved rule is a pattern. The example prompt in the documentation offers “don’t ask again for: npm test *”, which covers the test command with any arguments and holds nothing sensitive. Apiiro found that in other cases the rule was the command string itself. A command that queries a database or calls an API often carries the credential, so the rule carried it too. A file with one rule of each kind looks like this (the host and the password are made up):
{
"permissions": {
"allow": [
"Bash(npm test *)",
"Bash(PGPASSWORD=not-a-real-password psql -h db.staging.example.com -U app -d orders -c 'select count(1) from invoices')"
]
}
}
The second rule is a database password in plain text, in a JSON file that sits at the same path in every project.
The prompt appears many times in a session, and a password does not stand out in a long command. The file is also one that a developer rarely opens, because Claude Code creates and updates it on its own.
The file is meant to stay on the machine. According to the settings documentation, 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. That entry belongs to one user on one machine. It does not travel with the repository, and git never applies an ignore rule to a file that is already tracked. For a file that a teammate creates by hand, the documentation tells them to add it to .gitignore themselves. Apiiro listed further cases that the entry did not cover at the time: a folder that becomes a repository later, a clone on another machine, and a file that is already committed. In each of them the file could be committed and pushed with everything else.
A copy that never leaves the laptop still holds a credential in plain text, like the shell files in Part 1.
What Claude Code changed in November 2026
The changelog for version 2.1.323 has two entries about this file:
Changed “don’t ask again” so an allow rule that looks like it holds a secret, or would be saved to a
settings.local.jsonthat git tracks, lasts for the session only and isn’t saved
Fixed
.claude/settings.local.jsonnot being ignored globally when the folder became a git repository later, or on a new machine
npm lists that version as published on November 12, 2026, and claude --version prints the version you run. Three things stay as they were:
- A rule that was saved before the update is still in the file. The changelog entry is about new approvals.
- The check applies to a rule that “looks like” it holds a secret, and the changelog does not say how that is decided. We don’t assume that it recognizes every password a person can choose.
- A file that was committed before the update is still tracked, with whatever it holds, until someone stops tracking it.
Other assistants keep allow lists too
Claude Code is the assistant that was measured. Other assistants with terminal access have their own ways to stop asking, and each one stores the answer somewhere. This is what four vendors’ pages documented on November 30, 2026:
| Assistant | Where the rules live | What a rule holds |
|---|---|---|
| VS Code | The chat.tools.terminal.autoApprove setting. Copilot sessions on your machine read it from User settings; the integrated terminal tool reads User or Workspace settings. | A command prefix or a regular expression. “Always Allow” at the prompt saves “the exact command or a suggested prefix”. |
| Codex | .rules files. Adding a command to the allow list in the terminal UI writes to ~/.codex/rules/default.rules. | A prefix_rule whose pattern is the command and its leading arguments. |
| Gemini CLI | Policy files, for a user ~/.gemini/policies/*.toml. | A commandPrefix or a commandRegex. Choosing “Allow for all future sessions” at a prompt makes the approval persistent; the page does not name the file it is written to. |
| Cursor CLI | ~/.cursor/cli-config.json, or .cursor/cli.json in a project. | Shell(commandBase), where the base is the first token of the command line, with an optional argument pattern. |
Most of these formats store a prefix, and a prefix holds no secret as long as it ends before the secret. Apiiro compared the documentation of 16 coding agents and wrote, before version 2.1.323 was released, that Claude Code was “the only one confirmed to write the full approved command to a project file by default”. The others are still worth a look: VS Code can save the exact command, and Apiiro found real secrets in VS Code auto-approve settings committed to 9 repositories.
We treat all of these files the same way: if a secret was typed into a command, we assume that one of them now has it.
Keep the secret out of the command
The fix that works for every assistant is the pattern from Part 1, carried one step further. With that setup, credentials live in macOS Keychain or in 1Password (Part 2), and an interactive shell exports them as environment variables when it starts. A command can then name the variable:
PGPASSWORD=$DB_PASSWORD psql -h db.staging.example.com -U app -d orders -c 'select count(1) from invoices'
The shell expands $DB_PASSWORD when the command runs. The assistant saves its rule from the command text, so the rule holds the name of the variable:
"Bash(PGPASSWORD=$DB_PASSWORD psql -h db.staging.example.com -U app -d orders -c 'select count(1) from invoices')"
This keeps the value out of the command text and out of the saved rule. It does not hide the value from the agent, because every process started from that shell inherits its environment.
Many clients go one step further and read the credential themselves, from the environment, from standard input or from their own credential file, so nothing has to appear on the command line at all:
| Client | Where it reads the credential | What to know |
|---|---|---|
psql, pg_dump | PGPASSWORD in the environment | The PostgreSQL documentation advises against it on systems where other users can see process environments, and offers the ~/.pgpass password file instead. That file is plain text again, so on a single-user workstation we use the variable. |
mysql | A login path: mysql --login-path=staging | Store it once with mysql_config_editor, which keeps it in ~/.mylogin.cnf. That file is obfuscated, so the password stays out of commands and rules but not away from a process that runs as you. MySQL has deprecated MYSQL_PWD and calls it insecure. |
docker login | Standard input, with --password-stdin | Docker then keeps the credential in the operating system’s keychain or in a configured credential store. With neither, it writes it base64-encoded to ~/.docker/config.json. |
gh | GH_TOKEN in the environment, or standard input with gh auth login --with-token | With GH_TOKEN exported, gh needs no login step. gh auth login keeps the token in the system credential store, and falls back to a plain text file when it finds none. |
curl | Standard input, with -H @- | A header passed as an argument, even from a variable, shows in the process list while curl runs. |
The three standard-input forms look like this:
printf '%s' "$REGISTRY_TOKEN" | docker login registry.example.com --username ci --password-stdin
printf '%s' "$GITHUB_PAT" | gh auth login --with-token
printf 'Authorization: Bearer %s\n' "$API_TOKEN" | curl -H @- https://api.example.com/v1/items
The pattern only helps if the assistant writes the variable and not the value.
Tell the assistant. An agent copies what it finds. If the value sits in .env or in a config file that the agent can read, the command it proposes carries the value. Keep the value out of files, as in Part 1, and put one line in the project’s instruction file (CLAUDE.md, AGENTS.md): never write a credential value into a command, always reference it by its environment variable.
Read the command before you choose “don’t ask again”. If the command on screen contains a literal credential, answer “No” and ask for the variable form. A plain “Yes” saves no rule, but the command still runs with the literal value. The session transcript records the proposed command whichever answer you give, so a credential that shows up this way goes on the rotation list as well. Save an approval only for a command you would be comfortable reading in a file, and check what the rule will allow as well as what it contains: a short prefix also approves later invocations with different arguments.
Check what is already saved
The update does nothing about rules that are already saved, so this check is worth running once on every machine, whatever version it runs now.
Claude Code keeps per-project state in ~/.claude.json, and the keys of its projects object are the paths of the projects you have opened. This function reads the allow rules in your user settings and in the settings of the projects listed there. It needs jq and git 2.31 or later, and it changes nothing:
claude_allow_rules() {
local config project top git_dir root file
config="${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json"
{
printf '%s\n' "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/settings.json"
jq -r '.projects | keys[]' "$config" | while IFS= read -r project; do
top="$(git -C "$project" rev-parse --show-toplevel 2>/dev/null)"
git_dir="$(git -C "$project" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
for root in "$project" "$top" "${git_dir%/.git}"; do
[ -n "$root" ] && printf '%s\n' "$root/.claude/settings.local.json" "$root/.claude/settings.json"
done
done
} | sort -u | while IFS= read -r file; do
[ -f "$file" ] || continue
jq -r --arg file "$file" '.permissions.allow[]? | "\($file)\t\(tojson)"' "$file"
done
}
For each project it checks the project directory, the root of the checkout that contains it and, for a linked worktree, the root of the main checkout, because the repository root is where Claude Code keeps the local file when a session starts in a subdirectory or in a worktree. In each place it reads the local file and the shared .claude/settings.json. A project whose directory no longer exists is skipped. The list covers the projects recorded in that one configuration; a repository that you cloned and never opened is not on it. If you set CLAUDE_CONFIG_DIR, the function reads .claude.json and your user settings from that directory, so run it once for each configuration directory you use.
Calling the function prints rule text. If a rule holds a password, the password is on your screen and in the terminal’s scrollback. Run it yourself, in a private terminal. Don’t ask an agent to run it, because the output would become part of the session transcript, and don’t paste the output into a chat, a ticket or a screen share.
claude_allow_rules
Each line is a settings file and one rule, printed as a JSON string. An error message from jq means that a file could not be read, so an empty list under an error is not a clean result.
A long list is quicker to read with a first filter on the command shapes that carry a password:
claude_allow_rules | grep -E 'PGPASSWORD=|MYSQL_PWD=|SSHPASS=|sshpass -p|mysql[a-z]*( .*)? -p[^ )]|--password[= ]|[Bb]earer |://[^/ :]*:[^/ @]+@'
A rule that shows a variable name where the value would be is the good case. The filter is a shortcut, so read the whole list as well.
Then check whether git has ever seen the file. Run these three commands in the root of a repository:
git ls-files ':(top,glob)**/.claude/settings.local.json'
git log --oneline --name-only --all --full-history -- ':(top,glob)**/.claude/settings.local.json'
git check-ignore -v .claude/settings.local.json
The pathspec in the first two commands matches a copy at any depth. The first command prints every copy that is tracked now. The second lists the commits that touched one, in the history reachable from any ref in your clone, and prints the path under every commit that is not a merge. A hit means that the file was committed, and git show <commit>:<path> with that path prints what it held at that commit; for a commit that deleted the file, ask for <commit>~1. The third takes a real path and prints the ignore file and the pattern that cover the path, and prints nothing when no rule covers it or when the file is tracked. A pattern that starts with ! means that the path is not ignored.
Team controls
Update Claude Code. Version 2.1.323 or later no longer saves a rule that looks like it holds a secret, and no longer saves to a settings.local.json that git tracks. A machine on an older version keeps the old behavior.
Ignore the file in the repository. The global excludes entry protects the developer whose Claude Code wrote the file. An entry in the repository’s own .gitignore protects everyone who clones it. From the repository root:
printf '\n**/.claude/settings.local.json\n' >> .gitignore
git rm --cached --ignore-unmatch ':(top,glob)**/.claude/settings.local.json'
The pattern is the one that Claude Code writes to the global excludes file, and it covers a copy at any depth. The second command stops tracking every copy that was tracked, and leaves the files on disk. Check that the git ls-files command above now prints nothing, then commit both changes so that teammates get them. When a teammate pulls that commit, git deletes their copy of the file if they have not changed it, so tell them to keep a copy of any rules they want back.
Review the shared file. .claude/settings.json is committed on purpose, so its allow rules go through code review like any other change. Apiiro found a real secret in 298 of the 76,011 shared settings files it downloaded.
Decide whether developers can save rules at all. A team that deploys managed settings has a managed-only key for this, allowManagedPermissionRulesOnly:
{
"allowManagedPermissionRulesOnly": true
}
The settings reference lists two effects. Claude Code hides the always-allow choices in permission prompts and stops saving new rules, so no new command can be saved as a rule. It also ignores every allow, ask and deny rule in user, project and local settings. Move every rule the team relies on into the managed settings before you turn the key on, the deny and ask rules included, and check first that none of them holds a credential. A deny rule that is left behind stops blocking, and a missing allow rule means a prompt for every command that needs approval.
Make sure the scanner reads command lines. Apiiro ran gitleaks and TruffleHog over all 104,185 files. Of the 1,122 files with a real secret, gitleaks flagged 564 and TruffleHog flagged 643, and 215 were flagged by neither. Apiiro puts the gap down to passwords inside commands: a scanner tuned to key formats lets a password after PGPASSWORD= or mysql -p through. Include .claude/ and the other assistant folders that a repository carries, such as .cursor/, .gemini/ and .codex/, in pre-commit and CI scanning. Before you rely on the scanner, test it with a rule like the one at the top of this post, with an invented password of the kind a person would choose in place of ours.
If you find a credential
Treat it as exposed, whether or not the file was ever pushed. Deleting the rule does not undo the exposure.
- Rotate the credential first.
- Delete the rule from the settings file.
- Check the git history with the commands above; for a credential in the shared file, put
settings.jsonin place ofsettings.local.jsonin thegit logpathspec. If the file was committed while it held the value, the value is in the history, and in every fork and clone that received the commit. In the file histories it examined, Apiiro counted 734 real secrets that appear in no current copy, usually because the file was deleted. - Store the new value in macOS Keychain or 1Password, as in Parts 1 and 2, and reference it by variable from then on.
Frequently asked questions
Where does Claude Code save a "Yes, and don't ask again" approval?
For a shell command, Claude Code saves an allow rule in .claude/settings.local.json. In a git repository the file usually sits at the repository root, and the rule applies to later sessions anywhere in that repository, including sessions started in a subdirectory or a worktree. The documentation lists the exceptions, such as Windows. Since version 2.1.323, a rule that looks like it holds a secret lasts for the session only and is not saved.
Is .claude/settings.local.json kept out of git?
Usually. The first time Claude Code writes the file in a git repository that does not already ignore it, it adds the path to your global git excludes file. That entry belongs to one user on one machine. It does not travel with the repository, and it has no effect on a file that is already tracked, so add the path to the repository's own .gitignore as well.
I found a password in an allow rule and deleted the rule. Is that enough?
No. Rotate the credential. If the file was committed while it held the password, the password is in the git history, and in every fork and clone that received the commit. If it was never committed, it still sat in a plaintext file that other programs on the machine could read.
- security
- ai
- devops
- claude-code
CTO
Srđan Marković is the CTO of Red Black Tree. He writes about running AI in an engineering organization under governance, developer security and the operating decisions behind both.