explaingit

yodaisgaming/claude-code-command-guard

Analysis updated 2026-05-18

0JavaScriptAudience · developerComplexity · 2/5Setup · moderate

TLDR

A zero-dependency safety hook for Claude Code that blocks destructive shell commands like recursive deletes, database drops, or force pushes before they run.

Mindmap

mindmap
  root((command-guard))
    What it does
      Blocks destructive commands
      Fail-closed by default
      Compound command splitting
    Tech stack
      JavaScript
      Node.js
      Claude Code hooks
    Use cases
      Prevent rm -rf mistakes
      Block database drops
      Stop force pushes
    Audience
      Developers
      Claude Code users

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Prevent an AI coding agent from accidentally running rm -rf on important directories.

USE CASE 2

Block database drop or truncate commands before an agent executes them.

USE CASE 3

Stop force pushes to a main or default git branch from an AI agent.

USE CASE 4

Configure custom protected and safe folders for your own projects and production sites.

What is it built with?

JavaScriptNode.jsClaude Code hooks

How does it compare?

yodaisgaming/claude-code-command-guard00kaku/gallery-slider-block0xkinno/vellum
Stars00
LanguageJavaScriptJavaScriptJavaScript
Last pushed2021-05-19
MaintenanceDormant
Setup difficultymoderateeasyhard
Complexity2/52/54/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires Node.js 18+ and correctly registering an absolute path in Claude Code's settings.json hooks config.

In plain English

claude-code-command-guard is a small safety tool for Claude Code, an AI coding agent, that steps in before the agent runs a shell command and blocks the ones that could cause serious, unrecoverable damage. Examples include deleting an entire home directory, dropping a database table, wiping a disk, or force pushing over the main branch of a git repository. It works as a single JavaScript file with no external dependencies, plugged into a feature of Claude Code called a PreToolUse hook that runs right before any command executes. The tool is designed around the idea that agents rarely destroy things on purpose. Damage usually happens because a file path expanded incorrectly, a variable was empty, or the model matched the general shape of a command without checking exactly what it targets. To catch this reliably, the guard splits apart compound commands joined with things like double ampersands, and it looks inside commands that run other commands, such as one passed to bash minus c, rather than only checking the surface text. When it cannot confidently understand a command, it denies it by default rather than letting it through, since the author considers a false block far less costly than an accidental deletion. The author is explicit that this tool defends against accidental self inflicted damage from a cooperative agent, not against a determined attacker deliberately trying to hide a dangerous command, which is a different problem needing sandboxing and restricted credentials instead. Out of the box, with no setup, it already blocks deletion of common sensitive locations like the home directory, drive roots, and folders such as dot ssh or dot git, while allowing deletion of known safe build folders like node underscore modules. Users can also define their own protected folders, such as a live production site, and their own safe folders in a small configuration file. Installing it means copying two JavaScript files into a stable location and registering the hook in a Claude Code settings file with the correct absolute path, since the tool warns that a broken or unexpanded path will cause the guard to silently never run. It requires Node.js 18 or later and works on Linux, macOS, and Windows.

Copy-paste prompts

Prompt 1
Help me install this hook into my ~/.claude/settings.json PreToolUse configuration.
Prompt 2
Explain how the compound command splitting and interpreter re-scan works.
Prompt 3
Walk me through setting up my own protectedRoots and safeRoots in guard-config.json.
Prompt 4
How do I verify the hook is actually running after I install it?

Frequently asked questions

What is claude-code-command-guard?

A zero-dependency safety hook for Claude Code that blocks destructive shell commands like recursive deletes, database drops, or force pushes before they run.

What language is claude-code-command-guard written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, Claude Code hooks.

How hard is claude-code-command-guard to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is claude-code-command-guard for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.