@bifrostlabs/claude-shield
v1.0.0
Published
Security & protection hooks for Claude Code — blocks destructive commands, protects sensitive files, audit trail
Maintainers
Readme
@bifrostlabs/claude-shield
Security and protection hooks for Claude Code. Blocks destructive commands, protects sensitive files, prevents force pushes to protected branches, and maintains a full audit trail — all through Claude Code's hook system.
Features
- Destructive command blocking — catches
rm -rf,DROP TABLE,git reset --hard,chmod 777, and more - Sensitive file protection — blocks writes to
.env,*.pem,*.key, credentials files, SSH keys - Force push prevention — blocks
git push --forceto protected branches (main/master by default) - Full audit trail — SQLite-backed logging of every blocked action and tool execution
- Custom rules — add your own blocked commands, protected files, and protected branches via config
- Zero config start — ships with sensible defaults, customize via JSON config
Quick Start
npm install @bifrostlabs/claude-shieldAdd hooks to your Claude Code settings.json:
{
"hooks": {
"PreToolUse": [{ "command": "claude-shield-pre-tool" }],
"PostToolUse": [{ "command": "claude-shield-post-tool" }]
}
}Configuration
Config lives at ~/.claude-shield/config.json (auto-created on first run):
{
"enabled": true,
"block_destructive_commands": true,
"block_protected_files": true,
"block_force_push": true,
"audit_logging": true,
"audit_retention_days": 30,
"blocked_commands": [],
"protected_files": [],
"protected_branches": ["main", "master"]
}Custom Rules
Add your own patterns:
{
"blocked_commands": ["docker system prune", "kubectl delete namespace"],
"protected_files": ["*.tfstate", "production.yml"],
"protected_branches": ["main", "master", "release/*"]
}What Gets Blocked
Destructive Commands
rm -rf, DROP TABLE, DROP DATABASE, TRUNCATE TABLE, git reset --hard, git clean -f, git checkout ., git restore ., chmod 777, mkfs.*, writes to /dev/sd*, git commit --no-verify
Protected Files
.env, .env.*, credentials.*, *.pem, *.key, *.p12, *.pfx, id_rsa, id_ed25519, *.keystore, secrets.*, service-account*.json, firebase-adminsdk*.json, .npmrc, .pypirc
Force Push
git push --force and git push -f to protected branches (main/master by default)
API
import {
checkBlockedCommand,
checkProtectedFile,
loadConfig,
recentBlocked,
recentAudit,
} from "@bifrostlabs/claude-shield";
const config = loadConfig();
// Check if a command would be blocked
const result = checkBlockedCommand("rm -rf /", config);
// { blocked: true, ruleType: "destructive_command", ... }
// Check if a file write would be blocked
const fileResult = checkProtectedFile(".env.production", config);
// { blocked: true, ruleType: "protected_file", ... }How It Works
- PreToolUse hook intercepts Bash commands and file writes before execution — blocks if they match destructive patterns or target protected files
- PostToolUse hook logs all tool executions to the audit database for compliance and review
License
MIT
