Skip to content
khushwant.dev
← All posts
2 min read

Why I built PromptGuard: a secret firewall for AI coding prompts

AI coding tools are great until you paste a .env into one. PromptGuard scans every prompt locally before it leaves your machine — here's the why and the how.

AI toolingSecurityBuild log

I use AI coding tools all day. They're genuinely great. But there's a failure mode nobody wants to talk about: the prompt itself is an exfiltration channel.

You paste a stack trace to debug it. The stack trace has a connection string in it. That connection string just left your machine and is now sitting in someone else's logs. You didn't do anything wrong — you were just working fast.

PromptGuard is my answer to that. It's a secret firewall for prompts.

What it actually does

It hooks into the prompt-submission events that editors already expose — beforeSubmitPrompt in Cursor, UserPromptSubmit in Claude Code — and scans the prompt before it's sent.

  • Runs 100% locally. No network calls. Nothing stored.
  • Detects known provider credentials (AWS, OpenAI, Anthropic, GitHub, Stripe, Slack, npm, JWTs, private keys) plus high-entropy strings that just look like secrets.
  • Fails open by default, so it never blocks your flow on an error. There's a --strict mode that fails closed for security-critical setups.

Install is one line:

npx @khushwant.r/promptguard install

The design decision that mattered most

Fail open vs fail closed.

If a security tool is annoying, people turn it off — and then it protects nothing. So the default is: if PromptGuard itself hits an error, your prompt still goes through. It's a guardrail, not a gate.

For teams that genuinely can't afford a leak, --strict flips that: on error, the prompt is blocked. Same tool, two very different risk postures, one flag.

// Roughly the shape of the decision
function decide(scan: ScanResult, strict: boolean): "allow" | "block" {
  if (scan.error) return strict ? "block" : "allow";
  return scan.hasSecret ? "block" : "allow";
}

The bigger pattern

This is one of three tools I've shipped in the same spirit — small, focused, local-first tools that catch a specific new failure mode introduced by AI coding: leaked secrets (PromptGuard), hardcoded secrets before commit (SecretGuard AI), and hallucinated/typosquatted imports (ImportGuard).

The common thread: AI tools are powerful, but they move the moment where things go wrong. Catch it at that exact moment, locally, and you barely notice the tool is there.

More build logs coming. If this is useful to you, the package is on npm.

Enjoyed this?

Get new posts by email — build logs, RAG/LLM engineering, and AI dev-tooling notes.

Build logs, RAG/LLM deep-dives, and AI dev-tooling notes. No spam. Unsubscribe anytime.