Agent playbooks
The 7 procedures the agent runs through, grouped by trigger.
Detecting .env files
When the agent encounters a .env, .env.local, or similar:
- Offer to migrate: "I see N keys in
.env.local. Migrate them into Keychain underproject.<repo>.*?" - On approval, runs
mxkey migrate <path-to-env> <repo>(with--deleteif you want the file gone in one step). - Offers to add
.env*to.gitignore. - Trims the migrated keys out of the original
.envif the user kept the file. (mxkey migrateitself prints the list of names to remove.) - Suggests wrapping dev commands:
mxkey run-here -- pnpm dev.
The agent doesn't migrate silently. Some .env files are intentionally
project-local (loaded by tooling that can't read parent-process env vars —
e.g. Next.js's .env.development at build time). The agent always asks
before touching the file.
Full reference: mxkey migrate.
Detecting export KEY= in shell rc files
When reading or editing ~/.zshrc, ~/.bashrc, ~/.profile, a
direnv .envrc, etc., if the agent sees export SOMETHING_API_KEY=...:
- Flags it once: "That
exportleaks into every process you spawn from this shell." - Offers to migrate: move the value into mxkey, remove the
exportline, wrap the consuming command inmxkey run.
The agent only mentions this once per session — won't nag.
Detecting hardcoded secrets in code
When the agent sees a hardcoded-looking secret in source files —
Authorization: Bearer xyz, const API_KEY = "...", apiKey: "sk-...":
- Warns before suggesting or writing a commit.
- Suggests the safe pattern:
mxkey set api.foo FOO_API_KEY// in code const apiKey = process.env.FOO_API_KEY! - Offers to rewrite the file.
Rotating a secret
- User generates a new key at the provider.
- The agent runs
mxkey set <name> <ENV_VAR>again — overwrites the stored value (no confirmation; this is intentional). - Reminds the user to revoke the old key at the provider. mxkey's own copy is fresh, but the old credential is still valid until you go to OpenAI / Stripe / wherever and explicitly revoke it.
Removing a secret
- Confirms with
mxkey listwhich name to remove. - Runs
mxkey rm <name>. - Reminds the user the key is still valid at the provider.
mxkey rmonly removes the local copy.
Storing 2FA backup / recovery codes
When the user mentions backup codes, recovery codes, one-time codes, or has just generated a list at a provider (GitHub, Google, Porkbun, 1Password, etc.):
- Suggests
mxkey backup add <service>— service name is a single word, no dots. - Default is hidden input. Mentions
--showif the user wants visible echo, with a warning that visible input lands in scrollback. - Each code is stored as
backup.<service>.<n>with require-auth (Touch ID on every read) — no opt-out. - To consume one later:
mxkey backup use <service>prints the next code and atomically deletes it. - Warns: never use
mxkey get/mxkey exporton a backup code — that doesn't delete it, and you'll re-use a burned code on the next call. - Reminds the user to regenerate at the provider when the count gets low.
The agent confirms the service name first, and asks before adding to an
existing backup.<service>.* group (new codes append; old codes stay).
Full reference: mxkey backup.
Refusing a pasted secret
If the user pastes something that looks like a secret into chat:
-
Does not act on it. Does not store it. Does not echo it back.
-
Tells the user:
"That looks like a secret. Because it's now in this conversation, rotate it at the provider, then run
mxkey set <name> <ENV_VAR>and type the new value at the hidden prompt — it won't enter the chat."
This is a hard rule, not a playbook decision — see Hard rules.
See also
- Triggers — when each playbook fires
- Hard rules — what the agent never does