Claude Code Secret Leak: Mitigating 'Don't Ask Again' Credential Exposure
Seed story: "Claude Code Has Been Leaking Secrets through its "Don't Ask Again" Feature" (InfoQ AI/ML) · search original Written from facts verified across 2 report(s) — original explainer, not a copy or translation. Sources at the end.
Apiiro researchers uncovered 2,539 distinct secrets across nearly 2,000 public repositories stemming from Claude Code’s "Don’t Ask Again" feature, which inadvertently stores approved shell commands containing credentials in .claude/settings.local.json. This architectural flaw bypasses standard gitignore protections and evades common scanners like Gitleaks, exposing critical assets such as production database passwords and cloud API keys to 63 organizations. Developers must immediately rotate exposed credentials and explicitly untrack local settings files to prevent persistent, cross-device leakage in AI-assisted workflows.
The Scale of the Claude Code Credential Exposure
Apiiro researchers uncovered a staggering 2,539 distinct secrets across 1,994 public repositories linked to Claude Code’s "Don't Ask Again" feature. This exposure impacts 63 organizations, predominantly software companies, leaking critical credentials such as cloud API keys, production passwords, and access tokens. The root cause lies in how Claude Code stores approved shell commands containing embedded credentials in .claude/settings.local.json.
While Claude Code adds this file to the global git ignore list, this protection fails to travel with the project or cover files already tracked in git. Consequently, sensitive data remains publicly accessible. The leaked credentials included:
- A database vendor’s admin-level cloud key
- A production Azure PostgreSQL password
- A Square production token
- A medical-records database owner password
This highlights a critical gap in developer workflows where convenience features inadvertently bypass standard security boundaries.
Why the 'Don't Ask Again' Feature Failed Security Controls
The root cause lies in how Claude Code handles persistent command approvals. When developers select "Yes, and don't ask again," the tool stores the entire shell command—including any embedded credentials—directly into .claude/settings.local.json. While Anthropic added this file to the developer’s global git ignore list, this protection is inherently local. It does not travel with the repository, meaning it fails to prevent exposure if the file was already tracked or if the global configuration was bypassed.
This mechanism creates a critical gap in standard security workflows:
- Credentials are persisted in plaintext within a configuration file.
- Global git ignores are not version-controlled, offering no team-wide protection.
- Files already tracked in git remain exposed despite ignore rules.
- The feature prioritizes convenience over secure credential handling.
Consequently, approved commands containing sensitive data become permanent artifacts in the codebase, bypassing typical secret management expectations.
The Blind Spot in Standard Secret Scanners
Standard secret scanners like Gitleaks and TruffleHog failed to flag all exposed secrets, missing 215 files entirely. The root cause lies in how Claude Code stores credentials. Unlike traditional key-value pairs, secrets here are embedded within complex shell command strings in .claude/settings.local.json. When developers approve commands via "Don't Ask Again," the entire command—including inline passwords or tokens—is saved as a single string.
This structural difference creates a significant detection gap for tools optimized for standard patterns. Key challenges include:
- Contextual Embedding: Secrets appear as arguments within bash commands rather than isolated variables.
- Pattern Mismatch: Scanners often look for static keys, not dynamic command strings.
- False Negatives: High entropy within command syntax confuses heuristic-based detectors.
For developers, this highlights a critical workflow risk: relying solely on standard pre-commit hooks may leave AI-generated configuration files vulnerable. Security teams must update scanning rules to parse command structures, ensuring that credentials hidden within approved shell executions are caught before they reach public repositories.
Immediate Remediation for Affected Repositories
If your repository contains a committed .claude/settings.local.json, immediate action is required to prevent further credential exposure. First, rotate every exposed secret, including cloud API keys, production passwords, and access tokens found within the file. Do not rely on deletion alone; assume all credentials in the file are compromised.
Next, properly untrack the configuration file to stop it from syncing with your remote repository. Execute the following steps:
- Run
git rm --cached .claude/settings.local.jsonto remove the file from Git’s index while keeping it locally. - Add
.claude/settings.local.jsonto your repository’s.gitignorefile to ensure it remains untracked in future commits. - Commit these changes to finalize the removal from your version history.
This process ensures the file no longer travels with the project, addressing the gap where global git ignores failed to protect tracked files.
Architectural Shifts for Secure AI Agent Sessions
The incident highlights a critical gap in how AI coding agents handle persistent state. Relying on local plaintext files like .claude/settings.local.json for cross-device session continuity is fundamentally insecure, especially when gitignore protections fail to cover tracked files or travel with the project. Developers need architectural changes that decouple credential storage from local filesystems entirely.
To support secure, persistent agent sessions, teams should integrate directly with external secret managers rather than local caches. Key shifts include:
- External Vault Integration: Replace local JSON storage with dynamic retrieval from tools like HashiCorp Vault or AWS Secrets Manager.
- Ephemeral Token Generation: Use short-lived, scoped tokens instead of static API keys stored in approved command history.
- Centralized Policy Enforcement: Manage agent permissions through server-side policies rather than local configuration files.
These changes ensure that sensitive data never touches the local disk, mitigating risks associated with accidental commits and scanner blind spots.
Best Practices for Configuring Claude Code Safely
Developers must treat AI agent configurations as sensitive infrastructure. Since Claude Code stores approved commands in .claude/settings.local.json, never approve commands containing embedded credentials. Instead, use environment variables or secret managers to inject secrets at runtime, keeping the local settings file free of plaintext keys.
To prevent accidental commits, implement pre-commit hooks specifically tuned for AI agent files. These hooks should block any changes to .claude/settings.local.json that match secret patterns, even if standard scanners miss them.
- Audit local settings: Regularly check
.claude/settings.local.jsonfor hardcoded tokens before committing. - Enforce gitignore: Ensure the file is ignored at the repository level, not just globally.
- Use pre-commit hooks: Add custom rules to detect secrets in AI configuration files.
- Rotate credentials: Immediately replace any keys accidentally stored in approved commands.
FAQ
Why does Claude Code leak secrets in .claude/settings.local.json?
Secrets are stored in this file when developers approve shell commands containing embedded credentials using the 'Yes, and don't ask again' option. Although Claude Code adds the file to the global git ignore list, this protection does not travel with the project or cover files already tracked in git.
Do standard secret scanners detect Claude Code credential leaks?
Standard tools like Gitleaks and TruffleHog often fail to flag these secrets because passwords are embedded within shell commands, causing them to miss hundreds of exposed files. Independent research by GitGuardian found over 31,000 secrets in these files, with thousands remaining valid at the time of detection.
How should developers mitigate Claude Code secret exposure?
Apiiro recommends immediately rotating any exposed credentials and untracking the local settings file using git rm --cached. Developers should also ensure the file is added to the repository's .gitignore to prevent future accidental commits.
Sources
Put an AI coding agent to work in your own workspace
MeshCode is an AI coding agent workspace — delegate the tedious parts of shipping software and stay in control. Free to start.
Try MeshCode →