GuidesUpdated

My coding agent committed an API key. What now?

Respond to an agent-committed secret: stop the spread, revoke the key, restore services, check for misuse, then decide whether to rewrite Git history.

On this page

An API key in an agent's commit is an incident, even if the agent already deleted the line. Find where the key went, then have its owner revoke or rotate it with the provider. A cleanup commit fixes the latest file, but older commits, PRs, logs and clones can still hold it. Revocation comes before history cleanup.

Canopy Git review workspace showing a changed-file list and pull request context
Canopy Git review workspace showing a changed-file list and pull request context

Stop the spread and classify the exposure

Pause the agent's edits, commits, pushes and comments on the task. Note the provider, key type, owner, what it can access, and where it first appeared. Check whether it's in an uncommitted file, a local commit, a pushed branch or PR, or elsewhere such as a build log or transcript; each reaches different people. Never copy the key into a prompt, issue or screenshot. If you can't show a live key stayed private, treat it as exposed.

Triage by where the value went; the provider decides whether a key is still active.
Where foundImmediate checkNext owner action
Uncommitted local fileWas it shown to a CLI, log, preview or another person?Remove it from the file and decide whether to rotate
Local commit, never pushedDid the commit leave this machine through sync or review?Rotate if exposure is uncertain; repair the branch before sharing
Pushed branch, PR, or public repoWhich remote refs and other copies contain it?Revoke or rotate urgently, then update dependent services
CI log, issue, chat, or artifactWho could read or download it?Revoke, restrict access and follow that service's removal process

Revoke or rotate the key with its provider

GitHub says a leaked secret is compromised; deleting the line doesn't stop its use. Revoke an active public or production key first, through the provider's portal or process, or escalate to whoever can. If revoking at once would break a live service, install a replacement, then revoke the old key as soon as you switch. Record the time and scope, never the value. The provider's records, not a scanning alert, decide whether a key is valid.

  • Store the replacement in the approved vault or environment config.
  • Update every app, worker, CI job and integration that used the old key.
  • Confirm the replacement works and the old key doesn't.

Check for use during the exposure window

Ask the owner to review usage, billing and audit logs from first exposure to revocation, both in GitHub and at the provider. Send spikes or unfamiliar actions to your incident process; a quiet dashboard doesn't prove nobody copied the key. Record what you checked and who keeps watching. If the key reached an agent session or integration, check that service's retention separately.

  • Keep the scope, exposure and revocation times in a private incident record.
  • Escalate signs of unauthorized access to the security owner.

Fix the code, then decide on history

Remove the key from source and config, set up proper ignored or managed secrets, and check the agent's full diff for other copies. Scan the branch, PR description, logs and artifacts with an approved scanner. A pushed key stays reachable in the old commit.

GitHub recommends rewriting history only with repository and security leads. It changes commit hashes, can invalidate reviews, needs force pushes, and can't reach other clones or forks. Revocation may remove the risk without that disruption. Never ask an agent to force-push shared history as a first reaction.

  • Decide on history only after the key is dead and services are back.
  • Logs, PR comments, transcripts and artifacts each need their own cleanup.

Close the incident and prevent the next leak

Review the latest diff and deployed config, then record the outcome. Resolve a scanning alert once remediation is documented. Turn on push protection and secret scanning where available; no scanner catches every pattern. Give future agents config key names and setup steps, never values, and use least-privilege keys from a secret store. A short drill with a test key shows who stops the agent and who rotates keys.

  • The owner confirms the old key is revoked and the replacement works.
  • Keep the incident record private.

Copyable resources

Private incident handoff

Use a redacted key identifier; never paste the credential into an agent or ticket.

Provider and credential type: [ ]
Owner / escalation contact: [ ]
Redacted identifier and access scope: [ ]
First known exposure: [time, file/commit/surface]
Where it traveled: [local file, local commit, remote branch, PR, log, transcript, artifact]
Agent work paused at: [branch/commit]
Old key revoked or rotated by: [owner, time]
Replacement installed in: [services, CI, workers]
Service checks and results: [ ]
Provider usage/audit window checked: [ ]
Repo and other-surface cleanup decision: [ ]
Latest diff reviewed by: [ ]
Open risk and follow-up owner: [ ]

Frequently asked questions

The agent removed the key in the next commit. Is the incident over?

No. If the earlier commit was shared, the value can remain in history and other copies. Revoke or rotate the key with its provider, then check affected services and usage.

Should I immediately force-push a rewritten history?

No. Revoke the key and stabilize services first. Rewriting shared history is a coordinated repository decision because it changes commit IDs, PR reviews and collaborators' clones.

Does a private repository make a committed key safe?

No. It limits who can see it, but source control isn't a secret store. Check who had access, whether the key is active and whether it reached logs; coordinate rotation with its owner.

Will GitHub push protection catch every key?

No. Coverage depends on supported patterns, repository settings and plan. Review the actual diff and use the provider's records to assess a suspected leak.

More questions and answers →

Sources and further reading