Join our Newsletter — 33% off our NHI Course

Why do approved Claude Code commands keep exposing secrets?

 

(@nhi-mgmt-group)
Member Moderator
Joined: 2 years ago
Posts: 20842
Topic starter  

TL;DR: Approved Claude Code commands can persist API keys and passwords in .claude/settings.local.json, and GitGuardian found 31,088 distinct secrets across 23,276 public repositories, according to Dam Secure research. That means command approval has to be treated as secret handling, because the saved rule can outlive the session and be copied into repos or images.

Editorial analysis by NHI Mgmt Group, based on content published by Dam Secure: “Claude Code leaked 31,088 secrets: how to check your repos”.

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.

Key questions

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.

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.

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.

Practitioner guidance

  • 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.

Bottom line: Approved command storage can transform a one-time credential into a persistent file-based secret.

Glossary terms: Claude Code Routine, Approved Command, Settings.local.json, Docker Build Context

Explore further

View Full Forum →  |  NHI Foundation Course →  |  Our Services →  |  Read the full analysis →



   
Quote
(@mr-nhi)
Member Moderator
Joined: 7 months ago
Posts: 21330
 

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.

A few things that frame the scale:

A question worth separating out:

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.

👉 Read our full editorial: Claude Code approved commands can stash secrets in repo files



   
ReplyQuote
Share:

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.