name detecting-secrets description Detect hardcoded secrets, API keys, tokens, and credentials in code and git history. Use when auditing for leaked secrets or before publishing code. compatibility Designed for Claude Code metadata {"allowed-tools":"Read, Grep, Glob, Bash","argument-hint":["file-or-directory"],"stability":"stable"}
Secrets and Credential Detection
Scope : $ARGUMENTS
When to Use
Pre-publish audit (open-sourcing, npm publish, Docker push)
Reviewing PRs for accidental credential commits
Periodic security sweep
Post-incident secret rotation verification
Workflow
Scan files for secret patterns (see detection rules)
Check configuration files (.env, config, YAML, JSON)
Inspect git history for previously committed secrets
Classify findings by type and severity
Recommend remediation (rotate, revoke, remove)
Detection Patterns
API Keys and Tokens
AWS access keys (AKIA[0-9A-Z]{16})
AWS secret keys ([0-9a-zA-Z/+]{40} near AWS context)
GCP service account keys (JSON with "type": "service_account")
GCP API keys (AIza[0-9A-Za-z_-]{35})
Azure connection strings (DefaultEndpointsProtocol=)
GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_)
GitLab tokens (glpat-)
Slack tokens (xoxb-, xoxp-, xoxs-)
Stripe keys (sk_live_, pk_live_, rk_live_)
Generic API key patterns (api[_-]?key, apikey, api[_-]?secret)
Private Keys
Passwords and Credentials
JWT and Session Secrets
High-Risk File Patterns
Prioritize scanning these locations:
.env, .env.* (should be gitignored)
config/, settings/, secrets/
docker-compose*.yml (environment sections)
*.tfvars, terraform.tfstate
CI configs (.github/workflows/, .gitlab-ci.yml)
Dockerfile (ENV and ARG with secrets)
Git History Scan
Check for secrets in past commits:
Note : Secrets in git history remain accessible even after removal from
HEAD. If found, the secret must be rotated regardless.
Output Format
# Type Severity File:Line Pattern Match Remediation 1 AWS Key Critical .env:3AKIA...Rotate in IAM, add to .gitignore 2 Private Key Critical certs/key.pemRSA key Remove, regenerate, gitignore 3 DB Password High config/db.yml:12password: hunter2Move to env var 4 JWT Secret High src/auth.js:8SECRET = "..."Move to env var
Severity Definitions
Critical — Active credential that grants external access (cloud, API, DB)
High — Secret that could enable access if combined with other info
Medium — Internal-only credential or test/dev secret in prod path
Low — Potential false positive or non-sensitive token pattern
Remediation Steps
For every confirmed secret:
Rotate — Generate new credentials immediately
Revoke — Invalidate the exposed credential
Remove — Delete from codebase and git history if needed
Prevent — Add pattern to .gitignore and pre-commit hooks