$npx -y skills add Dicklesworthstone/agent_flywheel_clawdbot_skills_and_integrations --skill dcgDestructive Command Guard - High-performance Rust hook for Claude Code that blocks dangerous commands before execution. SIMD-accelerated, modular pack system, whitelist-first architecture. Essential safety layer for agent workflows.
| 1 | # DCG — Destructive Command Guard |
| 2 | |
| 3 | A high-performance Claude Code hook that intercepts and blocks destructive commands before they execute. Written in Rust with SIMD-accelerated filtering for sub-millisecond latency. |
| 4 | |
| 5 | ## Why This Exists |
| 6 | |
| 7 | AI coding agents are powerful but fallible. They can accidentally run destructive commands: |
| 8 | |
| 9 | - **"Let me clean up the build artifacts"** → `rm -rf ./src` (typo) |
| 10 | - **"I'll reset to the last commit"** → `git reset --hard` (destroys uncommitted changes) |
| 11 | - **"Let me fix the merge conflict"** → `git checkout -- .` (discards all modifications) |
| 12 | - **"I'll clean up untracked files"** → `git clean -fd` (permanently deletes untracked files) |
| 13 | |
| 14 | DCG intercepts dangerous commands *before* execution and blocks them with a clear explanation, giving you a chance to stash your changes first. |
| 15 | |
| 16 | ## Critical Design Principles |
| 17 | |
| 18 | ### 1. Whitelist-First Architecture |
| 19 | |
| 20 | Safe patterns are checked *before* destructive patterns. This ensures explicitly safe commands are never accidentally blocked: |
| 21 | |
| 22 | ``` |
| 23 | git checkout -b feature → Matches SAFE "checkout-new-branch" → ALLOW |
| 24 | git checkout -- file.txt → No safe match, matches DESTRUCTIVE → DENY |
| 25 | ``` |
| 26 | |
| 27 | ### 2. Fail-Safe Defaults (Default-Allow) |
| 28 | |
| 29 | Unrecognized commands are **allowed by default**. This ensures: |
| 30 | - The hook never breaks legitimate workflows |
| 31 | - Only *known* dangerous patterns are blocked |
| 32 | - New git commands work until explicitly categorized |
| 33 | |
| 34 | ### 3. Zero False Negatives Philosophy |
| 35 | |
| 36 | The pattern set prioritizes **never allowing dangerous commands** over avoiding false positives. A few extra prompts for manual confirmation are acceptable; lost work is not. |
| 37 | |
| 38 | ## What It Blocks |
| 39 | |
| 40 | ### Git Commands That Destroy Uncommitted Work |
| 41 | |
| 42 | | Command | Reason | |
| 43 | |---------|--------| |
| 44 | | `git reset --hard` | Destroys uncommitted changes | |
| 45 | | `git reset --merge` | Destroys uncommitted changes | |
| 46 | | `git checkout -- <file>` | Discards file modifications | |
| 47 | | `git restore <file>` (without `--staged`) | Discards uncommitted changes | |
| 48 | | `git clean -f` | Permanently deletes untracked files | |
| 49 | |
| 50 | ### Git Commands That Destroy Remote History |
| 51 | |
| 52 | | Command | Reason | |
| 53 | |---------|--------| |
| 54 | | `git push --force` / `-f` | Overwrites remote commits | |
| 55 | | `git branch -D` | Force-deletes without merge check | |
| 56 | |
| 57 | ### Git Commands That Destroy Stashed Work |
| 58 | |
| 59 | | Command | Reason | |
| 60 | |---------|--------| |
| 61 | | `git stash drop` | Permanently deletes a stash | |
| 62 | | `git stash clear` | Permanently deletes all stashes | |
| 63 | |
| 64 | ### Filesystem Commands |
| 65 | |
| 66 | | Command | Reason | |
| 67 | |---------|--------| |
| 68 | | `rm -rf` (outside `/tmp`, `/var/tmp`, `$TMPDIR`) | Recursive deletion is dangerous | |
| 69 | |
| 70 | ## What It ALLOWS |
| 71 | |
| 72 | Safe operations pass through silently: |
| 73 | |
| 74 | ### Always Safe Git Operations |
| 75 | |
| 76 | `git status`, `git log`, `git diff`, `git add`, `git commit`, `git push`, `git pull`, `git fetch`, `git branch -d` (safe delete with merge check), `git stash`, `git stash pop`, `git stash list` |
| 77 | |
| 78 | ### Explicitly Safe Patterns |
| 79 | |
| 80 | | Pattern | Why Safe | |
| 81 | |---------|----------| |
| 82 | | `git checkout -b <branch>` | Creating new branches | |
| 83 | | `git checkout --orphan <branch>` | Creating orphan branches | |
| 84 | | `git restore --staged <file>` | Unstaging only, doesn't touch working tree | |
| 85 | | `git restore -S <file>` | Short flag for staged | |
| 86 | | `git clean -n` / `--dry-run` | Preview mode, no actual deletion | |
| 87 | | `rm -rf /tmp/*` | Temp directories are ephemeral | |
| 88 | | `rm -rf $TMPDIR/*` | Shell variable forms | |
| 89 | |
| 90 | ### Safe Alternative: `--force-with-lease` |
| 91 | |
| 92 | ```bash |
| 93 | git push --force-with-lease # ALLOWED - refuses if remote has unseen commits |
| 94 | git push --force # BLOCKED - can overwrite others' work |
| 95 | ``` |
| 96 | |
| 97 | ## Modular Pack System |
| 98 | |
| 99 | DCG uses a modular "pack" system to organize patterns by category: |
| 100 | |
| 101 | ### Core Packs (Always Enabled) |
| 102 | |
| 103 | | Pack | Description | |
| 104 | |------|-------------| |
| 105 | | `core.git` | Destructive git commands | |
| 106 | | `core.filesystem` | Dangerous rm -rf outside temp | |
| 107 | |
| 108 | ### Database Packs |
| 109 | |
| 110 | | Pack | Description | |
| 111 | |------|-------------| |
| 112 | | `database.postgresql` | DROP/TRUNCATE in PostgreSQL | |
| 113 | | `database.mysql` | DROP/TRUNCATE in MySQL/MariaDB | |
| 114 | | `database.mongodb` | dropDatabase, drop() | |
| 115 | | `database.redis` | FLUSHALL/FLUSHDB | |
| 116 | | `database.sqlite` | DROP in SQLite | |
| 117 | |
| 118 | ### Container Packs |
| 119 | |
| 120 | | Pack | Description | |
| 121 | |------|-------------| |
| 122 | | `containers.docker` | docker system prune, docker rm -f | |
| 123 | | `containers.compose` | docker-compose down --volumes | |
| 124 | | `containers.podman` | podman system prune | |
| 125 | |
| 126 | ### Kubernetes Packs |
| 127 | |
| 128 | | Pack | Description | |
| 129 | |------|-------------| |
| 130 | | `kubernetes.kubectl` | kubectl delete namespace | |
| 131 | | `kubernetes.helm` | helm uninstall | |
| 132 | | `kubernetes.kustomize` | kustomize delete patterns | |
| 133 | |
| 134 | ### Cloud Provider Packs |
| 135 | |
| 136 | | Pack | Description | |
| 137 | |------|-------------| |
| 138 | | `cloud.aws` | Destructive AWS CLI commands | |
| 139 | | `cloud. |