Skip to content

How to keep API keys and passwords out of a coding agent’s context

A secret the agent reads can end up in a log, a commit or a summary. Practical steps: ignore files, deny reads, scan commits, rotate on exposure.

Published by Contextingo.

Anything an agent reads becomes part of its context, and context travels: to the model provider, into session logs, and sometimes into a saved summary or a commit. The safest secret is one the agent never sees.

Where secrets leak from

  • A .env file in the working folder.
  • A key pasted into the chat “just to make it work”.
  • Output of a command that prints environment variables.
  • A config file in the repository that was committed by mistake.

Steps

  1. Keep real secrets outside the repository folder, in a secret manager or the operating system keychain, and load them at run time.
  2. List .env files in .gitignore, and commit an .env.example without values.
  3. Use the permission settings of your coding tool to deny reading secret files, and keep approvals on for commands that print the environment.
  4. Turn on secret scanning and push protection in your repository host, so a committed key is caught.
  5. Use separate keys for development with narrow scopes and low limits.
  6. If a secret was exposed, rotate it. Deleting the commit is not enough.

What Contextingo stores

Never put secrets in project records. Contextingo keeps its own access keys out of logs and audit data, and each person connects with their own personal key, which can be revoked. The security page lists the details.

Questions

Good to know.

Is it enough to ignore .env in git?

It keeps the file out of commits. It does not stop an agent from reading it in your working folder, so also restrict reads or keep secrets elsewhere.

What do I do after a leak?

Revoke and rotate the secret first, then check logs for use, and then clean up the history.

Nothing learned is lost. Nothing unchecked is done.