TL;DR: Approved commands in Claude Code can preserve API keys and passwords inside .claude/settings.local.json, and GitGuardian found 31,088 distinct secrets across 23,276 public repositories with 5,343 still valid when detected, according to Dam Secure. The control problem is not approval itself but storing command text as policy, because that turns an execution convenience into a reusable secret record.
At a glance
What this is: NHI Mgmt Group's analysis, drawing on Dam Secure's blog post: Claude Code's approved-command feature can store secrets in repository files, and those files can spread into Git history and container images.
Why it matters: IAM and NHI teams need to treat agent approvals as part of the credential lifecycle, because a local permission rule can become a durable secret exposure across repos, clones, and builds.
By the numbers:
- 5,343 of the secrets GitGuardian found were still valid when detected.
- GitGuardian found 613 distinct secrets from these files in public Docker Hub images.
- GitGuardian found 6,155 distinct secrets in committed CLAUDE.md files.
Context
A saved allow rule is only as safe as the command it records. In this case, a convenience feature turns the exact command text into a persistent local policy file, so a typed password or API key becomes part of the project state instead of remaining a one-time runtime input.
That matters because repository-level controls and machine-level controls are not the same thing. A file that is ignored on one developer laptop can still be committed from another clone, copied into an image build context, or preserved in history after the original command is forgotten.
Key questions
Q: How do approved commands leak API keys in agent settings files?
A: Approved commands can leak API keys when an agent stores a trusted shell or tool invocation with embedded secrets in a settings file that is later synced, copied, or committed. The leakage path is usually the file itself, plus logs, cache, and diffs that expose the secret value. Keep credentials out of command arguments and use a secrets manager or short-lived token instead.
Q: Why do local ignore rules fail to protect secret-bearing agent files?
A: Local ignore rules fail because they only affect which files are added to a repository, not what exists on disk, gets copied into archives, or enters a Docker build context. A secret-bearing agent file can still be read by build steps, packaging scripts, backups, or shared folders. Exclude it explicitly and keep secrets in separate protected storage.
Q: How should teams check whether agent config files contain secrets?
A: Teams should inspect current files, generated copies, and git history for any secret values, placeholders, or credential-like strings in agent config files. Search for API keys, bearer tokens, private keys, and connection strings, then verify whether the file was ever committed, cached, or exported. If found, remove exposure and replace the secret.
Q: What should teams do first after finding a secret in approved commands?
A: First rotate or revoke the exposed secret, because a copied credential remains usable even after the file is cleaned up. Then remove the secret from the approved command, scrub commits and logs where feasible, and replace it with a new credential or short-lived token. If the command was shared, treat every copied version as compromised.
Technical breakdown
How approved commands become persistent secret records
Claude Code saves an approved command as a rule in .claude/settings.local.json. The risk is structural: the command string itself becomes the policy object, so anything embedded in that string is stored as text and can be replayed, copied, or committed later. If the command included a bearer token, database password, or connection string, the secret is no longer tied to the session that used it. Instead, it sits in a file that looks like configuration but behaves like a credential container. See the API Key Management Guide.
Practical implication: Treat approval logs and agent settings files as secret-bearing artefacts, not as harmless local metadata.
Why .gitignore and .dockerignore solve different parts of the leak
A repository ignore rule only protects the working copy on the machine where it exists, while Docker builds use the build context, not the git index. That means a file can stay out of one clone and still enter an image, or remain untracked while still living in history from a prior commit. This is why local ignore handling and repository-level ignore handling are separate controls, not duplicates. The same principle applies to other agent files that store approvals or prompts, because build tooling and source control preserve different surfaces.
Practical implication: Put the ignore rule in the repository and in the build context, then verify both paths before treating the file as safe.
Why shell commands defeat simple secret scanners
Secret scanners are strongest when secrets appear as obvious tokens, but approved commands often wrap credentials inside shell syntax. That makes detection harder because the secret may be embedded in a header, an environment assignment, or a one-line script rather than sitting alone in a dedicated secrets file. In practice, the dangerous object is not the file type but the text pattern that carries the credential. This is why command storage in agent settings expands the search surface beyond standard .env hygiene. Read Guide to the Secret Sprawl Challenge.
Practical implication: Scan command history, agent config files, and shell-style wrappers together rather than relying on repository secret scans alone.
Threat narrative
Attacker objective: The attacker or unintended reader wants durable access to the service or data protected by the leaked credential, not just the local project file.
- Entry occurs when a user approves a command with a secret embedded in the arguments or environment block, and the agent records that exact text in a settings file.
- Credential access follows when the stored command exposes the API key, password, or token to anyone who can read the file, its history, or a copied image layer.
- Impact follows when the same secret is reused elsewhere, allowing access to data, services, or build systems that the original approval was never meant to persist into.
Breaches seen in the wild
- Hugging Face Spaces breach 2024: Unauthorised access to Hugging Face Spaces may have exposed secrets users stored for AI apps; tokens were revoked and org tokens removed.
- xAI API key leak 2025: An xAI developer leaked an API key on GitHub that reached 60+ private Grok models and stayed live for about two months before revocation.
Read and download The State of NHI & AI Agent Breach Report 2026, covering 200+ breaches impacting Non-Human Identities including AI Agents.
NHI Mgmt Group analysis
Secret-bearing approval rules create credential persistence outside the intended runtime: Once a command approval is stored as text, the credential lifecycle stops being session-bound and becomes file-bound. That breaks the assumption that an approval is a one-time operating decision rather than a durable secret record. The practitioner implication is that command approval has to be governed as secret creation, not just as access convenience.
Repository ignores do not equal governance: A file ignored on one workstation can still be present in history, other clones, or container builds. This is a classic lifecycle mismatch between local developer hygiene and organisation-wide control inheritance. The implication is that governance has to follow the file across source control, build pipelines, and image artefacts, not just the original workstation.
Approved-command storage is a form of NHI secret reuse: The same API key or password can be written once, copied many times, and then rediscovered by scanners, builders, or collaborators. That is not simply leakage, it is reuse of the same non-human credential across contexts that were never meant to share it. The practitioner implication is to treat agent settings files as part of the NHI estate and not as code-adjacent convenience files.
Human-friendly agent settings can hide machine-identity risk: The file looks like a developer preference, but it actually governs how a machine-operated tool captures and replays privileged commands. That shifts the control problem from user experience to identity lifecycle. The practitioner implication is to include agent config files in the same review and offboarding discipline used for service accounts and other NHI artefacts.
From our research library:
- 69% of organisations still authenticate machine identities with long-lived API keys, according to the 2026 State of AI Agent Identity Security Report.
- Read next: API Key Management Guide
What this signals
Secret-carrying approval files turn developer convenience into credential lifecycle debt: Once a command rule stores the literal credential, the organisation has created another place where rotation, revocation, and discovery all have to work at once. That expands the attack surface beyond the original repository and into any workflow that reuses the same working tree or image.
Approved-command storage should be governed like other NHI artefacts: Treat .claude/, .cursor/, .codex/, and related agent files as credential-bearing project state, not as disposable local preferences. That governance shift matters because agent tools increasingly create, replay, and persist machine-facing access in places developers do not inspect routinely. When the file is part of the project, it becomes part of the access model.
For practitioners
- Move secrets out of command text Use environment variables or a secret manager so approved commands store names, not values, and the allow rule never captures a live credential.
- Add repository and build ignores Add .claude/settings.local.json to .gitignore and .claude/ to .dockerignore in every repo template, then verify the files are ignored in clones and image builds.
- Search history before trusting cleanup Check tracked files and git history for .claude/settings.local.json, because deleted files and previous commits can still expose secrets in existing clones.
- Rotate every credential found in agent files Revoke or rotate any API key, password, or token discovered in settings.local.json, then remove the allow rule that carried it.
- Block reads of secret files in agent workflows Use deny rules for files such as .env and .env.* and rely on sandboxing for OS-level enforcement, since built-in file tools are not enough on their own.
Key takeaways
- Approved command storage can transform a one-time credential into a persistent file-based secret.
- The evidence is not anecdotal: GitGuardian found tens of thousands of distinct secrets in these files, including thousands that were still valid.
- The effective control set is lifecycle-based, combining rotation, repository ignores, build-context ignores, and history removal.
Related NHI Mgmt Group resources: API Key Management Guide · Secrets Management Guide · Ultimate Guide to NHIs · Guide to the Secret Sprawl Challenge
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 and MITRE ATT&CK address the attack and risk surface, while NIST SP 800-53 Rev 5 sets the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Approved command storage leaks secrets into a file that can spread through repos and images. |
| NHI-07 — Long-Lived Secrets | The leaked command text keeps credentials alive long after the original approval event. | |
| NHI-10 — Human Use of NHI | Developers are embedding machine credentials into commands that agents then persist as policy. | |
| Recommendation — Remove secret-bearing commands from agent settings and scan repository history for exposed credentials. Replace long-lived credentials in agent workflows with short-lived variables or managed secrets. Prevent humans from pasting live secrets into agent commands and enforce safer approval patterns. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | The article is fundamentally about credential lifecycle failure and unsafe authenticator persistence. |
| Recommendation — Apply IA-5 to rotate, revoke, and replace credentials exposed through saved agent commands. | ||
| MITRE ATT&CK | TA0006 — Credential Access | The attacker value comes from exposed keys and passwords that can be read from files or history. |
| Recommendation — Hunt for credential access opportunities in agent settings files, git history, and container contexts. | ||
Key terms
- Claude Code Routine: A Claude Code Routine is a saved configuration that packages a prompt, repositories, and connectors so Claude Code can run automatically in Anthropic-managed cloud infrastructure. It is designed for unattended execution through schedules, APIs, or GitHub events, which makes governance, permissions, and auditability central concerns rather than optional extras.
- Approved Command: An approved command is a pre-authorised shell, tool, or automation command that a person or system is allowed to run. In identity and access practice, it often appears in scripts, agent configurations, or operational runbooks, where its parameters and resulting permissions determine whether it can expose secrets or perform privileged actions.
- Settings.local.json: settings.local.json is a local JSON configuration file used by some applications to store per-machine or per-user settings. It is typically not meant for shared source control, and if it contains API keys, tokens, or endpoint credentials, those values can be exposed through copies, backups, or commits.
- Docker Build Context: Docker build context is the set of files sent to the Docker daemon when building an image. The build can access any file in that context unless excluded, so secret files, keys, and configuration artefacts can be copied into layers or inspected during the build process.
Deepen your knowledge
NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are building or maturing an IAM programme, it is worth exploring.
Published by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org