Skip to content

commandSecurity

Find Secrets

Searches the working tree for API keys, tokens, private keys and risky config files and reports where each one lives.

npx workspacetemplates add find-secrets --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/find-secrets.md14 lines · 1.2 KBFile
---
description: Searches the working tree for API keys, tokens, private keys and risky config files and reports where each one lives.
argument-hint: "[folder to limit the search]"
---

Look for committed or exposed secrets. Scope: $ARGUMENTS (whole working tree if empty).

1. List tracked and untracked files with `git ls-files` and `git status --short --ignored`. Note any .env, .pem, .key, .p12, credentials.json, id_rsa or *.tfstate file and whether it is tracked or ignored.
2. Search file contents for high-signal patterns: `AKIA[0-9A-Z]{16}`, `-----BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY-----`, `ghp_`, `xox[bp]-`, `sk_live_`, bearer tokens, connection strings with passwords, and assignments like password, secret or api_key with a literal value.
3. Check config for risk: debug flags, permissive CORS, default admin passwords, database URLs with real hosts.
4. Run gitleaks or trufflehog if installed, quoting what they report.
5. Never print a full secret: show the first 4 characters and the length only. Do not delete, rewrite history or rotate anything.

Report file:line, type, tracked or ignored, and confidence (likely real or likely dummy value). Finish by listing which credentials should be rotated first and ask whether to draft a cleanup plan.

What it does

Leaked credentials usually hide in places nobody looks: an old .env copy, a test fixture, a Dockerfile argument or a commented-out line. This command sweeps the tree with patterns for the common key formats and checks which files git actually tracks.

The report names location and type but masks the value itself, so the output is safe to paste into a ticket. It does not rotate or delete anything.

Example

you › /find-secrets

agent › likely real: config/prod.env:7, Stripe live key (sk_l..., 32 chars), tracked in git.
likely real: scripts/deploy.sh:22, AWS access key id (AKIA...).
dummy: .env.example, all values empty.
Rotate the Stripe and AWS keys first. Draft a cleanup plan?

Questions

Does it show me the secret values?
No. It prints a four-character prefix and the length so reports are safe to share.
Does it remove secrets from git history?
No. History rewriting is risky, so it only suggests a plan and waits for you.
  • Audit Dependencies

    CommandSecurity

    Free
  • Check Auth

    CommandSecurity

    Free
  • Harden Input

    CommandSecurity

    Free
  • Review Permissions

    CommandSecurity

    Free