[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71FYMGPT6219WTM1XY6SCB1":3,"skill-same:01M71FYMGPT6219WTM1XY6SCB1":63},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":45,"repositoryHtmlUrl":46,"repositoryHomepageUrl":6,"ownerHtmlUrl":47,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":48,"install":49,"resources":62},"01M71FYMGPT6219WTM1XY6SCB1","dcg",null,"Destructive 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.","JSGforever\u002Fskillguard","JSGforever","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F85541948?v=4","01M71FQD3E132VMR5F4TAYX3YS","01M71FQD4DYW0XJ4XQ4YQH75Y9",2,"GPL-3.0","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__Dicklesworthstone--dcg\u002FSKILL.md",[],[5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],"Safety","first","guard","execution","simd","system","for","essential","hook","layer","commands","modular","command","architecture","code","workflows","high-performance","rust","performance","2026-11-10 10:12:30",false,"---\nname: dcg\ndescription: \"Destructive 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.\"\n---\n\n# DCG — Destructive Command Guard\n\nA 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.\n\n## Why This Exists\n\nAI coding agents are powerful but fallible. They can accidentally run destructive commands:\n\n- **\"Let me clean up the build artifacts\"** → `rm -rf .\u002Fsrc` (typo)\n- **\"I'll reset to the last commit\"** → `git reset --hard` (destroys uncommitted changes)\n- **\"Let me fix the merge conflict\"** → `git checkout -- .` (discards all modifications)\n- **\"I'll clean up untracked files\"** → `git clean -fd` (permanently deletes untracked files)\n\nDCG intercepts dangerous commands *before* execution and blocks them with a clear explanation, giving you a chance to stash your changes first.\n\n## Critical Design Principles\n\n### 1. Whitelist-First Architecture\n\nSafe patterns are checked *before* destructive patterns. This ensures explicitly safe commands are never accidentally blocked:\n\n```\ngit checkout -b feature    →  Matches SAFE \"checkout-new-branch\"  →  ALLOW\ngit checkout -- file.txt   →  No safe match, matches DESTRUCTIVE  →  DENY\n```\n\n### 2. Fail-Safe Defaults (Default-Allow)\n\nUnrecognized commands are **allowed by default**. This ensures:\n- The hook never breaks legitimate workflows\n- Only *known* dangerous patterns are blocked\n- New git commands work until explicitly categorized\n\n### 3. Zero False Negatives Philosophy\n\nThe pattern set prioritizes **never allowing dangerous commands** over avoiding false positives. A few extra prompts for manual confirmation are acceptable; lost work is not.\n\n## What It Blocks\n\n### Git Commands That Destroy Uncommitted Work\n\n| Command | Reason |\n|---------|--------|\n| `git reset --hard` | Destroys uncommitted changes |\n| `git reset --merge` | Destroys uncommitted changes |\n| `git checkout -- \u003Cfile>` | Discards file modifications |\n| `git restore \u003Cfile>` (without `--staged`) | Discards uncommitted changes |\n| `git clean -f` | Permanently deletes untracked files |\n\n### Git Commands That Destroy Remote History\n\n| Command | Reason |\n|---------|--------|\n| `git push --force` \u002F `-f` | Overwrites remote commits |\n| `git branch -D` | Force-deletes without merge check |\n\n### Git Commands That Destroy Stashed Work\n\n| Command | Reason |\n|---------|--------|\n| `git stash drop` | Permanently deletes a stash |\n| `git stash clear` | Permanently deletes all stashes |\n\n### Filesystem Commands\n\n| Command | Reason |\n|---------|--------|\n| `rm -rf` (outside `\u002Ftmp`, `\u002Fvar\u002Ftmp`, `$TMPDIR`) | Recursive deletion is dangerous |\n\n## What It ALLOWS\n\nSafe operations pass through silently:\n\n### Always Safe Git Operations\n\n`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`\n\n### Explicitly Safe Patterns\n\n| Pattern | Why Safe |\n|---------|----------|\n| `git checkout -b \u003Cbranch>` | Creating new branches |\n| `git checkout --orphan \u003Cbranch>` | Creating orphan branches |\n| `git restore --staged \u003Cfile>` | Unstaging only, doesn't touch working tree |\n| `git restore -S \u003Cfile>` | Short flag for staged |\n| `git clean -n` \u002F `--dry-run` | Preview mode, no actual deletion |\n| `rm -rf \u002Ftmp\u002F*` | Temp directories are ephemeral |\n| `rm -rf $TMPDIR\u002F*` | Shell variable forms |\n\n### Safe Alternative: `--force-with-lease`\n\n```bash\ngit push --force-with-lease   # ALLOWED - refuses if remote has unseen commits\ngit push --force              # BLOCKED - can overwrite others' work\n```\n\n## Modular Pack System\n\nDCG uses a modular \"pack\" system to organize patterns by category:\n\n### Core Packs (Always Enabled)\n\n| Pack | Description |\n|------|-------------|\n| `core.git` | Destructive git commands |\n| `core.filesystem` | Dangerous rm -rf outside temp |\n\n### Database Packs\n\n| Pack | Description |\n|------|-------------|\n| `database.postgresql` | DROP\u002FTRUNCATE in PostgreSQL |\n| `database.mysql` | DROP\u002FTRUNCATE in MySQL\u002FMariaDB |\n| `database.mongodb` | dropDatabase, drop() |\n| `database.redis` | FLUSHALL\u002FFLUSHDB |\n| `database.sqlite` | DROP in SQLite |\n\n### Container Packs\n\n| Pack | Description |\n|------|-------------|\n| `containers.docker` | docker system prune, docker rm -f |\n| `containers.compose` | docker-compose down --volumes |\n| `containers.podman` | podman system prune |\n\n### Kubernetes Packs\n\n| Pack | Description |\n|------|-------------|\n| `kubernetes.kubectl` | kubectl delete namespace |\n| `kubernetes.helm` | helm uninstall |\n| `kubernetes.kustomize` | kustomize delete patterns |\n\n### Cloud Provider Packs\n\n| Pack | Description |\n|------|-------------|\n| `cloud.aws` | Destructive AWS CLI commands |\n| `cloud.gcp` | Destructive gcloud commands |\n| `cloud.azure` | Destructive az commands |\n\n### Infrastructure Packs\n\n| Pack | Description |\n|------|-------------|\n| `infrastructure.terraform` | terraform destroy |\n| `infrastructure.ansible` | Dangerous ansible patterns |\n| `infrastructure.pulumi` | pulumi destroy |\n\n### System Packs\n\n| Pack | Description |\n|------|-------------|\n| `system.disk` | dd, mkfs, fdisk operations |\n| `system.permissions` | Dangerous chmod\u002Fchown patterns |\n| `system.services` | systemctl stop\u002Fdisable patterns |\n\n### Other Packs\n\n| Pack | Description |\n|------|-------------|\n| `strict_git` | Extra paranoid git protections |\n| `package_managers` | npm unpublish, cargo yank |\n\n### Configuring Packs\n\n```toml\n# ~\u002F.config\u002Fdcg\u002Fconfig.toml\n[packs]\nenabled = [\n    \"database.postgresql\",\n    \"containers.docker\",\n    \"kubernetes\",  # Enables all kubernetes sub-packs\n]\n```\n\n## Environment Variables\n\n| Variable | Description |\n|----------|-------------|\n| `DCG_PACKS=\"containers.docker,kubernetes\"` | Enable packs (comma-separated) |\n| `DCG_DISABLE=\"kubernetes.helm\"` | Disable packs\u002Fsub-packs |\n| `DCG_VERBOSE=1` | Verbose output |\n| `DCG_COLOR=auto\\|always\\|never` | Color mode |\n| `DCG_BYPASS=1` | Bypass DCG entirely (escape hatch) |\n\n## Installation\n\n### Quick Install (Recommended)\n\n```bash\ncurl -fsSL \"https:\u002F\u002Fraw.githubusercontent.com\u002FDicklesworthstone\u002Fdestructive_command_guard\u002Fmaster\u002Finstall.sh?$(date +%s)\" | bash\n\n# Easy mode: auto-update PATH\ncurl -fsSL \"https:\u002F\u002Fraw.githubusercontent.com\u002FDicklesworthstone\u002Fdestructive_command_guard\u002Fmaster\u002Finstall.sh?$(date +%s)\" | bash -s -- --easy-mode\n\n# System-wide (requires sudo)\ncurl -fsSL \"https:\u002F\u002Fraw.githubusercontent.com\u002FDicklesworthstone\u002Fdestructive_command_guard\u002Fmaster\u002Finstall.sh?$(date +%s)\" | sudo bash -s -- --system\n```\n\n### From Source (Requires Rust Nightly)\n\n```bash\ncargo +nightly install --git https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fdestructive_command_guard\n```\n\n### Prebuilt Binaries\n\nAvailable for: Linux x86_64, Linux ARM64, macOS Intel, macOS Apple Silicon, Windows\n\n## Claude Code Configuration\n\nAdd to `~\u002F.claude\u002Fsettings.json`:\n\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"matcher\": \"Bash\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \"dcg\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n**Important:** Restart Claude Code after adding the hook.\n\n## How It Works\n\n### Processing Pipeline\n\n```\n┌─────────────────────────────────────────────────────────────────┐\n│                        Claude Code                               │\n│  Agent executes `rm -rf .\u002Fbuild`                                │\n└─────────────────────┬───────────────────────────────────────────┘\n                      │\n                      ▼ PreToolUse hook (stdin: JSON)\n┌─────────────────────────────────────────────────────────────────┐\n│                          dcg                                     │\n│  ┌──────────────┐    ┌──────────────┐    ┌──────────────┐       │\n│  │    Parse     │───▶│  Normalize   │───▶│ Quick Reject │       │\n│  │    JSON      │    │   Command    │    │   Filter     │       │\n│  └──────────────┘    └──────────────┘    └──────┬───────┘       │\n│                                                  │               │\n│                      ┌───────────────────────────┘               │\n│                      ▼                                           │\n│  ┌──────────────────────────────────────────────────────────┐   │\n│  │                   Pattern Matching                        │   │\n│  │   1. Check SAFE_PATTERNS (whitelist) ──▶ Allow if match  │   │\n│  │   2. Check DESTRUCTIVE_PATTERNS ──────▶ Deny if match    │   │\n│  │   3. No match ────────────────────────▶ Allow (default)  │   │\n│  └──────────────────────────────────────────────────────────┘   │\n└─────────────────────┬───────────────────────────────────────────┘\n                      │\n                      ▼ stdout: JSON (deny) or empty (allow)\n```\n\n### Stage 1: JSON Parsing\n- Reads hook input from stdin\n- Validates Claude Code's `PreToolUse` format\n- Non-Bash tools immediately allowed\n\n### Stage 2: Command Normalization\n- Strips absolute paths: `\u002Fusr\u002Fbin\u002Fgit status` → `git status`\n- Preserves argument paths\n\n### Stage 3: Quick Rejection Filter\n- SIMD-accelerated substring search for \"git\" or \"rm\"\n- Commands without these bypass regex entirely (99%+ of commands)\n\n### Stage 4: Pattern Matching\n- Safe patterns checked first (short-circuit on match → allow)\n- Destructive patterns checked second (match → deny)\n- No match → default allow\n\n## Exit Codes\n\n| Code | Meaning |\n|------|---------|\n| `0` | Command is safe, proceed |\n| `2` | Command is blocked, do not execute |\n\n## CLI Usage\n\nTest commands manually:\n\n```bash\n# Show version with build metadata\ndcg --version\n\n# Test a command\necho '{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":\"git reset --hard\"}}' | dcg\n```\n\n## Example Block Message\n\n```\n════════════════════════════════════════════════════════════════════════\nBLOCKED  dcg\n────────────────────────────────────────────────────────────────────────\nReason:  git reset --hard destroys uncommitted changes. Use 'git stash' first.\n\nCommand:  git reset --hard HEAD~1\n\nTip: If you need to run this command, execute it manually in a terminal.\n     Consider using 'git stash' first to save your changes.\n════════════════════════════════════════════════════════════════════════\n```\n\n### Contextual Suggestions\n\n| Command Type | Suggestion |\n|-------------|------------|\n| `git reset`, `git checkout --` | \"Consider using 'git stash' first\" |\n| `git clean` | \"Use 'git clean -n' first to preview\" |\n| `git push --force` | \"Consider using '--force-with-lease'\" |\n| `rm -rf` | \"Verify the path carefully before running manually\" |\n\n## Edge Cases Handled\n\n### Path Normalization\n\n```bash\n\u002Fusr\u002Fbin\u002Fgit reset --hard          # Blocked\n\u002Fusr\u002Flocal\u002Fbin\u002Fgit checkout -- .   # Blocked\n\u002Fbin\u002Frm -rf \u002Fhome\u002Fuser             # Blocked\n```\n\n### Flag Ordering Variants\n\n```bash\nrm -rf \u002Fpath          # Combined flags\nrm -fr \u002Fpath          # Reversed order\nrm -r -f \u002Fpath        # Separate flags\nrm --recursive --force \u002Fpath    # Long flags\n```\n\nAll variants are handled.\n\n### Shell Variable Expansion\n\n```bash\nrm -rf $TMPDIR\u002Fbuild           # Allowed (temp)\nrm -rf ${TMPDIR}\u002Fbuild         # Allowed\nrm -rf \"$TMPDIR\u002Fbuild\"         # Allowed\nrm -rf \"${TMPDIR:-\u002Ftmp}\u002Fbuild\" # Allowed\n```\n\n### Staged vs Worktree Restore\n\n```bash\ngit restore --staged file.txt    # Allowed (unstaging only)\ngit restore -S file.txt          # Allowed (short flag)\ngit restore file.txt             # BLOCKED (discards changes)\ngit restore --worktree file.txt  # BLOCKED (explicit worktree)\ngit restore -S -W file.txt       # BLOCKED (includes worktree)\n```\n\n## Performance Optimizations\n\nDCG is designed for zero perceived latency:\n\n| Optimization | Technique |\n|--------------|-----------|\n| **Lazy Static** | Regex patterns compiled once via `LazyLock` |\n| **SIMD Quick Reject** | `memchr` crate for CPU vector instructions |\n| **Early Exit** | Safe match returns immediately |\n| **Zero-Copy JSON** | `serde_json` operates on input buffer |\n| **Zero-Allocation** | `Cow\u003Cstr>` for path normalization |\n| **Release Profile** | `opt-level=\"z\"`, LTO, single codegen unit |\n\n**Result:** Sub-millisecond execution for typical commands.\n\n## Pattern Counts\n\n| Type | Count |\n|------|-------|\n| Safe patterns (whitelist) | 34 |\n| Destructive patterns (blacklist) | 16 |\n\n## Security Considerations\n\n### What DCG Protects Against\n\n- Accidental data loss from `git checkout --` or `git reset --hard`\n- Remote history destruction from force pushes\n- Stash loss from `git stash drop\u002Fclear`\n- Filesystem accidents from `rm -rf` outside temp directories\n\n### What DCG Does NOT Protect Against\n\n- Malicious actors (can bypass the hook)\n- Non-Bash commands (Python\u002FJavaScript file writes, API calls)\n- Committed but unpushed work\n- Commands inside scripts (`.\u002Fdeploy.sh` contents not inspected)\n\n### Threat Model\n\nDCG assumes the AI agent is **well-intentioned but fallible**. It catches honest mistakes, not adversarial attacks.\n\n## Troubleshooting\n\n### Hook not blocking commands\n\n1. Verify `~\u002F.claude\u002Fsettings.json` has hook configuration\n2. Restart Claude Code\n3. Test manually: `echo '{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":\"git reset --hard\"}}' | dcg`\n\n### Hook blocking safe commands\n\n1. Check if there's an edge case not covered\n2. File a GitHub issue\n3. Temporary bypass: `DCG_BYPASS=1` or run command manually\n\n## FAQ\n\n**Q: Why block `git branch -D` but allow `git branch -d`?**\n\nLowercase `-d` only deletes branches fully merged. Uppercase `-D` force-deletes regardless of merge status, potentially losing commits.\n\n**Q: Why is `git push --force-with-lease` allowed?**\n\nForce-with-lease refuses to push if the remote has commits you haven't seen, preventing accidental overwrites.\n\n**Q: Why block all `rm -rf` outside temp directories?**\n\nRecursive forced deletion is extremely dangerous. A typo or wrong variable can delete critical files. Temp directories are designed to be ephemeral.\n\n**Q: What if I really need to run a blocked command?**\n\nDCG instructs the agent to ask for permission. Run the command manually in a separate terminal after making a conscious decision.\n\n## Integration with Flywheel\n\n| Tool | Integration |\n|------|-------------|\n| **Claude Code** | Native PreToolUse hook |\n| **Agent Mail** | Agents can report blocked commands to coordinator |\n| **BV** | Flag tasks that repeatedly trigger DCG |\n| **CASS** | Search DCG block patterns across sessions |\n| **RU** | DCG protects agent-sweep from destructive commits |\n","# DCG — Destructive Command Guard\n\nA 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.\n\n## Why This Exists\n\nAI coding agents are powerful but fallible. They can accidentally run destructive commands:\n\n- **\"Let me clean up the build artifacts\"** → `rm -rf .\u002Fsrc` (typo)\n- **\"I'll reset to the last commit\"** → `git reset --hard` (destroys uncommitted changes)\n- **\"Let me fix the merge conflict\"** → `git checkout -- .` (discards all modifications)\n- **\"I'll clean up untracked files\"** → `git clean -fd` (permanently deletes untracked files)\n\nDCG intercepts dangerous commands *before* execution and blocks them with a clear explanation, giving you a chance to stash your changes first.\n\n## Critical Design Principles\n\n### 1. Whitelist-First Architecture\n\nSafe patterns are checked *before* destructive patterns. This ensures explicitly safe commands are never accidentally blocked:\n\n```\ngit checkout -b feature    →  Matches SAFE \"checkout-new-branch\"  →  ALLOW\ngit checkout -- file.txt   →  No safe match, matches DESTRUCTIVE  →  DENY\n```\n\n### 2. Fail-Safe Defaults (Default-Allow)\n\nUnrecognized commands are **allowed by default**. This ensures:\n- The hook never breaks legitimate workflows\n- Only *known* dangerous patterns are blocked\n- New git commands work until explicitly categorized\n\n### 3. Zero False Negatives Philosophy\n\nThe pattern set prioritizes **never allowing dangerous commands** over avoiding false positives. A few extra prompts for manual confirmation are acceptable; lost work is not.\n\n## What It Blocks\n\n### Git Commands That Destroy Uncommitted Work\n\n| Command | Reason |\n|---------|--------|\n| `git reset --hard` | Destroys uncommitted changes |\n| `git reset --merge` | Destroys uncommitted changes |\n| `git checkout -- \u003Cfile>` | Discards file modifications |\n| `git restore \u003Cfile>` (without `--staged`) | Discards uncommitted changes |\n| `git clean -f` | Permanently deletes untracked files |\n\n### Git Commands That Destroy Remote History\n\n| Command | Reason |\n|---------|--------|\n| `git push --force` \u002F `-f` | Overwrites remote commits |\n| `git branch -D` | Force-deletes without merge check |\n\n### Git Commands That Destroy Stashed Work\n\n| Command | Reason |\n|---------|--------|\n| `git stash drop` | Permanently deletes a stash |\n| `git stash clear` | Permanently deletes all stashes |\n\n### Filesystem Commands\n\n| Command | Reason |\n|---------|--------|\n| `rm -rf` (outside `\u002Ftmp`, `\u002Fvar\u002Ftmp`, `$TMPDIR`) | Recursive deletion is dangerous |\n\n## What It ALLOWS\n\nSafe operations pass through silently:\n\n### Always Safe Git Operations\n\n`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`\n\n### Explicitly Safe Patterns\n\n| Pattern | Why Safe |\n|---------|----------|\n| `git checkout -b \u003Cbranch>` | Creating new branches |\n| `git checkout --orphan \u003Cbranch>` | Creating orphan branches |\n| `git restore --staged \u003Cfile>` | Unstaging only, doesn't touch working tree |\n| `git restore -S \u003Cfile>` | Short flag for staged |\n| `git clean -n` \u002F `--dry-run` | Preview mode, no actual deletion |\n| `rm -rf \u002Ftmp\u002F*` | Temp directories are ephemeral |\n| `rm -rf $TMPDIR\u002F*` | Shell variable forms |\n\n### Safe Alternative: `--force-with-lease`\n\n```bash\ngit push --force-with-lease   # ALLOWED - refuses if remote has unseen commits\ngit push --force              # BLOCKED - can overwrite others' work\n```\n\n## Modular Pack System\n\nDCG uses a modular \"pack\" system to organize patterns by category:\n\n### Core Packs (Always Enabled)\n\n| Pack | Description |\n|------|-------------|\n| `core.git` | Destructive git commands |\n| `core.filesystem` | Dangerous rm -rf outside temp |\n\n### Database Packs\n\n| Pack | Description |\n|------|-------------|\n| `database.postgresql` | DROP\u002FTRUNCATE in PostgreSQL |\n| `database.mysql` | DROP\u002FTRUNCATE in MySQL\u002FMariaDB |\n| `database.mongodb` | dropDatabase, drop() |\n| `database.redis` | FLUSHALL\u002FFLUSHDB |\n| `database.sqlite` | DROP in SQLite |\n\n### Container Packs\n\n| Pack | Description |\n|------|-------------|\n| `containers.docker` | docker system prune, docker rm -f |\n| `containers.compose` | docker-compose down --volumes |\n| `containers.podman` | podman system prune |\n\n### Kubernetes Packs\n\n| Pack | Description |\n|------|-------------|\n| `kubernetes.kubectl` | kubectl delete namespace |\n| `kubernetes.helm` | helm uninstall |\n| `kubernetes.kustomize` | kustomize delete patterns |\n\n### Cloud Provider Packs\n\n| Pack | Description |\n|------|-------------|\n| `cloud.aws` | Destructive AWS CLI commands |\n| `cloud.gcp` | Destructive gcloud commands |\n| `cloud.azure` | Destructive az commands |\n\n### Infrastructure Packs\n\n| Pack | Description |\n|------|-------------|\n| `infrastructure.terraform` | terraform destroy |\n| `infrastructure.ansible` | Dangerous ansible patterns |\n| `infrastructure.pulumi` | pulumi destroy |\n\n### System Packs\n\n| Pack | Description |\n|------|-------------|\n| `system.disk` | dd, mkfs, fdisk operations |\n| `system.permissions` | Dangerous chmod\u002Fchown patterns |\n| `system.services` | systemctl stop\u002Fdisable patterns |\n\n### Other Packs\n\n| Pack | Description |\n|------|-------------|\n| `strict_git` | Extra paranoid git protections |\n| `package_managers` | npm unpublish, cargo yank |\n\n### Configuring Packs\n\n```toml\n# ~\u002F.config\u002Fdcg\u002Fconfig.toml\n[packs]\nenabled = [\n    \"database.postgresql\",\n    \"containers.docker\",\n    \"kubernetes\",  # Enables all kubernetes sub-packs\n]\n```\n\n## Environment Variables\n\n| Variable | Description |\n|----------|-------------|\n| `DCG_PACKS=\"containers.docker,kubernetes\"` | Enable packs (comma-separated) |\n| `DCG_DISABLE=\"kubernetes.helm\"` | Disable packs\u002Fsub-packs |\n| `DCG_VERBOSE=1` | Verbose output |\n| `DCG_COLOR=auto\\|always\\|never` | Color mode |\n| `DCG_BYPASS=1` | Bypass DCG entirely (escape hatch) |\n\n## Installation\n\n### Quick Install (Recommended)\n\n```bash\ncurl -fsSL \"https:\u002F\u002Fraw.githubusercontent.com\u002FDicklesworthstone\u002Fdestructive_command_guard\u002Fmaster\u002Finstall.sh?$(date +%s)\" | bash\n\n# Easy mode: auto-update PATH\ncurl -fsSL \"https:\u002F\u002Fraw.githubusercontent.com\u002FDicklesworthstone\u002Fdestructive_command_guard\u002Fmaster\u002Finstall.sh?$(date +%s)\" | bash -s -- --easy-mode\n\n# System-wide (requires sudo)\ncurl -fsSL \"https:\u002F\u002Fraw.githubusercontent.com\u002FDicklesworthstone\u002Fdestructive_command_guard\u002Fmaster\u002Finstall.sh?$(date +%s)\" | sudo bash -s -- --system\n```\n\n### From Source (Requires Rust Nightly)\n\n```bash\ncargo +nightly install --git https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fdestructive_command_guard\n```\n\n### Prebuilt Binaries\n\nAvailable for: Linux x86_64, Linux ARM64, macOS Intel, macOS Apple Silicon, Windows\n\n## Claude Code Configuration\n\nAdd to `~\u002F.claude\u002Fsettings.json`:\n\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"matcher\": \"Bash\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \"dcg\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n**Important:** Restart Claude Code after adding the hook.\n\n## How It Works\n\n### Processing Pipeline\n\n```\n┌─────────────────────────────────────────────────────────────────┐\n│                        Claude Code                               │\n│  Agent executes `rm -rf .\u002Fbuild`                                │\n└─────────────────────┬───────────────────────────────────────────┘\n                      │\n                      ▼ PreToolUse hook (stdin: JSON)\n┌─────────────────────────────────────────────────────────────────┐\n│                          dcg                                     │\n│  ┌──────────────┐    ┌──────────────┐    ┌──────────────┐       │\n│  │    Parse     │───▶│  Normalize   │───▶│ Quick Reject │       │\n│  │    JSON      │    │   Command    │    │   Filter     │       │\n│  └──────────────┘    └──────────────┘    └──────┬───────┘       │\n│                                                  │               │\n│                      ┌───────────────────────────┘               │\n│                      ▼                                           │\n│  ┌──────────────────────────────────────────────────────────┐   │\n│  │                   Pattern Matching                        │   │\n│  │   1. Check SAFE_PATTERNS (whitelist) ──▶ Allow if match  │   │\n│  │   2. Check DESTRUCTIVE_PATTERNS ──────▶ Deny if match    │   │\n│  │   3. No match ────────────────────────▶ Allow (default)  │   │\n│  └──────────────────────────────────────────────────────────┘   │\n└─────────────────────┬───────────────────────────────────────────┘\n                      │\n                      ▼ stdout: JSON (deny) or empty (allow)\n```\n\n### Stage 1: JSON Parsing\n- Reads hook input from stdin\n- Validates Claude Code's `PreToolUse` format\n- Non-Bash tools immediately allowed\n\n### Stage 2: Command Normalization\n- Strips absolute paths: `\u002Fusr\u002Fbin\u002Fgit status` → `git status`\n- Preserves argument paths\n\n### Stage 3: Quick Rejection Filter\n- SIMD-accelerated substring search for \"git\" or \"rm\"\n- Commands without these bypass regex entirely (99%+ of commands)\n\n### Stage 4: Pattern Matching\n- Safe patterns checked first (short-circuit on match → allow)\n- Destructive patterns checked second (match → deny)\n- No match → default allow\n\n## Exit Codes\n\n| Code | Meaning |\n|------|---------|\n| `0` | Command is safe, proceed |\n| `2` | Command is blocked, do not execute |\n\n## CLI Usage\n\nTest commands manually:\n\n```bash\n# Show version with build metadata\ndcg --version\n\n# Test a command\necho '{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":\"git reset --hard\"}}' | dcg\n```\n\n## Example Block Message\n\n```\n════════════════════════════════════════════════════════════════════════\nBLOCKED  dcg\n────────────────────────────────────────────────────────────────────────\nReason:  git reset --hard destroys uncommitted changes. Use 'git stash' first.\n\nCommand:  git reset --hard HEAD~1\n\nTip: If you need to run this command, execute it manually in a terminal.\n     Consider using 'git stash' first to save your changes.\n════════════════════════════════════════════════════════════════════════\n```\n\n### Contextual Suggestions\n\n| Command Type | Suggestion |\n|-------------|------------|\n| `git reset`, `git checkout --` | \"Consider using 'git stash' first\" |\n| `git clean` | \"Use 'git clean -n' first to preview\" |\n| `git push --force` | \"Consider using '--force-with-lease'\" |\n| `rm -rf` | \"Verify the path carefully before running manually\" |\n\n## Edge Cases Handled\n\n### Path Normalization\n\n```bash\n\u002Fusr\u002Fbin\u002Fgit reset --hard          # Blocked\n\u002Fusr\u002Flocal\u002Fbin\u002Fgit checkout -- .   # Blocked\n\u002Fbin\u002Frm -rf \u002Fhome\u002Fuser             # Blocked\n```\n\n### Flag Ordering Variants\n\n```bash\nrm -rf \u002Fpath          # Combined flags\nrm -fr \u002Fpath          # Reversed order\nrm -r -f \u002Fpath        # Separate flags\nrm --recursive --force \u002Fpath    # Long flags\n```\n\nAll variants are handled.\n\n### Shell Variable Expansion\n\n```bash\nrm -rf $TMPDIR\u002Fbuild           # Allowed (temp)\nrm -rf ${TMPDIR}\u002Fbuild         # Allowed\nrm -rf \"$TMPDIR\u002Fbuild\"         # Allowed\nrm -rf \"${TMPDIR:-\u002Ftmp}\u002Fbuild\" # Allowed\n```\n\n### Staged vs Worktree Restore\n\n```bash\ngit restore --staged file.txt    # Allowed (unstaging only)\ngit restore -S file.txt          # Allowed (short flag)\ngit restore file.txt             # BLOCKED (discards changes)\ngit restore --worktree file.txt  # BLOCKED (explicit worktree)\ngit restore -S -W file.txt       # BLOCKED (includes worktree)\n```\n\n## Performance Optimizations\n\nDCG is designed for zero perceived latency:\n\n| Optimization | Technique |\n|--------------|-----------|\n| **Lazy Static** | Regex patterns compiled once via `LazyLock` |\n| **SIMD Quick Reject** | `memchr` crate for CPU vector instructions |\n| **Early Exit** | Safe match returns immediately |\n| **Zero-Copy JSON** | `serde_json` operates on input buffer |\n| **Zero-Allocation** | `Cow\u003Cstr>` for path normalization |\n| **Release Profile** | `opt-level=\"z\"`, LTO, single codegen unit |\n\n**Result:** Sub-millisecond execution for typical commands.\n\n## Pattern Counts\n\n| Type | Count |\n|------|-------|\n| Safe patterns (whitelist) | 34 |\n| Destructive patterns (blacklist) | 16 |\n\n## Security Considerations\n\n### What DCG Protects Against\n\n- Accidental data loss from `git checkout --` or `git reset --hard`\n- Remote history destruction from force pushes\n- Stash loss from `git stash drop\u002Fclear`\n- Filesystem accidents from `rm -rf` outside temp directories\n\n### What DCG Does NOT Protect Against\n\n- Malicious actors (can bypass the hook)\n- Non-Bash commands (Python\u002FJavaScript file writes, API calls)\n- Committed but unpushed work\n- Commands inside scripts (`.\u002Fdeploy.sh` contents not inspected)\n\n### Threat Model\n\nDCG assumes the AI agent is **well-intentioned but fallible**. It catches honest mistakes, not adversarial attacks.\n\n## Troubleshooting\n\n### Hook not blocking commands\n\n1. Verify `~\u002F.claude\u002Fsettings.json` has hook configuration\n2. Restart Claude Code\n3. Test manually: `echo '{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":\"git reset --hard\"}}' | dcg`\n\n### Hook blocking safe commands\n\n1. Check if there's an edge case not covered\n2. File a GitHub issue\n3. Temporary bypass: `DCG_BYPASS=1` or run command manually\n\n## FAQ\n\n**Q: Why block `git branch -D` but allow `git branch -d`?**\n\nLowercase `-d` only deletes branches fully merged. Uppercase `-D` force-deletes regardless of merge status, potentially losing commits.\n\n**Q: Why is `git push --force-with-lease` allowed?**\n\nForce-with-lease refuses to push if the remote has commits you haven't seen, preventing accidental overwrites.\n\n**Q: Why block all `rm -rf` outside temp directories?**\n\nRecursive forced deletion is extremely dangerous. A typo or wrong variable can delete critical files. Temp directories are designed to be ephemeral.\n\n**Q: What if I really need to run a blocked command?**\n\nDCG instructs the agent to ask for permission. Run the command manually in a separate terminal after making a conscious decision.\n\n## Integration with Flywheel\n\n| Tool | Integration |\n|------|-------------|\n| **Claude Code** | Native PreToolUse hook |\n| **Agent Mail** | Agents can report blocked commands to coordinator |\n| **BV** | Flag tasks that repeatedly trigger DCG |\n| **CASS** | Search DCG block patterns across sessions |\n| **RU** | DCG protects agent-sweep from destructive commits |\n",{"name":5,"description":7},"main","f2ec4b3b9133d34eeaf9b38e4b0a97e8e5705a7f","benchmarks\u002Ffinal\u002Fskills\u002Fasset1__Dicklesworthstone--dcg",0,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard","https:\u002F\u002Fgithub.com\u002FJSGforever","2026-08-29 18:27:56",{"source":8,"skillName":5,"commands":50,"prompt":60,"zipAvailable":61},[51,54,57],{"tool":52,"command":53},"npx","npx skills add JSGforever\u002Fskillguard --skill dcg",{"tool":55,"command":56},"bunx","bunx skills add JSGforever\u002Fskillguard --skill dcg",{"tool":58,"command":59},"pnpm","pnpm dlx skills add JSGforever\u002Fskillguard --skill dcg","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__Dicklesworthstone--dcg\u002FSKILL.md",true,[],[64,91,102,128,146,166],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":37},"01M71HY2SNXBA9Q00WZDTZQ31Z","skillguard-codex-scanner","Hybrid deterministic+LLM agent-skill security scanner. Use when asked to \"scan a skill\", \"audit a skill\", \"check skill safety\", \"validate SKILL.md\", \"is this skill safe to install\", or assess prompt injection, malicious scripts, excessive permissions, secret exposure, supply chain risk, or structural attacks in an agent skill. Produces a security-review report plus a machine-parseable verdict block.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fsrc\u002Fskillguard\u002Fstatic_scanner\u002Fskillguard-codex-scanner\u002FSKILL.md",[],[71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90],"scanner","skillguard codex scanner","skillguard","codex","chain","skill security","security-review","review report","structural","secret","prompt injection","security scanner","when","review","malicious","permissions","exposure","audit","scripts","safe",{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":95,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":37},"01M71HY0SPKTT3S27BC2HPAC5M","data-exfiltrator","Analyzes data files","MIT","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Fsmoke-one-skill\u002Fasset1__cisco-ai-defense--data-exfiltrator\u002FSKILL.md",[],[99,100,101],"data","data exfiltrator","files",{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":37},"01M71HXVS9EMN44BGDW215FZ72","real-time-collaboration-engine","Build real-time collaborative editing with WebSockets, OT\u002FCRDT conflict resolution, and presence awareness. Implements cursor tracking, optimistic updates, and offline sync. Use for collaborative editors, whiteboards, video editing. Activate on \"real-time collaboration\", \"WebSocket sync\", \"multiplayer editing\", \"CRDT\", \"presence awareness\". NOT for simple chat, request-response APIs, or single-user apps.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--real-time-collaboration-engine\u002FSKILL.md",[],[109,110,111,112,113,114,115,116,117,36,118,119,120,121,122,123,124,125,126,127],"time","real time collaboration engine","real time collaboration","collaboration","engine","real time","Video","reliability","video editing","conflict resolution","presence","access","apps","updates","Bash","activate","optimizer","react","streaming",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":37},"01M71HXP6CTY4KFN0QVMMN0V7J","react-performance-optimizer","Optimize React apps for 60fps performance. Implements memoization, virtualization, code splitting, bundle optimization. Use for slow renders, large lists, bundle bloat. Activate on \"React performance\", \"slow render\", \"useMemo\", \"bundle size\", \"virtualization\". NOT for backend optimization, non-React frameworks, or premature optimization.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--react-performance-optimizer\u002FSKILL.md",[],[36,135,125,126,136,137,138,139,140,141,109,142,143,121,123,32,124,127,144,145],"react performance optimizer","react performance","performance optimizer","app","nextjs","expert","re","render","2025","router","strategies",{"skillNo":147,"name":148,"nameZh":6,"description":149,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":150,"categories":151,"keywords":152,"publishedAt":37},"01M71HXH7QXSQB4QTDZ7SP7YXQ","llm-streaming-response-handler","Build production LLM streaming UIs with Server-Sent Events, real-time token display, cancellation, error recovery. Handles OpenAI\u002FAnthropic\u002FClaude streaming APIs. Use for chatbots, AI assistants, real-time text generation. Activate on \"LLM streaming\", \"SSE\", \"token stream\", \"chat UI\", \"real-time AI\". NOT for batch processing, non-streaming APIs, or WebSocket bidirectional chat.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--llm-streaming-response-handler\u002FSKILL.md",[],[153,127,154,155,156,157,36,109,158,159,160,123,124,125,161,126,162,163,164,165],"llm streaming response handler","handler","error","processing","retry","chat ui","error recovery","critical","batch","display","text","server","read",{"skillNo":167,"name":168,"nameZh":6,"description":169,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":170,"categories":171,"keywords":172,"publishedAt":37},"01M71HXCB0E1YRKYW1Y8T0Y106","github-actions-pipeline-builder","Build production CI\u002FCD pipelines with GitHub Actions. Implements matrix builds, caching, deployments, testing, security scanning. Use for automated testing, deployments, release workflows. Activate on \"GitHub Actions\", \"CI\u002FCD\", \"workflow\", \"deployment pipeline\", \"automated testing\". NOT for Jenkins\u002FCircleCI, manual deployments, or non-GitHub repositories.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--github-actions-pipeline-builder\u002FSKILL.md",[],[173,174,175,176,177,178,179,116,140,180,181,33,124,145,182,165,183,184,185,186],"github actions pipeline builder","actions","github actions","pipeline builder","github","builder","pipeline","testing","ci","run","release","write","edit","git"]