Claude Code Leaks Secrets to GitHub: How to Fix It
Analyst
GTIS
Deployed
2026-11-09T06:03:12.736Z
Reading Time
5 min read
Over 2,500 passwords and keys were exposed on GitHub through one Claude Code click. See how the leak happens, who is at risk and how to fix it.
Claude Code's "Yes, and don't ask again" option can quietly write your passwords and API keys into a project file, and thousands of developers have pushed that file to public GitHub repositories.
A security firm found 2,539 distinct secrets across 1,994 public repositories, tied to 63 organizations, mostly software companies. The exposed credentials included a database vendor's admin-level cloud key, a production Azure PostgreSQL password, a Square production token, and the owner password for a medical-records database. One company confirmed its exposed key was live.
This is not a story about hackers or stolen accounts. It happens through a normal approval click during everyday development. This guide explains how the leak works, what the research found, why scanners miss so much of it, and exactly what to do today.
How the Claude Code secrets leak happens
The leak starts with ordinary work. A developer asks Claude Code to check a database, test an API, or troubleshoot a failed login. Claude prepares a shell command that contains a credential pulled from a configuration file, then asks permission to run it.
First, the developer sees the prompt and picks "Yes, and don't ask again."
Second, Claude Code saves that exact command, secret included, in the local settings file at .claude/settings.local.json.
Third, the command becomes an allow rule, so it can run again without another prompt.
Fourth, the file is committed and pushed, and the secret is now sitting in a public repository.
Claude Code does try to prevent step 4. When it first writes the file inside a Git repository, it adds an exclusion to the developer's global Git ignore file. That protection has gaps: it does not travel with the project, it does not cover files that are already tracked, and it does not reliably protect a folder that becomes a repository later.
Anthropic's settings documentation confirms that standing approvals are saved in the local settings file, and its permissions guide explains that shell approvals can persist across sessions. A GitHub issue reported plaintext credential storage in approved commands as early as August 2025.
What the security firm's research found
The security firm examined 104,185 public copies of the local settings file (settings.local.json) and collected data between November 1 and 3, 2026. Real secrets turned up in 1,122 files holding 1,379 distinct credentials. Checking earlier commits, shared settings and saved agent transcripts raised the total to 2,539 distinct secrets across 1,994 public repositories and 63 organizations.
In short, the research covered 104,185 files, found real secrets in 1,122 of them, and uncovered 2,539 distinct secrets in total once history, shared settings and transcripts were included.
Databases accounted for a large share of the exposed access, including 379 database passwords and 122 Supabase service-role keys. Researchers also found cloud credentials, private keys, package-registry tokens, and 43 SSH logins. Some of those SSH commands contained root passwords.
Why secret scanners miss these credentials
Standard scanners caught only part of the problem. Of the 1,122 affected files, Gitleaks flagged 564 and TruffleHog flagged 643. Neither tool flagged 215 files.
The reason is format. Provider-issued keys have recognizable patterns, which scanners look for. Passwords embedded in commands do not. Secrets that follow PGPASSWORD=, sshpass -p, or sit inside request headers often look like ordinary text.
The lesson for security teams: a clean scan is not proof of a clean repository. Add checks for command-embedded passwords alongside checks for recognizable API keys.
The risk does not stop at GitHub
Keeping the file off GitHub still leaves a local risk. Malware on a compromised laptop can read plaintext settings files directly.
The Shai-Hulud npm supply-chain attack already showed how attackers run TruffleHog across developer machines to hunt for credentials. That makes agent approval files a practical target, not only a publishing mistake.
This also differs from earlier Claude Code configuration vulnerabilities, where attackers changed project settings to steal API keys. Here no attacker is needed to create the exposure: the secrets are recorded during legitimate work. The researchers also found secrets in saved agent conversations, memory files and deployment notes, so check those too.
How to fix it: a step-by-step checklist
Rotate first, delete second. Removing a file does not un-leak a secret that was already public.
Step 1: Search your repositories. Look in current files and Git history for the file .claude/settings.local.json, and inspect any shared .claude/settings.json file.
Step 2: Review the allow rules. Look for passwords, tokens, connection strings and authorization headers inside approved commands.
Step 3: Rotate every exposed credential. Revoke the old keys and passwords before touching the files or rewriting history.
Step 4: Untrack the local file. Run this command in your repository:
git rm --cached .claude/settings.local.json
Step 5: Ignore it going forward. Add this line to your repository's .gitignore file:
.claude/settings.local.json
Step 6: Check other agent files. Scan saved agent conversations, memory files and deployment notes for secrets.
Step 7: Rewrite history only after rotation. Cleaning history helps, but it is never a substitute for revoking the secret.
How GTIS can help secure your AI coding workflow
Globaltech & Infosec Pvt. Ltd. (GTIS) helps organizations find and fix exactly this kind of hidden exposure before attackers do.
VAPT (Vulnerability Assessment and Penetration Testing): Our testers check your repositories, pipelines and developer environments for exposed credentials, weak configurations and exploitable paths, including secrets that standard scanners miss, such as passwords embedded in commands. Findings come with clear, prioritized fixes.
Risk management: we assess where AI coding agents, settings files, transcripts and memory files create risk, score each one, and record it in a risk register with owners, remediation steps and deadlines, so nothing is left open.
Baseline management: we help you define a secure configuration baseline for AI coding tools, for example no literal passwords in approved commands, local settings files always ignored, and secrets pulled only from a secret manager, and then check that every team follows it.
Compliance: Exposed credentials can put you in breach of security standards and customer contracts. We map these controls to the frameworks you follow and prepare the evidence auditors ask for, so your AI-assisted development stays compliant as well as fast.
Best practices to prevent AI coding agent secret leaks
Use secret-manager references, not literal passwords. Commands should call a reference to the secret, so the real value never lands in an approval rule.
Read approval prompts before choosing "don't ask again." If the command contains a password, token or header, approve it once instead.
Scan agent folders and history. Security teams should include .claude directories, transcripts and memory files in secret scanning.
Add command-aware checks. Look for patterns such as PGPASSWORD= and sshpass -p in addition to provider key formats.
Do not rely on a global ignore. Put the path in each repository's .gitignore so protection travels with the project.
Protect laptops too. Plaintext settings on a developer machine are readable by malware, so treat them as sensitive.
Frequently asked questions
What does "Yes, and don't ask again" do in Claude Code?
It saves the approved shell command as an allow rule in the local settings file (.claude/settings.local.json), so Claude Code can run it again without asking. If the command contained a credential, the credential is saved too.
Is this a Claude Code vulnerability or a user mistake?
It is neither a hack nor a stolen account. It follows a normal approval flow, and the exposure happens when the local file is committed and pushed. Claude Code adds a Git ignore entry to the developer's global ignore file, but that does not protect every project.
How many secrets were exposed?
The security firm found 2,539 distinct secrets across 1,994 public repositories and 63 organizations.
Will Gitleaks or TruffleHog catch these secrets?
Only partly. Gitleaks flagged 564 and TruffleHog flagged 643 of the 1,122 affected files, and neither flagged 215.
I found a secret in my repo. What should I do first?
Rotate it. Revoke the exposed credential before you delete the file or rewrite Git history.
How do I stop the file from being committed?
Run the command git rm --cached .claude/settings.local.json, then add .claude/settings.local.json to your repository's .gitignore file.
Conclusion
The Claude Code secrets leak shows how a routine click can turn private credentials into public data. If your team uses AI coding agents, audit your repositories for the file .claude/settings.local.json today, rotate anything exposed, and move to secret-manager references so passwords never appear in commands. Convenience features are only safe when the secrets stay out of them.
Not sure whether your repositories are already exposed? Talk to GTIS about a VAPT, risk management and compliance review of your AI coding environment, and find out before someone else does.
Stay in touch , Stay Secure :
Ready to Strengthen
Your Security Posture?
Our team of cybersecurity experts is ready to help you navigate the evolving threat landscape. Get in touch for a tailored security assessment.