Smart command safety filter for Claude Code
npx claudepluginhub banyudu/claude-wardenSmart command safety filter for Claude Code — parses shell pipelines and evaluates per-command safety rules to auto-approve safe commands and block dangerous ones
Share bugs, ideas, or general feedback.
Smart command safety filter for Claude Code. Parses shell commands, evaluates each against configurable safety rules, and returns allow/deny/ask decisions — eliminating unnecessary permission prompts while blocking dangerous commands.
Claude Code's permission system is all-or-nothing. In the default mode, you're prompted for every shell command — even ls, cat, and grep. This creates a painful UX where you're clicking "Allow" hundreds of times per session on obviously safe commands. The alternative (yolo mode) disables all prompts, which is dangerous.
There's no middle ground: you can't say "allow git but block git push --force", or "allow ssh to my dev server but prompt for production". And compound commands like npm run build && npm test trigger a single opaque prompt with no visibility into what's actually being run.
Warden hooks into Claude Code's PreToolUse event and parses every shell command into an AST using bash-parser. This means it doesn't just see npm run build && git push --force as a single string — it walks the AST to extract each individual command, then evaluates them independently against a configurable rule engine.
This AST-based approach enables:
cat file | grep pattern | wc -l is parsed into three commands, each evaluated separately. All safe → auto-allow. One dangerous → deny the whole pipeline.git status → allow, git push --force → prompt. rm temp.txt → allow, rm -rf / → prompt. The evaluator matches against argument patterns, not just command names.ssh devserver 'cat /etc/hosts' → Warden extracts the remote command, parses it through the same pipeline, and allows it. ssh devserver 'sudo rm -rf /' → denied. Same for docker exec, kubectl exec, and sprite exec.sh -c "npm run build && npm test" → the inner command is extracted and recursively parsed/evaluated, not treated as an opaque string.NODE_ENV=production npm run build → correctly evaluates npm run build, ignoring the env prefix.$() or backticks are extracted, parsed, and recursively evaluated through the same pipeline. echo $(cat file.txt) → both echo and cat are evaluated individually. Only unparseable constructs (heredocs, complex shell syntax) fall back to prompting when askOnSubshell is enabled.The result: 100+ common dev commands auto-approved, dangerous commands auto-denied, everything else configurable — with zero changes to how you use Claude Code.
| Command | Without Warden | With Warden |
|---|---|---|
ls -la | Prompted | Auto-allowed |
cat file | grep pattern | wc -l | Prompted | Auto-allowed (3 safe commands) |
npm run build && npm test | Prompted | Auto-allowed |
git push --force origin main | Prompted | Prompted (force push is risky) |
sudo rm -rf / | Prompted | Auto-denied (sudo is blocked) |
ssh devserver cat /etc/hosts | Prompted | Auto-allowed (trusted host + safe cmd) |
ssh devserver sudo rm -rf / | Prompted | Auto-denied (trusted host + dangerous cmd) |
Claude Code recently introduced Auto Mode, which uses a background classifier model to approve or block actions without manual prompts. Here's how it compares to Warden: