AIDEFEND in Action AIA-0165 Validated Research

Claude Code “Don't Ask Again”: Approved Commands Carry Passwords Into a Project File That Ends Up on Public GitHub

Claude Code, Anthropic's AI coding agent, asks before it runs most shell commands. Apiiro's research from early November 2026 shows that answering “Yes, and don't ask again” can save the exact approved command, including any password or token typed into it, as plain text in the project file .claude/settings.local.json. On public GitHub, Apiiro found 1,122 copies of that file holding 1,379 different secrets. It did not test whether they still work, and no public evidence currently shows they were used in an attack.

Credential ExposureCredential GovernanceConfiguration ReviewAI Coding AgentGitHub Security
4 applicable AIDEFEND defenses
Source: Coding Agents Copy Your Secrets to a Hidden File 
Author: Apiiro
Original article: Nov 5, 2026

Threat Analysis

  • How a password gets into the file. When a developer answers the approval prompt for a Bash command with “Yes, and don't ask again”, Claude Code saves an allow rule in .claude/settings.local.json inside the project, and matching commands run without a prompt in later sessions. The rule covers only what the prompt offered: sometimes a pattern such as npm test *, sometimes one exact command. For example, if the approved command is PGPASSWORD=example-password psql -h db.example.com -U app, the stored rule is that whole line, password included. Apiiro found such rules in public files and reproduced the behaviour with the latest models (Opus 5.5 and Fable 5.1). Of 16 coding agents whose documentation it compared, only Claude Code is confirmed to save the full approved command in a project file by default.
  • How a local file ends up public. The file is meant to stay out of version control. Claude Code adds it to the user's global git excludes the first time it writes it in a git repository. As Apiiro points out, that list lives in the git settings of one computer and does not travel with the project: a clone on another machine, a folder that becomes a repository later, or a file that was already committed is not covered, and the project's own .gitignore is not changed. In 539 of the 1,105 repositories Apiiro traced, a commit listing Claude as co-author changed the file. Boris Cherny of the Claude Code team replied on Hacker News that the file is ignored automatically when Claude creates it, so in his view the exposed files were created by hand and committed. The public evidence does not settle how many cases each explanation covers.
  • What was measured. Apiiro found 104,185 copies of the file in 103,617 public repositories, and 1,122 of them hold at least one secret. More than a third of the 1,379 secrets open a database directly, including 379 database passwords, alongside 43 SSH logins for public servers, 42 tokens for GitHub, GitLab and npm, and 23 AWS keys. Half of the leaking files had been on the default branch for at least 217 days, older versions in git history hold 734 more secrets, and 211 forks carry the same credentials. The shared .claude/settings.json that teams commit on purpose holds secrets in 298 of 76,011 copies. Apiiro did not test validity. GitGuardian, a security company that scans public GitHub commits as they are pushed, checks validity at that moment: 5,343 of the 31,088 distinct secrets it found in this file were valid at detection. It also found 613 distinct secrets in public Docker Hub images, because COPY . . in a Dockerfile copies the whole working tree, including files that git ignores.
  • Why scanners and earlier reports did not stop it. Apiiro ran gitleaks and TruffleHog, two widely used secret scanners, over the 1,122 files: the first flagged 564, the second 643, and neither flagged 215. Most misses are passwords typed inside commands, because a value after PGPASSWORD=, sshpass -p or mysql -p matches no known key format. A user had reported the behaviour in GitHub issue #5544 on August 11, 2025; an automated bot closed it as “not planned” on January 3, 2026. Cherny said Claude Code has historically not scrubbed secrets and that the team is looking into what it can do to prevent this. He also recommended auto mode, where a classifier reviews actions in place of per-command prompts, and secret scanning on the source control host.

Applicable AIDEFEND Defenses (4)

