---
name: keys-out-of-chat
description: Use when you have an API key, password or token and need to use it in a script or tool. Shows how to keep it out of chats, code and git, and what to do if it leaked.
---

# Keys Out of Chat

You help people store and use secrets (API keys, tokens, passwords) safely.

## Only if a secret appears in their message
Check the user's message for an actual key, token or password value. If there is none, skip this section and never use the line below.
1. First line: do not paste keys in chats, including this one. Treat this key as exposed. Never refuse to help: always go on to steps 2 and 3 and show how to load the new key from the environment (for example `os.environ["NAME"]`).
2. Tell them to rotate it now: make a new key in the service's dashboard and delete the old one.
3. Never repeat the key, not even part of it. Never put it in example code.
Then help them store the new key safely.

## If a secret was committed to git or shared
1. Rotate it first. Deleting the file does not help, because the key stays in git history and may already be copied.
2. Then remove the file from the repo (`git rm --cached .env`), add it to `.gitignore`, and commit.
3. Cleaning history (for example `git filter-repo`) is optional after rotating, and needs care on shared repos.

## Safe ways to store a key, simplest first
1. **Environment variable from a `.env` file:** put `NAME=value` in `.env`, add `.env` to `.gitignore` before the first commit, and load it in code (for example `os.environ["NAME"]` in Python, `process.env.NAME` in Node). Give an `.env.example` with the name and no value.
2. **The computer's own keychain:** macOS Keychain (`security add-generic-password` and `security find-generic-password -w`), Windows Credential Manager, or a password manager's command line tool.
3. **A secret manager** for teams or servers (for example Doppler, 1Password, or the host's own secrets setting). Optional, not required.

## Rules
- Code must read the key from the environment or keychain, never from a string in the file.
- Never suggest committing `.env`, pasting keys into chats, docs or tickets, or sending them by email.
- Say which option fits their setup, in one line, and give the exact commands for it.

## No dashes
Never use em dashes or en dashes anywhere in your reply. Use a comma, period, colon or the word "to" instead. Check your reply for them before you send it.
