The Claude Code Password Leak: Keep AI From Committing Secrets
Learn how to keep coding agents from exposing credentials with safer configuration, server-side secrets, and secret scans before every commit.

A coding agent can save time by writing commands, configuration, and application code—but it can also put a credential somewhere it doesn’t belong. A report on Claude Code found 1,122 public GitHub files containing at least one secret in saved local settings; that does not mean every exposed secret was still valid, but it shows how easily sensitive data can end up in a repository. (The Hacker News)
The lesson is bigger than any one coding tool: an approval prompt is not a secrets-management system. A developer may approve a command containing a password, then later discover that the credential was saved in a project file, pasted into generated code, or included in a commit. Keeping secrets out of an AI-built app takes a few deliberate safeguards.
Keep credentials out of the repository
Start by storing local development secrets in a dedicated file such as .env, rather than hard-coding them in source code or pasting them into instructions for an agent. Add the file to .gitignore so Git excludes it from future commits:
.env
.env.*
!.env.example
An .env.example file can document the variable names an app needs without containing real values. For example, it might list DATABASE_URL and PAYMENT_API_KEY with empty values.
Ignore rules help prevent accidental additions, but they don’t erase a file that has already been committed. And a machine-wide ignore setting is not a substitute for project-level protection: collaborators and build environments may not share your local configuration.
Be especially careful when a tool offers to remember an approval. If the command includes a password or token, don’t approve it for permanent reuse. Check local tool settings before committing, and avoid putting credentials in shell commands, comments, test fixtures, README files, or prompts that may be saved.
Put production secrets on the server
A browser-based app should not need access to production credentials. Keep keys for databases, payment providers, email services, and other external systems in server-side environment variables or a managed secrets store. The server can use those values to make requests without sending them to the user’s browser.
For example, a payment key belongs in the server-side code that creates a payment session—not in a frontend component that runs on a customer’s device. Apply the same principle to any credential that grants access to data or actions: expose only what the client needs, and keep privileged values on the server.
The OWASP Secrets Management Cheat Sheet recommends managing secrets through controlled processes rather than treating them as ordinary application configuration. For an AI-generated project, give the agent variable names, not live credentials.
Scan before every commit
Ignore files and careful prompts reduce risk, but they can’t catch every mistake. Add a secret scan to your pre-commit workflow and to continuous integration. GitHub’s documentation describes how secret scanning can identify credentials exposed in repositories and alert maintainers.
A practical checklist before committing:
- Review the staged changes with
git diff --cached. - Search for sensitive patterns and unexpected
.envor settings files. - Run a secret scanner against the staged changes.
- Stop if a real credential appears; remove it before committing.
- If a credential has already been exposed, revoke or rotate it. Deleting the line does not make an exposed credential safe to keep using.
The critical habit is scanning before every commit, not just when a project is ready to ship. A key can slip into a debugging example or a generated test even when the main app is structured correctly.
Build with variable names, verify with real values
You can still ask an AI agent to connect a feature to an external service. Describe the required variable, such as PAYMENT_API_KEY, without sharing its live value. Add the real value through your local environment or deployment platform, then test the integration without exposing the credential in source control.
This matters for any app that handles user data or transactions. If you’re building a booking app, for instance, keep payment and email credentials out of the interface and make the server responsible for using them. And before launch, review how data moves through the app with our guide to catching hidden data calls in a vibe-coded app.
AI can help write the integration. It should never decide where a production secret lives.
Keep Reading

Walk through a practical visual feedback loop: capture the broken screen, give the AI coder the screenshot and the intended behavior, ask it to identify one…

Local AI is drawing fresh attention, but a first MVP doesn’t need a model running on your own hardware. Test whether users actually want the core workflow…

With the Nasdaq erasing its 2026 gains amid an AI sell-off, don’t assume enthusiasm for AI means customers want your app. Before vibe coding, test whether…