destructive_command_guard: a high-performance safety hook that blocks destructive commands from AI coding agents

destructive_command_guard: a high-performance safety hook that blocks destructive commands from AI coding agents

What it solves

AI coding agents (such as Claude Code, Cursor, and GitHub Copilot) can occasionally execute catastrophic commands—like rm -rf ./src or DROP TABLE users—that destroy uncommitted work or production data in seconds. dcg provides a safety layer that intercepts these destructive commands before they are executed.

How it works

It acts as a high-performance hook that intercepts commands from AI agents. It uses SIMD-accelerated filtering and a dual regex engine to scan commands, including those embedded in heredocs or inline scripts (e.g., python -c "os.remove(...)"). The tool classifies the context to avoid blocking safe data operations (like grep "rm -rf") while blocking actual execution. It is designed to fail-open, ensuring that timeouts or parse errors do not block the user's workflow.

Who it’s for

Developers using AI coding agents who want to prevent accidental data loss or system destruction caused by agent-generated shell commands.

Highlights

  • Broad Agent Support: Compatible with Claude Code, Codex CLI, Gemini CLI, Copilot, Cursor, Hermes Agent, Grok, and more.
  • Extensive Security Packs: Over 50 modular packs covering databases (PostgreSQL, MongoDB), cloud providers (AWS, GCP, Azure), containers (Docker, Kubernetes), and infrastructure (Terraform, Pulumi).
  • Sub-Millisecond Latency: High-performance Rust implementation ensures the guard does not slow down the agent's response time.
  • Smart Context Detection: Distinguishes between commands being executed and commands being mentioned as data.
  • Flexible Bypass: Offers multiple ways to allow commands, including environment variables (DCG_BYPASS=1), one-time allow-codes, and permanent allowlists.
  • CI Integration: Includes a scan mode for use in pre-commit hooks and CI pipelines to catch dangerous commands during code review.

Sources