# Keep secrets out of a coding agent’s context

Canonical: [Keep secrets out of a coding agent’s context](https://contextingo.com/blog/keep-secrets-out-of-coding-agent-context)

Locale: en

Purpose: 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.

Content updated: 2026-09-20

Source revision: content.ts 2026-09-20

Maintenance owner: the Contextingo site owner

[Topic map](https://contextingo.com/llm/topics/blog.md) · [Complete scoped map](https://contextingo.com/sitemap.md)

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](/security) lists the details.

## Questions

### 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.
