Skip to content

feat(plugins): Add destructive-command-guardrails plugin#30261

Open
stevenelliottjr wants to merge 1 commit intoanthropics:mainfrom
stevenelliottjr:feat/destructive-command-guardrails
Open

feat(plugins): Add destructive-command-guardrails plugin#30261
stevenelliottjr wants to merge 1 commit intoanthropics:mainfrom
stevenelliottjr:feat/destructive-command-guardrails

Conversation

@stevenelliottjr
Copy link

@stevenelliottjr stevenelliottjr commented Mar 3, 2026

Summary

  • Adds a PreToolUse hook plugin that intercepts destructive shell commands before execution, preventing accidental data loss during autonomous agent sessions
  • Covers 23 detection rules across filesystem deletion (rm -rf, find -delete), git operations (reset --hard, push --force, clean -fd), SQL (DROP TABLE, TRUNCATE, DELETE FROM without WHERE), Docker (volume prune, system prune -a), system-level (mkfs, dd of=/dev/, sudo + destructive), and environment/config destruction
  • Includes smart allowlisting for safe patterns: build artifact cleanup (node_modules, dist, build, __pycache__), temp directories, git dry-runs, filtered Docker prunes, and specific PID kills
  • Handles chained commands — splits on &&, ||, ;, and | to catch destructive subcommands embedded in pipelines
  • Logs all blocked commands to ~/.claude/security-logs/guardrails-YYYY-MM-DD.jsonl with structured JSON entries (timestamp, rule, severity, command, session info)

Motivation

Multiple real-world incidents where agents autonomously executed destructive commands:

This plugin adds a safety net at the PreToolUse stage — every Bash tool call is checked against known destructive patterns before execution.

Test plan

  • 70 test cases covering all 23 rules, 5 allowlist patterns, chained commands, and edge cases
  • Run: python3 plugins/destructive-command-guardrails/tests/test_guardrails.py
  • Install plugin and verify it blocks rm -rf / in a live session
  • Verify allowlisted commands (rm -rf node_modules) pass through
  • Verify security log file is created and populated on block

PreToolUse hook that intercepts dangerous shell commands before execution,
preventing accidental data loss from autonomous agent actions. Addresses
multiple reported incidents of rm -rf, git reset --hard, DROP TABLE, and
similar commands causing irreversible damage during agent sessions.

- 23 detection rules across filesystem, git, SQL, Docker, and system categories
- Smart allowlisting for safe patterns (build artifact cleanup, temp dirs, dry-runs)
- Chained command support (splits on &&, ||, ;, |)
- Security logging to ~/.claude/security-logs/
- 70 tests covering all rules, allowlist, edge cases, and chained commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant