Claude Code settings.local.json secrets from "Don't ask again"
Find tokens Don't ask again saved in Claude Code settings.local.json, check if git ignores or tracks the file or its history, and rotate keys first if exposed.
Choosing "Yes, and don't ask again" saves the command as an allow rule in .claude/settings.local.json. If the command carried a token, the token is saved too. If it already went public, rotate the key before you clean history.
[1] Search the file for rules that look like secrets. The saved rule is the string shown in the prompt option, so if that string held a Bearer … header or a KEY=value prefix, it stays as typed. All values below are fake.
$ grep -nEi 'bearer|token|secret|passw|api_?key|[A-Z_]+=' .claude/settings.local.json5: "Bash(curl -H \"Authorization: Bearer FAKE-TOKEN-0000-not-real\" https://api.example.com/v1/items)",6: "Bash(DEMO_API_KEY=FAKE-KEY-1111-not-real npm run deploy)"Versions before v2.1.211, and Windows today, create the file in the starting directory, so copies can sit in subdirectories. git status leaves out ignored files, so search with find and run the grep above on each result.
$ find . -path ./.git -prune -o -name settings.local.json -path '*/.claude/*' -print./.claude/settings.local.json./tools/.claude/settings.local.json[2] Check whether git ignores the file with git check-ignore -v. If no ignore rule matches, there is no output (exit code 1) and the file shows up as a commit candidate.
According to the settings docs, the first time Claude Code writes this file it adds **/.claude/settings.local.json to your global git excludes file (core.excludesFile, otherwise ~/.config/git/ignore and similar). Then you get:
$ git check-ignore -v .claude/settings.local.json/home/dev/.config/git/ignore:1:**/.claude/settings.local.json .claude/settings.local.json[3] Check whether the file is already tracked. Ignore rules do not apply to tracked files, so after a commit the global line leaves check-ignore silent (only --no-index shows it).
$ git check-ignore -v .claude/settings.local.json$ git check-ignore -v --no-index .claude/settings.local.json/home/dev/.config/git/ignore:1:**/.claude/settings.local.json .claude/settings.local.json$ git ls-files '*settings.local.json'.claude/settings.local.jsonpackages/web/.claude/settings.local.jsonIn this state, rules added later also end up in the next commit. For rules held back because the file is tracked, see Claude Code settings.local.json allow rule not applied.
[4] Stop tracking it. git rm --cached removes the file from the index and leaves it on disk. To undo, run git add -f <file>.
$ git rm -q --cached .claude/settings.local.json packages/web/.claude/settings.local.json$ git commit -qm "stop tracking settings.local.json"$ git ls-files '*settings.local.json'The global excludes file exists only on your machine, so to protect teammates' clones add the pattern to the repository .gitignore, then commit and push. The docs give the same advice for a file you created by hand. The **/ prefix covers subdirectories.
**/.claude/settings.local.json[5] Check history. Untracking does not change earlier commits.
$ git grep -nEi 'bearer|token|secret|passw|api_?key|[A-Z_]+=' $(git rev-list --all) -- '*settings.local.json'1e52c23a5d7a2c6f259dd7b22a1c2c4ca39d4537:.claude/settings.local.json:5: "Bash(curl -H \"Authorization: Bearer FAKE-TOKEN-0000-not-real\" https://api.example.com/v1/items)",1e52c23a5d7a2c6f259dd7b22a1c2c4ca39d4537:.claude/settings.local.json:6: "Bash(DEMO_API_KEY=FAKE-KEY-1111-not-real npm run deploy)"This search only catches the same words as [1]. To see everything, read git log -p --all -- '*settings.local.json'. If a commit with a token was pushed or shipped in a package, go to [6].
[6] Revoke or rotate the token with the service that issued it. GitHub's Removing sensitive data from a repository says that for a secret this is the first step, and that it may be enough on its own. Even after a rewrite, the data may remain in other clones and forks, in cached views by SHA, and in pull requests that reference the commits.
After rotating, delete the rule that holds the old token. Any backup you made before editing also contains the token; delete it as well.
[7] Check npm packages separately. With the same global excludes line, git ignores the file, yet npm pack included it.
$ npm pack --dry-run 2>&1 | grep -E 'npm notice [0-9.]+[kMG]?B 'npm notice 87B .claude/settings.local.jsonnpm notice 19B index.jsnpm notice 38B package.jsonAdding .claude/ to .npmignore and running it again dropped the file. If a published version already contains it, rotate as in [6].
[8] Read the option before you pick it next time. Per the permissions docs, "don't ask again" appears only when the prompt can show everything it would allow. If a token is visible there, choose "Yes" to allow it once, and pass the token through an environment variable. To keep Claude Code out of secret files, see Block Claude Code from Reading .env with deny Rules.