Every secret scanner on the market today runs after the damage has already happened.
Tools like GitGuardian, TruffleHog, and pre-commit hooks check your code when you type git commit or push to CI. But if you accidentally paste a token or database string into your shell:
- It is already written in plain text to
~/.zsh_historyor~/.bash_history. - It was broadcast live on your screen during a Zoom or Google Meet demo.
- Autonomous AI coding agents (like Claude Code or Cursor) already cached your terminal buffer into local workspace configs (
.claude/settings.local.json).
I wanted a privacy guard that lives directly inside the terminal execution loop and stops secrets at the keystroke level before commands ever touch persistent disk.
So I built SecretGuard in Rust.
⚡ 15.68 Microseconds Latency
When building a pre-exec shell hook, speed is everything. If the hook introduces even a 20ms lag, your terminal feels sluggish.
SecretGuard is compiled with aggressive release profile optimizations (opt-level = 3, lto = true, codegen-units = 1, panic = "abort"):
- Average Scan Latency: 15.68 µs (0.016 milliseconds) across 1,000 synthetic commands.
- Binary Footprint: 1.56 MB standalone static binary.
- Zero Network / 100% Offline: Never connects to external servers, zero telemetry.
🔍 How Detection Works
SecretGuard uses a dual-engine architecture to catch both known formats and raw unformatted secrets:
1. Compiled Signature Engine
Matches known SaaS tokens in sub-microsecond time using a compiled regex::RegexSet:
- OpenAI / Anthropic (
sk-proj-...,ant-api-...) - AWS Access Keys (
AKIA...) - GitHub Personal Access Tokens (
ghp_...,github_pat_...) - Stripe live/test API keys (
sk_live_...,rk_live_...) - Slack bot tokens & webhooks (
xoxb-...) - PostgreSQL, MySQL, MongoDB URIs with embedded passwords
2. Contextual Shannon Entropy ($H \ge 3.6$)
For arbitrary passwords and non-standard tokens, SecretGuard calculates character probability distributions using Shannon Entropy:
$$H(X) = -\sum_{i=1}^{n} P(x_i) \log_2 P(x_i)$$
To eliminate false positives, it automatically discounts:
- UUIDs (
550e8400-e29b-41d4-a716-446655440000) - Git commit SHA-1 / SHA-256 hashes
- Hexadecimal color codes and standard system paths
🛠️ CLI Toolkit
SecretGuard is more than just a background hook:
1. Live Shell Hook
# Attach to your active Zsh session
secretguard hook zsh
When you hit Enter on a command containing an API key, SecretGuard flags the secret, strips it from shell history, and saves you from a leak.
2. One-Click History Scrubbing
secretguard clean-history
Finds and scrubs historical tokens already trapped inside ~/.zsh_history or ~/.bash_history, creating an automatic timestamped backup first.
3. AI Coding Agent Protection
secretguard protect-agent
Scans .claude/ and .cursor/ workspace directories to ensure cached environment variables and MCP credentials aren't accidentally committed to Git.
4. Real-Time Cloaked Wrappers
secretguard wrap "curl -H 'Authorization: Bearer sk-proj-...' https://api.openai.com/v1/models"
Masks stdout tokens on the fly during screen shares, video recordings, and conference talks.
5. Instant Diagnostics
secretguard doctor
Runs a health check verifying hook status, history hygiene, agent config security, and engine benchmark in under 10ms.
🚀 Quick Install
Via Homebrew (macOS / Linux):
brew tap hemanathk636/tap && brew install secretguard
Via One-Line Installer:
curl -fsSL https://raw.githubusercontent.com/hemanathk636/secretguard/main/install.sh | bash
Via Cargo:
cargo install --git https://github.com/hemanathk636/secretguard.git
🔗 Links & Feedback
- GitHub Repository: hemanathk636/secretguard
- Interactive Web Sandbox & Entropy Visualizer: hemanathk636.github.io/secretguard
I would love to hear feedback from the developer community! What edge cases, token formats, or terminal shells would you like to see supported next? If you find it useful, a star on GitHub means the world! ⭐
Top comments (0)