---
name: secrets-hygiene
description: Handle API keys, tokens, and other credentials safely when working with AI agents and code. Covers where they should live, how agents should read them at runtime, how to keep them out of repos, chat, skills, and logs, how to scan for leaks, and what to do after one is exposed. Use when a task needs a credential, when the user is about to paste a key into chat, when adding or rotating a token, when separating credentials across projects or clients, or when asked to "check this repo for secrets" or "I think I leaked a key". It does not manage a specific vault product's administration or replace a real security review.
license: MIT
metadata:
  title: Secrets Hygiene
  summary: Keep credentials out of repos, chats, skills, and logs, read them at runtime, scan for leaks, and rotate fast after exposure.
  category: agent-ops
  tags: [security, credentials, agents, devops]
  version: "1.0.0"
  author: Austin Christensen
  publisher: Christensen Equity
  related: [skill-authoring, launch-checklist, coding-agent-handoff]
---

# Secrets Hygiene

Agents make leaking credentials easy: a key pasted into chat lands in transcripts, a helper script hardcodes a token, a debug log prints a header. The rule is simple. Secrets are fetched at runtime from a store built for them, used in-process, and never written anywhere a human or model reads.

## When to use

- A task needs an API key, token, password, or private key.
- The user offers to paste a credential into the conversation.
- Adding, rotating, or separating credentials across projects, ventures, or clients.
- Auditing a repo, skill, or log for exposed secrets, or responding to a suspected leak.

## Where secrets should live

In order of preference:

1. **A password manager or secrets manager with a CLI** (for example `op` for 1Password, `bw` for Bitwarden, or a cloud secrets manager). Encrypted, audited, revocable, and shared across machines.
2. **The OS keychain** (macOS Keychain, libsecret on Linux, Windows Credential Manager) for single-machine use.
3. **Environment variables injected at runtime** by the platform: hosting provider settings, CI secrets, or the agent environment's credential feature.
4. **Last resort: a local file outside any repository**, readable only by the user (`chmod 600`), never synced to version control.

Never: the repo (including `.env` committed "temporarily"), skill files, prompts, chat messages, issue or PR text, screenshots, or logs.

## Workflow

1. **Name the credential, not the value.** Agree on a variable name (`STRIPE_SECRET_KEY`) and which store holds it. Separate by project and environment (`<project>/<service>` naming, distinct keys for staging and production) so one leak or one wrong lookup cannot cross a boundary.
2. **If the user starts to paste a secret into chat, stop them.** Ask them to put it in the store or the platform's secret settings instead, and give the exact place.
3. **Read at runtime, use in-process.** Pipe the value from the store straight into the command that needs it, for example `STRIPE_SECRET_KEY="$(op read 'op://<vault>/<item>/credential')" npm run sync`. Do not echo it, print it, or save it to an intermediate file.
4. **Keep it out of the repo.** Ensure `.gitignore` covers `.env*` (keep an `.env.example` with names and no values). Add a pre-commit secret scanner if the project has none.
5. **Scan before committing or publishing.** Quick checks:
   - `git grep -nIiE "(api[_-]?key|secret|token|passw(or)?d|bearer|private[_-]?key)\s*[:=]"`
   - `git grep -nIE "(sk_live_|ghp_|github_pat_|xox[bp]-|AKIA[0-9A-Z]{16}|-----BEGIN [A-Z ]*PRIVATE KEY)"`
   - For history: run a dedicated scanner such as gitleaks or trufflehog over the full history, since deleting a file does not remove it from past commits.
6. **Redact logs and errors.** Mask authorization headers and known secret variables in any output the agent shows or stores.
7. **Track expiry.** Note when tokens expire next to their name (not their value) so a scheduled check can warn before they break.

## If a secret was exposed

1. **Rotate first.** Revoke or regenerate the credential at the provider immediately. Assume it is compromised the moment it touched a repo, chat, or log; cleanup comes second.
2. Update the store and every place that consumes it, then confirm the old value no longer works.
3. Remove it from the source (and from git history if the repo is shared), knowing forks and caches may keep copies.
4. Check provider logs for use during the exposure window.
5. Write down what happened and the fix that prevents a repeat (scanner, ignore rule, process change).

## Output

- For setup tasks: the variable names, the store and location for each, and the exact runtime command pattern. Never the values.
- For audits: a list of findings with file and line, severity, and the rotation or removal step for each.

## Guardrails

- Never print, log, echo, or commit a secret value, and never repeat one back in chat even to confirm it.
- Confirm before overwriting or rotating a stored credential; rotation can break running systems.
- When unsure which project's credential applies, ask. Using the wrong account crosses a tenant boundary.
- A clean scan is not proof of safety. Say what was scanned and what was not (history, other branches, CI logs).
