Secrets & Credentials
Secrets — passwords, API keys, tokens, production data — are the one place where a small slip becomes a real incident. The rules are simple, they're absolute, and a bit of prevention is highly preferable to the alternative.
The rules
-
Never paste secrets or production data into a chat
Not to debug, not to “ask a quick question,” not with your real code attached. Once it's in the prompt, it has left the building. Operate as if every chat transcript could be reviewed — because it could.
-
Environment variables and secret managers, always
Configuration that varies by environment — and everything secret — lives outside your source files. Your code reads it at runtime; the value itself is never written down in the repo.
-
.env stays out of the repo; .env.example goes in
Add
.envto.gitignorebefore your first commit, and commit a.env.examplewith safe placeholder values so collaborators (and the AI) know what configuration exists without seeing any of it. -
Remember what the agent can read
An agent with filesystem access can read your
.envjust like any other file. Scope its access accordingly — see Scope your agent — and never hand an agent credentials broader than the task needs.
If a secret leaks: rotate first, report second
- Rotate — revoke the exposed credential and issue a new one, wherever it lives.
- Check — did anything use the credential between exposure and rotation? Logs will tell you.
- Report — file the incident so the right people can assess scope. Not sure where? Start here.
- Fix the path — how did it get into a pastable place? Close that door (usually: it was in code or a log that should have been an environment variable).
Let the tooling catch what you miss
GitHub's secret scanning watches your repos for committed credentials and flags them — one more reason your projects belong in version control. Treat any scanner alert as real until proven otherwise, and practice the rotation script on a test credential once so the real day is muscle memory.