Sub topic 10
Keeping secrets and risky guidance out
This chapter assumes you can write a basic AGENTS.md (setup, build, test, style) and that you use Git and a command line. It covers what must stay out of the file and how to word risky operations safely.
Why the file needs extra care
AGENTS.md is committed to the repository. Everyone with read access to the repo can read it, and so can every agent session that loads it. The file usually ends up in the agent's prompt, so anything in it can also be sent to a model provider, written to logs, or copied into a pull request description.
Git history keeps old versions. Deleting a secret in a later commit does not remove it from earlier commits.
What does not belong in the file
| Content | Why it is a problem | What to write instead |
|---|---|---|
| API keys, passwords, tokens | Readable by anyone with repo access and kept in history | Name the environment variable and where to get it |
| Connection strings with credentials | Same as above | Point to a `.env.example` file |
| Internal hostnames or customer data | Leaks details about your infrastructure | Refer to a private internal document |
| Commands that delete or overwrite data | An agent may run them as written | Describe the safe alternative |
| "Always approve" or "skip checks" rules | Weakens review and safety checks | Keep human review in place |
Pointing to secrets without storing them
Tell the agent that a secret exists and where it comes from. Do not include the value.
## Configuration
- Copy `.env.example` to `.env` for local development.
- `DATABASE_URL` and `INVOICE_API_KEY` are read from the environment.
Ask the user to provide them. Never write their values into source files,
tests, commit messages or this file.
- `.env` is listed in `.gitignore`; do not commit it.The agent now knows which variables the project needs and what it must not do with them. The values stay in a secret manager or in each developer's local .env.
If a secret was committed by mistake, treat it as exposed. Rotate it first, then remove it from the file. Rewriting history is optional and does not undo exposure.
Wording risky operations
Some commands are legitimate but dangerous: database migrations against shared environments, deploys, force pushes, bulk deletes. Do not list them as routine steps. State the boundary instead.
## Boundaries
- Run migrations only against the local database from `docker compose`.
Never run them against staging or production.
- Do not deploy, publish packages, or push to `main`.
- Do not use `git push --force`, `git reset --hard`, or `rm -rf` on
directories you did not create.
- Ask the user before deleting files or dropping tables.Each rule is specific and checkable, in line with the concrete-writing advice from earlier chapters. A rule such as "be careful with the database" gives the agent nothing to act on.
Treat the file as code under review
Because the file steers what an agent does, changes to it deserve the same review as changes to a build script.
- Require pull request review for AGENTS.md, for example with a CODEOWNERS entry.
- Watch for instructions that tell the agent to download and run scripts, disable tests, or send data to an external URL. A malicious or careless contribution can hide these in a long file.
- Be cautious with AGENTS.md files in third-party repositories you clone. Read them before pointing an agent at the project, since they are instructions written by someone else.
Quick checklist
- Search the file for strings that look like keys, tokens, or URLs with passwords.
- Confirm every credential is referenced by name only.
- Confirm no command in the file can harm shared environments.
- Confirm changes to the file go through review.
Exercise
A teammate adds this line to AGENTS.md: "Run npm run migrate -- --url postgres://admin:[email protected]:5432/prod to apply migrations." Name two problems and rewrite the line.
Show answer
It exposes a password and an internal hostname in a committed file, and it points a migration at production. A safer version: "Run npm run migrate against the local database only. It reads DATABASE_URL from .env. Never run migrations against staging or production." The exposed password should also be rotated, because it remains in Git history.
Exercise
Why is "Never touch production" in AGENTS.md not enough to protect production?
Show answer
The file is only guidance that an agent may ignore or misread. Real protection comes from access controls such as scoped credentials, branch protection, required reviews, and tool permission prompts.