Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
dcg
description
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.
DCG — Destructive Command Guard
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.
Why This Exists
AI coding agents are powerful but fallible. They can accidentally run destructive commands:
"Let me clean up the build artifacts" → rm -rf ./src (typo)
"I'll reset to the last commit" → git reset --hard (destroys uncommitted changes)
"Let me fix the merge conflict" → git checkout -- . (discards all modifications)
Unrecognized commands are allowed by default. This ensures:
The hook never breaks legitimate workflows
Only known dangerous patterns are blocked
New git commands work until explicitly categorized
3. Zero False Negatives Philosophy
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.
What It Blocks
Git Commands That Destroy Uncommitted Work
Command
Reason
git reset --hard
Destroys uncommitted changes
git reset --merge
Destroys uncommitted changes
git checkout -- <file>
Discards file modifications
git restore <file> (without --staged)
Discards uncommitted changes
git clean -f
Permanently deletes untracked files
Git Commands That Destroy Remote History
Command
Reason
git push --force / -f
Overwrites remote commits
git branch -d, --delete, -D, -f, -M, -C
Deletes or force-overwrites a user-owned branch ref
Replace /absolute/path/to/dcg with the exact resolved binary path. Do not use
bare dcg: non-interactive hook shells may not inherit the interactive
PATH. On native Windows, use install.ps1 so the hook receives the
PowerShell-safe absolute command and explicit shell selection.
Important: Restart Claude Code after adding the hook.
Strips absolute paths: /usr/bin/git status → git status
Preserves argument paths
Stage 3: Quick Rejection Filter
SIMD-accelerated substring search for "git" or "rm"
Commands without these bypass regex entirely (99%+ of commands)
Stage 4: Pattern Matching
Safe patterns checked first (short-circuit on match → allow)
Destructive patterns checked second (match → deny)
No match → default allow
Exit Codes
Code
Meaning
0
Command is safe, proceed
2
Command is blocked, do not execute
CLI Usage
Test commands manually:
# Show version with build metadata
dcg --version
# Test a commandecho'{"tool_name":"Bash","tool_input":{"command":"git reset --hard"}}' | dcg
Example Block Message
════════════════════════════════════════════════════════════════════════
BLOCKED dcg
────────────────────────────────────────────────────────────────────────
Reason: git reset --hard destroys uncommitted changes. Use 'git stash' first.
Command: git reset --hard HEAD~1
Tip: If you need to run this command, execute it manually in a terminal.
Consider using 'git stash' first to save your changes.
════════════════════════════════════════════════════════════════════════
Contextual Suggestions
Command Type
Suggestion
git reset, git checkout --
"Consider using 'git stash' first"
git clean
"Use 'git clean -n' first to preview"
git push --force
"Consider using '--force-with-lease'"
rm -rf
"Verify the path carefully before running manually"
Result: Sub-millisecond execution for typical commands.
Pattern Counts
Type
Count
Safe patterns (whitelist)
34
Destructive patterns (blacklist)
16
Security Considerations
What DCG Protects Against
Accidental data loss from git checkout -- or git reset --hard
Remote history destruction from force pushes
Stash loss from git stash drop/clear
Filesystem accidents from rm -rf outside temp directories
What DCG Does NOT Protect Against
Malicious actors (can bypass the hook)
Non-Bash commands (Python/JavaScript file writes, API calls)
Committed but unpushed work
Commands inside scripts (./deploy.sh contents not inspected)
Threat Model
DCG assumes the AI agent is well-intentioned but fallible. It catches honest mistakes, not adversarial attacks.
Troubleshooting
Hook not blocking commands
Verify ~/.claude/settings.json has hook configuration
Restart Claude Code
Test manually: echo '{"tool_name":"Bash","tool_input":{"command":"git reset --hard"}}' | dcg
Hook blocking safe commands
Check if there's an edge case not covered
File a GitHub issue
Temporary bypass: DCG_BYPASS=1 or run command manually
FAQ
Q: Why block both git branch -d and git branch -D?
Lowercase -d checks merge state, but still removes the branch name, upstream-tracking configuration, and convenient reflog reference. Those are user-owned state, so every delete form requires explicit approval. Review first with git branch -vv, git branch --merged, and git branch --no-merged.
Q: Why is git push --force-with-lease allowed?
Force-with-lease refuses to push if the remote has commits you haven't seen, preventing accidental overwrites.
Q: Why block all rm -rf outside temp directories?
Recursive forced deletion is extremely dangerous. A typo or wrong variable can delete critical files. Temp directories are designed to be ephemeral.
Q: What if I really need to run a blocked command?
DCG instructs the agent to ask for permission. Run the command manually in a separate terminal after making a conscious decision.