TL;DR: If an AI agent leaked an API key, revoke or rotate the key at the provider first, before you delete anything. Then find the blast radius: every agent, Computer and repo that holds the key, and the one run that leaked it. Rotate the key in one place, clean the agent-specific copies (transcripts, run logs, comments, settings files), and only then rewrite git history.
When an AI agent leaked an API key, the first hour decides how much it costs you. A coding agent pushed a commit, wrote a pull request comment or echoed a curl command into a log, and a live credential went with it. Now it's public, or at least visible to more people than it should be.
The single-developer version of this incident is well documented. The team version is harder, because agents change three facts:
This is the response runbook. If you want the prevention side, our guardrail checklist for coding agents leaking secrets covers who owns each control. This post assumes the leak already happened.
Revoke the key at the provider. Deleting the commit, the comment or the log line doesn't undo the leak, because anyone who already copied the key still has it.
GitHub's guide to removing sensitive data from a repository puts it plainly: if the data is a secret, the first step is to revoke or rotate it. Once it's revoked, it can no longer be used for access, and that may be enough on its own.
Two choices at this step:
Then open the provider's usage or audit view and look for calls you don't recognize. Write down the time window. You'll need it for the next step.
The blast radius is every place the key could be used from, plus every place it was written down. Map it before you rotate across the team, or you'll miss a holder and break it later.
List every agent environment, .env file, CI secret and Computer that holds it. If each agent was given the same key, all of them are in scope. If you can't answer this list in five minutes, that's the first finding of the postmortem.
Search history for the key's first characters, not the full value, so the search itself doesn't spread it:
export LEAKED_PREFIX="sk-live-4f9a" # first 12 characters only
git log --all -S "$LEAKED_PREFIX" \
--format='%h %ad %an%n %(trailers:key=Co-authored-by,valueonly)' \
--date=iso
The commit time and author narrow it to a window. Match that window against your agents' run history: the run that was active at that minute, on that repo, is your suspect. Read its log for the tool call that wrote the key.
Rotation is where teams lose the most time. The key lives in six places, each owner updates their copy at a different speed, and one forgotten agent keeps failing for a day.
Fix it in this order:
The OWASP Secrets Management Cheat Sheet covers rotation, revocation and expiry as one lifecycle, which is the right frame here: the incident is a rotation you didn't schedule.
Now remove the copies. Agents add places a human leak rarely touches:
| Place | Why the key is there | What to do |
|---|---|---|
| Agent transcripts | The agent ran a command containing the key | Search and delete the session files on each Computer |
| Run output and logs | Tool output echoed the request | Delete or redact the run's log where your tools allow it |
| Task and PR comments | The agent pasted its command as evidence | Edit or delete the comment; check its edit history |
| Agent settings files | A standing approval saved the literal command | Remove the rule, then untrack the file |
| CI logs | A step printed the environment | Delete the job log, then fix the step |
| Git history | The commit itself | Rewrite last, after rotation |
Claude Code, for example, stores session transcripts in plaintext under ~/.claude/projects/ for 30 days by default. Every Computer that ran an agent with the key has its own copy:
rg -l --fixed-strings "$LEAKED_PREFIX" ~/.claude/projects ~/.config 2>/dev/null
For git history, GitHub's guide uses git-filter-repo --sensitive-data-removal. It's explicit about the limits: rewritten commits can stay reachable in forks, clones, cached views and pull requests, and GitHub Support only helps remove them when rotating the credential can't mitigate the risk. That's why rotation comes first. GitHub secret scanning with push protection should already be on; if it wasn't, turn it on today.
Sharkly doesn't scan for secrets or rotate keys. Its part is coordination: who does each step, what they found, and who approved the rotation. During an incident, that record is what you'll want at the postmortem.
Here's the pattern that works in Sharkly:
.env files on every laptop and server.
If the leaked credential is a Sharkly personal access token (they start with shk_), the settings page shows when each token was last used, which answers "was it used after the leak?" Delete it there and create a replacement.
Prevention is its own checklist, so it isn't repeated here. The short version: secrets travel as variable references, agent settings files get reviewed like code, scanners learn to catch passwords inside commands, and every key has a named rotation owner. The team guardrail checklist has the configs, and our piece on approval gates for coding agents covers where to put a human stop. For what an agent should never be handed at all, see the Meta Muse agent signal leak.
An agent leak is a normal key leak with more holders and more copies. Revoke first, map who holds the key, find the run from commit time and run history, rotate in one place, then clean transcripts, logs and history.
Write the runbook down before you need it. Then put your agents' work on one board where every run and every comment is on record: Sharkly is free to start, and you can connect your first Computer and Agent in a few minutes.
No. Anyone who fetched the repo, a fork or a cached view still has the key. Revoke or rotate it at the provider first; cleaning history comes last.
Use git log -S with the key's first characters to get the commit time and author. Then match that time against your agents' run history for that repo and read the suspect run's tool calls.
Yes, where the provider allows it. Per-agent or per-Computer keys turn the next leak into one revoke and make usage logs tell you which agent made each call.