How to stop an AI agent committing secrets
By the AgentReceipt team · Updated 13 November 2026
An AI agent reads many files while it works, including files that hold keys and passwords. Sometimes a value ends up where it should not. These steps reduce the chance, and limit the damage when it happens.
Keep secrets out of the agent’s reach
Put secrets in environment files that are ignored by git, and keep them out of the folders the agent works in where you can. An agent cannot copy what it never reads.
Check before every push
A check that runs before code leaves your machine is the cheapest place to catch a leak. AgentReceipt can install a git pre-push hook that runs agentreceipt check --hook before each push, and stops the push when a session breaks a rule that is set to block.
npm install -g @agent-receipt/cli cd your-repo agentreceipt init --pre-push
Watch the prompt as well as the code
Secrets also appear in prompts, when someone pastes an error message that contains a key. AgentReceipt removes secret-like values from prompts before writing them to disk, so the record of the session does not become a second copy of the secret.
If a secret did get committed
Act in this order:
- Revoke or rotate the secret first. Assume it has been seen.
- Then remove it from the code, and from history if the repository is shared.
- Check the logs of the service it unlocks for use you do not recognise.