feat(plugins): Add destructive-command-guardrails plugin#30261
Open
stevenelliottjr wants to merge 1 commit intoanthropics:mainfrom
Open
feat(plugins): Add destructive-command-guardrails plugin#30261stevenelliottjr wants to merge 1 commit intoanthropics:mainfrom
stevenelliottjr wants to merge 1 commit intoanthropics:mainfrom
Conversation
This was referenced Mar 3, 2026
Open
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
04adb78 to
9f1eb6b
Compare
This was referenced Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rm -rf,find -delete), git operations (reset --hard,push --force,clean -fd), SQL (DROP TABLE,TRUNCATE,DELETE FROMwithout WHERE), Docker (volume prune,system prune -a), system-level (mkfs,dd of=/dev/,sudo+ destructive), and environment/config destructionnode_modules,dist,build,__pycache__), temp directories, git dry-runs, filtered Docker prunes, and specific PID kills&&,||,;, and|to catch destructive subcommands embedded in pipelines~/.claude/security-logs/guardrails-YYYY-MM-DD.jsonlwith structured JSON entries (timestamp, rule, severity, command, session info)Motivation
Multiple real-world incidents where agents autonomously executed destructive commands:
rm -rf /instead ofrm -rf ./dist([Opus 4.6] Claude Code deleted all personal files with find / -delete during security test execution #28521)Remove-Item -Recurse -Forcetraversing NTFS junctions ([MODEL] Claude Code CLI executed Remove-Item -Recurse -Force on pnpm worktrees, triggering catastrophic NTFS junction traversal — permanent deletion of user profile folders and source code #29249)git clean -fdwiping gitignored files (Claude Code destroyed gitignored files with unnecessary git clean -fd during branch creation #29179)find / -deleteduring security testing ([Opus 4.6] Claude Code deleted all personal files with find / -delete during security test execution #28521)rmwiping project files ([BUG] Critical Bug: Claude Code executed 'rm -rf' and deleted project files unexpectedly #29082)This plugin adds a safety net at the PreToolUse stage — every Bash tool call is checked against known destructive patterns before execution.
Test plan
python3 plugins/destructive-command-guardrails/tests/test_guardrails.pyrm -rf /in a live sessionrm -rf node_modules) pass through