AID-H-021.001
Client-Side Configuration Enforcement
High
The approval file leaves the laptop at the commit. A pre-commit hook that inspects the staged content can refuse a commit that includes .claude/settings.local.json or an agent settings file with a literal credential, and it also runs when Claude Code creates the commit in that clone. A local hook can be skipped or missing in another clone, so it is fast feedback, not the final gate. That gate is a required CI job on the protected branch: it fails when the local file is tracked, and it validates the shared .claude/settings.json against a schema and policy that allow no literal credential in permission rules or env. The framework's examples target other files, so this case needs its own path and password-in-command rules. A branch pushed to a public repository is readable before the job runs.
AID-H-018.001
Tool Parameter Constraint & Schema Validation
High
The password can be stopped before the approval prompt. Per Claude Code's documentation, a PreToolUse hook runs before the prompt, and one that exits with code 2 stops the tool call before permission rules are evaluated. A platform team can deliver such a hook through managed settings and reject Bash commands that carry a literal value after PGPASSWORD=, a password flag such as sshpass -p, credentials inside a URL, or a bearer value in a header. A rejected command never reaches approval, so no rule is written. Only the listed shapes are caught, and the password is already in the session transcript.
AID-E-001.001
Root & Long-Lived Credential Object Eviction
High
A credential that appeared in a committed file should be treated as disclosed. Its owner revokes and rotates it at the issuer (database, cloud IAM, SSH server, code host or package registry) before any cleanup, because after the file is deleted or history is rewritten the value is still in older commits, forks and pushed images. Confirm the old value is rejected and the new one works. The framework's example covers one AWS IAM key; other credential types need the issuer's own procedure.
AID-H-028.002
Client Credential Secure Storage & Lifecycle Management
Medium
What a saved rule can contain depends on where the credential lives. If passwords and tokens stay in the operating system keychain or a managed secret store, and commands and the env block of agent settings carry only a variable name, an exact-command approval records the name, not the value. A scheduled audit of agent settings paths for plaintext credentials finds older rules, including files that exist only on laptops. This relies on developer practice, so it is a supporting control only; a value the shell prints still reaches the transcript.

What Defenders Should Do Now

  • Find the copies that already left, then revoke and rotate what they hold. Search the GitHub organization, each repository's git history, its forks and the image registry for .claude/settings.local.json and .claude/settings.json. Revoke and rotate every credential the files ever held at its issuer, starting with those paired with a public server address, and confirm the old value is rejected. Do this before cleanup, because deleting the file does not reach the copies in history, forks and images.
  • Stop tracking the file and clear old rules on developer machines. Run git rm --cached .claude/settings.local.json, add the file to the repository's own .gitignore and exclude .claude/ in .dockerignore. Ask each developer to open the file on their own computer, or run /permissions in Claude Code, and delete every rule that contains a credential. From then on, refer to credentials in commands by variable name, such as $DB_URL, and approve pattern rules such as Bash(npm run:*) instead of one exact command.
  • Check at commit and in CI, and test the scanning rules. Use a pre-commit hook plus a required CI job on the protected branch to refuse a tracked .claude/settings.local.json and plaintext credentials in the shared settings file. Before relying on them, test with fake credential samples, for example a test string after PGPASSWORD=, sshpass -p or mysql -p. Rules that know only provider key formats will not pass this test.
  • Stop credential-bearing commands before the approval prompt. Deliver a PreToolUse hook through managed settings that rejects Bash commands containing plaintext credentials. To verify it, let Claude Code propose a harmless command with a fake password in a test project and confirm that the command is refused, no approval prompt appears and no rule is added to the file. Also confirm what the system does when the hook cannot run.

2 additional considerations

Scan git history, forks and published images with rules for passwords inside commands

Copies that left the repository earlier stay readable after the file is deleted, and a scanner that knows only provider key formats passes over a password that follows PGPASSWORD=, sshpass -p or mysql -p.
Recommendation: AppSec teams can run secret scanning over the full git history of every organization repository, its forks and the images in their registries, add rules for password-bearing command shapes, and test those rules with seeded fake credentials first. A finding starts the rotation; it does not revoke anything by itself, and forks under other accounts can only be reported to the hosting platform.

Keep agent folders out of image builds and published packages

A file that git ignores is still in the working tree, so a build that copies the whole directory carries it into a container image or a published package.
Recommendation: Build owners can add .claude/ and other agent folders to .dockerignore and to package exclusion lists, then open a built image or package and confirm the folder is absent. This affects later builds only; images and package versions already published need their own review and credential rotation.

Conclusion

A convenience that spares the developer a repeated confirmation ended up as a plaintext list of the systems that developer can reach and the passwords that open them. AIDEFEND  maps the defense to three points on this path: check agent settings files at commit and in CI so the approval file does not enter a repository, reject a command that carries a plaintext credential before Claude Code asks for approval, and revoke and rotate published credentials at the issuer instead of counting on file deletion.

Last updated: