← Catalog

pi-secret-guard

A pi extension that guards against committing secrets, API keys, and credentials to git repositories using hybrid regex + LLM review.

Extension

Install

Install with PiG

pig install npm:pi-secret-guard

Install with Pi

pi install npm:pi-secret-guard
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "image": "https://raw.githubusercontent.com/acarerdinc/pi-secret-guard/master/media/demo.png",
  "extensions": [
    "./extensions/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 1.2.15 (README.md). PiG does not review it.

pi-secret-guard 🔐

npm license

Catches secrets before they reach git. Regex scan for known patterns, then the agent reviews the diff for anything suspicious.

A pi extension.

pi-secret-guard blocking a commit with AWS keys and database credentials

Install

pi install npm:pi-secret-guard

How It Works

Intercepts git commit and git push bash commands via pi's tool_call event.

git commit / git push
       │
       ▼
┌──────────────────┐
│ Get the diff     │  staged changes or unpushed commits
└──────┬───────────┘
       │
       ▼
┌──────────────────┐    Regex hit
│ Phase 1: Regex   │ ─────────────► 🚨 Hard block (must fix)
└──────┬───────────┘
       │ Clean
       ▼
┌──────────────────┐    Agent finds secrets
│ Phase 2: Agent   │ ─────────────► 🚫 Explains + helps fix
│ reviews the diff │
└──────┬───────────┘
       │ Clean
       ▼
  Agent re-issues
  the command      ──► ✅ Allowed (diff hash verified)

Phase 1 is fast and free — regex against 30+ known secret formats.

Phase 2 uses the agent already in your session. No extra API calls or config. The agent has full project context, so it can tell whether auth: "Tr0ub4dor&3" in a config object is a real password or a test fixture.

When the agent re-issues a blocked command, the extension verifies the diff hasn't changed (SHA-256 hash comparison, 5-minute expiry).

What It Catches

Regex Patterns (instant block)

CategoryExamples
Cloud providersAWS keys (AKIA...), Azure connection strings, GCP service account keys
API keysOpenAI, Anthropic, Stripe, SendGrid, Twilio, Slack, Discord, Mailgun, Google
VCS tokensGitHub (ghp_, gho_, ghs_, github_pat_), GitLab (glpat-), Bitbucket (ATBB)
Private keysRSA, EC, DSA, OpenSSH, PGP headers
AuthJWTs, credentials in URLs, database connection strings with passwords
GenericAssignments to api_key, secret, password, token variables with long values

Suspicious Files (flagged for review)

.env, .env.*, *.pem, *.key, *.p12, *.pfx, id_rsa, id_ed25519, credentials.json, service_account*.json, secrets.yaml, .htpasswd, .netrc

Agent Review (contextual)

Hardcoded passwords in config objects, database URLs with embedded credentials, tokens in unusual formats, anything that looks like it shouldn't be public. The agent already knows the project, so it understands context.

Behavior Details

git commit — scans git diff --cached. Handles git commit -a / --all by including unstaged tracked changes.

git push — scans unpushed commits via @{u}..HEAD, falls back to origin/main or origin/master.

Shell wrappers — Detects git commands wrapped in bash -c, sh -c, zsh -c, etc.

Hard block — regex finds a known secret pattern. Masks the secret in the output. Won't allow re-issue until the secret is removed.

Soft block — regex is clean, agent reviews. If the agent says clean and re-issues, allowed through. If the diff changed between review and re-issue, requires fresh review.

Why Not Just GitHub Push Protection?

GitHub's push protection is a good last line of defense, but it operates at a different stage:

(blank)pi-secret-guardGitHub Push Protection
WhenBefore git commitBefore git push
Secret in git history?Never entersAlready committed locally
CleanupJust fix the fileRewrite git history
Contextual reviewLLM reads the diffPattern matching only
Catches subtle secretsHardcoded passwords, config objectsOnly known token formats
Works offlineRegex phase, yesRequires GitHub remote

We built this extension, and GitHub's own push protection blocked our test push because the test files contained realistic-looking fake tokens. We had to amend three times. The earlier you catch a secret, the cheaper the fix.

Alternative Install Methods

From GitHub:

pi install https://github.com/acarerdinc/pi-secret-guard

Manual (global):

git clone https://github.com/acarerdinc/pi-secret-guard ~/.pi/agent/extensions/pi-secret-guard

Quick test (no install):

pi -e /path/to/pi-secret-guard

License

MIT