AI Coding Agents Exposed API Keys. What to Rotate
GitGuardian found 31,088 secrets in Claude Code settings on public GitHub, 5,343 of them valid. Rotate first. Deleting the file leaves history intact.
By Muhammad Saif and Aashan Khan · Techtribe co-founders
An API key an agent wrote into a project file is a production credential until you revoke it. The file can be private, the repo can be a demo, and the key can still open the database, the cloud account, or the model bill. Incident response here is the order of operations: make the key stop working, find every copy, then clean the git history so the old string stops spreading.
Two research teams documented the same Claude Code behavior in November 2026, with different counts because they asked different questions. Apiiro reported that choosing "Yes, and don't ask again" stores the approved command, word for word, in .claude/settings.local.json, and that 1,122 public copies of that file held at least one secret. GitGuardian, writing on November 9, counted every secret it had seen pushed in that file, including copies later deleted, and checked which ones still worked. The product change in Claude Code 2.1.323, which stops some new secrets from being saved, is explained in the note on "Don't ask again". This note is what you do when the key has already left the laptop.
The same shape shows up beyond that one filename. A trace of an agent session can hold a key the model saw. Cursor's account of copied historical traces is in the Cursor security breach. Stolen model keys that get resold are in LLM jacking. If the key was written down by an agent, the response starts the same way regardless of which file you found first.
What GitGuardian measured, and what Apiiro measured
Keep the two reports separate or the numbers will sound like a contradiction.
Apiiro searched public GitHub and reported 104,185 copies of .claude/settings.local.json across 103,617 repositories. About 1.1 percent, 1,122 copies, held at least one secret, 1,379 distinct secrets in total. Apiiro counted a value when it matched a known key format, or when a password sat beside a server address, and an AI reviewer agreed. Apiiro did not test whether those secrets still worked. More than a third opened a database directly, including 379 database passwords. The rest of the public summary includes 43 SSH logins for public servers, 42 tokens for GitHub, GitLab, and npm, and 23 AWS keys. Sixty-three organizations were among the owners. As of the Monday Apiiro described, every file with a secret was still on the repository's default branch, and in half of those repositories it had been there at least 217 days.
History made the set larger. Apiiro reported 734 further secrets across 509 repositories that were gone from the current file, usually because the file was deleted. Forks carried the same secrets further: 211 forks of 74 repositories. The shared .claude/settings.json, which teams commit on purpose, held secrets in 298 of 76,011 copies, mostly inside allow rules. Adding older versions and saved agent chat logs, Apiiro's total was 2,539 secrets across 1,994 repositories.
GitGuardian's November 9 post watches public commits as they are pushed, so deleted and force-pushed copies stay in the count. From January 2025 through November 7, 2026 it reported 71,525 occurrences of settings.local.json and 31,088 distinct secrets in that file, across 23,276 repositories and 11,336 authors. Where its checker returned a verdict, 67 percent of occurrences in settings.local.json were valid. Over the whole set, 5,343 of the 31,088 distinct secrets worked at detection. GitGuardian is explicit that detectors without a live check are never counted as valid, so 5,343 is a floor.
The live credentials cluster in databases. GitGuardian reported 1,955 distinct valid Postgres connection strings in settings.local.json alone, 292 valid SSH passwords, 116 valid MongoDB URIs, 941 valid Google API keys, 355 valid Telegram bot tokens, 142 valid Resend keys, and 186 valid DeepSeek keys. By family it put database identifiers first, with 2,280 distinct valid secrets, then cloud provider tokens with 971, then AI tokens with 583.
On the shared settings.json file the same post reported 17,705 occurrences, 8,271 distinct secrets, 6,839 repositories, and 1,283 secrets valid at detection. The file people think of as local was the larger leak. The file teams commit on purpose was still large enough to matter.
GitGuardian also described copies in Docker Hub images. A .dockerignore that does not mention .claude will happily send the settings file into an image, and an image is another public registry. If you have ever built a container from a laptop where Claude Code had saved an allow rule, the registry is in the rotation scope even when the git repo looks private.
Apiiro's 1,379 and GitGuardian's 31,088 are both real. One is "what is sitting on default branches under a conservative filter, unchecked." The other is "what was pushed, and what still authenticated when a checker asked." For incident response, the second question is the one that decides whether you are late.
How a key gets into the file
Claude Code asks before it runs most shell commands. "Yes, and don't ask again" stores an allow rule so a later session can run a matching command without asking. Sometimes the rule is a pattern. Sometimes it is the exact command. When it is the exact command, a token typed into that command is stored in plain text.
GitGuardian's example is the ordinary one. A developer asks the agent to list workflows on an internal automation server. The agent proposes a curl with the API key in a header. The developer clicks the button that means "stop asking me this afternoon." The key is now in .claude/settings.local.json in the project directory. Claude Code tries to keep that file out of git by adding it to the user's global git excludes the first time it writes the file. That exclude lives in one user's git settings on one computer. It does nothing for a file that is already tracked, nothing for a second computer, and nothing for a project .gitignore that was never updated. Apiiro found that in 539 of 1,105 repositories it traced, a commit listing Claude as a co-author changed the file. The agent that created the rule is often the agent that commits it.
GitGuardian placed the secrets it could locate inside allow rules or environment blocks, not inside deny rules. In a sample of about 3,000 occurrences, curl carried about half, environment-variable prefixes such as a database URL carried about 15 percent, and export carried about 5 percent. The pattern is "the command a person approved so the task would finish," which is most of what an agent does on a Tuesday.
Other paths exist and should be on the same checklist. A key pasted into a prompt can land in a transcript, a debug log, or a support thread. A key in a committed .env that the agent was told to read is an older mistake the agent makes easier to repeat, because it will copy the value into a command and then into a rule. A container build that sends the build context to a registry publishes whatever the context contained. Treat every one of those as a copy, not as a separate philosophy.
The order that actually reduces damage
Rotate before you clean the repository. A public commit is already cloned by whoever watches for fresh credentials. The hours you spend rewriting git history are hours the key still works. GitGuardian's validity rate is the argument: a large share of these strings authenticated when checked. Assume yours does until the provider says it does not.
- Identify the credential exactly. The string in the file is a database URL, a cloud access key, a model key, a bot token, or a password in a command. Name the provider and the account. If the file has several, list them all before you start clicking. Partial rotation is how the second key in the same rule stays live.
- Revoke it at the provider, from a machine that did not hold the file. Create the replacement in the provider's console or in your secret store, with a scope no wider than the old key's job. Sessions and long-lived tokens derived from the secret get revoked too. A database password change that leaves existing connection pools holding the old password will drop traffic, which is what you want, and you should plan the blip.
- Check whether the key was used. Provider audit logs, cloud trail, database logs, and the model's usage page will not be complete, and they are still how you learn whether this is a leak on disk or a leak that has already been exercised. Look from the date the file was first committed, not from the date you noticed. Apiiro's median "at least 217 days" on half the repos is a warning about how long "we just found it" can be.
- Replace the value everywhere it is supposed to live: production secret manager, CI, a teammate's laptop, a serverless environment, a mobile build config. Then deploy the replacement. Revoking without shipping the new value is an outage you cause yourself. Do that on purpose, with the app owner watching, rather than at midnight by accident.
- Find copies. Search the org for the key prefix, for the filename, and for the host the command called. Include forks, mirrors, CI caches, container registries, and agent transcripts if your tool stores them. GitHub's secret scanning and push protection help on the platform you are on. They do not see the Docker Hub image GitGuardian called out, and they do not see a laptop that never pushed.
- Remove the file from the places teammates will clone next. Add
.claude/settings.local.jsonto the project.gitignore. After the key is dead, clean history if the repo is public or widely forked. History cleaning before rotation is theater. History cleaning after rotation stops the dead string from training the next person to panic. - Write down the window, the key identifiers, the providers you notified, and the commits you rewrote. The next incident will start with someone asking whether this key was already rotated. A Slack thread is a bad system of record.
If the key belongs to a customer, or to a production database of personal data, the legal and customer-notice questions start in parallel with step 2, not after the blog post is finished. The technical order does not pause for a perfect narrative. You can tell customers the truth you have: the key is revoked, the window is this, the investigation of use is still open.
Where else an agent leaves a copy
Search beyond the filename that started the incident.
Chat transcripts and project memories. Some tools keep a local history of commands and file snippets. A key that was in a command is in that history even when the settings file was never committed. Delete those logs after rotation, on each machine that ran the session.
CI logs. A workflow that prints the agent's command, or that checks out a branch where the file existed, can store the secret in a log retention bucket. Rotate first, then expire the logs. Editing a log by hand is how you miss the second job that echoed the same value.
Images. Add .claude to .dockerignore and confirm the build context with a tool that lists what was sent. Rebuild and replace tags that were published while the file was present. A floating latest tag is a second copy you will forget.
Forks and downstream clones. You cannot force a stranger to delete a fork. You can make the secret useless, which is why rotation comes first. For forks inside your own org, close them or clean them. A fork of a private repo by an ex-contractor is still a copy.
The agent on another branch. A feature branch can hold the file after the default branch is clean. Search all branches and tags. Tags are how a "cleaned" repo keeps the secret available forever.
Support inboxes and issue trackers. People paste the failing command into a ticket. If the command contained the key, the ticket is a copy. Search there too.
The companion problem of instruction files that tell an agent to run a hostile script is in the AGENTS.md audit. A script that runs can read keys that were never written into settings.local.json. If you found the settings leak because a machine was already suspect, do both cleanups. Finding one file does not mean the disk had only one problem.
What does not hold
Deleting the file in the working tree does not hold. Git history, forks, and images keep the string. Apiiro's history count exists because people delete the file and believe they are done.
Rewriting history while the key is live does not hold. It spends time. It can also push the secret through another set of systems if the rewrite is sloppy. Revoke, then rewrite if you still need to.
A scanner that missed the secret once does not hold as proof the secret is absent. GitGuardian noted that many of the database passwords were inline in commands, the kind of string a format-only rule misses. Search for the filename and for command patterns, not only for AKIA prefixes. Postgres URLs and curl headers are the bulk of the valid set.
Claude Code 2.1.323 does not hold as a cleanup. The release stops some new allow rules that look like secrets from being written to disk, and it refuses to add a standing rule to a settings.local.json that git already tracks. It does not scan rules already in the file, and it does not pull strings back from GitHub. Upgrade, and still rotate what was saved before the upgrade. The details are in the "Don't ask again" note.
Moving the repo from public to private does not hold. The clones already exist. The key is the thing that has to die.
Blaming the developer who clicked the button does not hold as a control. The button is the product's default way to get through a repetitive task. The fix is a project gitignore, a secret store the agent cannot commit, and a rotation habit. A lecture does not remove the key from the fork.
How a small company gets through a weekend like this
Name one person to revoke and one person to watch the app. The revoker works from a clean machine with the provider consoles open. The watcher watches error rates, because a database password rotation will drop connections and a cloud key rotation will break the deploy that still has the old value. Decide the maintenance window in one sentence, even if the window is "now."
List keys on paper or in a ticket, not in a chatbot session that will store the list. Identifiers and providers are enough. Do not paste the live secret into the ticket you just opened to discuss the leak.
Tell customer support what they can say if someone writes in: we rotated a credential, the app may have blipped, we have no customer action to request unless a later notice says so. Speculation in the inbox becomes the story. The timestamps you wrote down in step 7 are what support is allowed to repeat.
If you cannot tell whether a key was used, say that. "We revoked it, we are reading logs from this date, we have not confirmed misuse" is a complete sentence. Inventing certainty is how a short incident becomes a credibility problem.
After the weekend, add the gitignore, turn on push protection where the host offers it, and move production secrets out of any file an agent can edit. The agent can still read a secret from the environment when a person runs a command. The difference is that the environment is not a file the next git add . will pick up. Keep production values out of the developer environment in the first place when you can. A laptop that can only reach staging cannot leak production by approving a curl.
What to change so the next approval is boring
Give the agent a way to call the API without you putting the key in the command. A local tool that reads from a secret store, or a curl that uses an environment variable the allow rule can name without storing the value, is the shape GitGuardian's own notes point at: a rule that mentions $PGPASS is a name, and a name is what you want saved. The value stays in a place the commit cannot see.
Review diffs for .claude/ the way you review workflows. An agent co-author on a settings file is a reason to look, which Apiiro's 539 repositories illustrate. The look takes a minute when the rule is npm test. It takes an incident when the rule is a header.
Separate keys by environment and by blast radius. A model key that can only spend ten dollars, a database user that can only read staging, and a cloud role that cannot create new keys are the reasons a leak becomes a cleanup. The production owner password Apiiro described in a medical-records database is the version of this failure you do not want to discover from a researcher.
If your product's own backend holds keys for customers, the same incident can be yours from the other side. A support agent pasting a tenant token into a coding assistant is how a B2B company leaks someone else's cloud. Put that on the list of commands people are not allowed to approve.
If this is your app, send the repo.
A 30-minute scope call. We read what is live, name what is dangerous, and quote a fixed scope.
How Techtribe runs the sweep
We take the repo, the CI config, and the list of providers you actually use, and we come back with the rotation list in the order above: what is still live, where the copies are, and what the app has to ship so revocation does not become a longer outage. We do not need the raw secret pasted into a chat. A prefix and the provider are enough to start, and if the key is already public we treat it as burned on the first call.
A one-time sweep fits when a settings file, a trace, or a researcher notice just named you. A Dedicated Team fits when agents commit every week and the secret store is still a folder of env files. The follow-up build, moving the app onto scoped credentials and a gitignore that travels with the repo, is the part that keeps the next approval from becoming the next post. Production MVP is the right package when that work is the path to putting the product in front of customers with monitoring already on.
Bring the repositories, including any you made public by accident, and say whether a container image was built from the same directory. If you are not sure the key was used, say that. We will start from the provider logs you can export. If the leak started from a "don't ask again" rule and you want the setting fixed on every laptop, read that product note and bring the org search results with you.
The fixed scope for taking a generated app to production is a page per tool: Lovable, Bolt, v0, and Replit.
Questions
How do coding agents end up publishing API keys?
Claude Code's "Yes, and don't ask again" choice can save the exact shell command, secret included, in .claude/settings.local.json. GitGuardian's November 9, 2026 research found that file, and the shared settings file, pushed to public GitHub. A global git exclude on one laptop does not travel with the repo.
Is deleting the settings file enough?
No. The secret remains in git history, in forks, in CI caches, and in container images that copied the file. Apiiro and GitGuardian both tell teams to rotate the credential first. Cleanup of the file is what you do after the key no longer works.
Which number should we believe, Apiiro's or GitGuardian's?
They measured different sets. Apiiro reported 1,379 secrets in current public copies of settings.local.json, plus more in history. GitGuardian counted 31,088 distinct secrets ever pushed in that file, 5,343 of them valid when checked. Use GitGuardian's validity count as the floor for "this kind of leak works," and rotate anything that was ever in the file.
What if the key was only in a private repository?
Treat it as exposed to everyone who could clone that repository and to every system that cached the clone, including CI and a teammate's laptop. Private is not unreadable. Rotate, then remove the file from history if you still need the repository to be free of the string.