elertan

Claude Code Rm Guard — Development skill for Claude Code

Development community

Stop Claude Code from accidentally running rm -rf ~ or other catastrophic commands.

How to install Claude Code Rm Guard

This entry records only its repository, not the path inside it, so there is no exact command to give. Open elertan/claude-code-rm-guard and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What Claude Code Rm Guard does

Stop Claude Code from accidentally running rm -rf ~ or other catastrophic commands.

Alternatives in Development

  • Maestro Guard — Manage editing boundary restrictions 530 ★
  • Voice Guard — Use to check ONE already-written piece of copy against a voice guide before it ships — it spawns ONE fresh sib 130 ★
  • Check Gitignore — Check and update .gitignore to exclude Plan Cascade temporary files 123 ★

README

claude-code-rm-guard

**Important to note:** Claude Code's sandboxing feature (https://code.claude.com/docs/en/sandboxing) seems like a much better way to solve this problem, or otherwise using devcontainers. If that isn't what you want, then maybe this hook will help!

🛡️ Security hook for [Claude Code](https://docs.anthropic.com/en/docs/claude-code) that prevents destructive file operations outside your working directory.

Stop Claude from accidentally running `rm -rf ~/` or other catastrophic commands.

Quick Install

curl -fsSL https://raw.githubusercontent.com/elertan/claude-code-rm-guard/main/install.py | python3

The installer will:

  1. Download the hook to ~/.claude/hooks/validate-rm.py
  2. Add the hook configuration to ~/.claude/settings.json
  3. Optionally add ask permissions for rm/unlink/rmdir (recommended)

**Uninstall:**

curl -fsSL https://raw.githubusercontent.com/elertan/claude-code-rm-guard/main/install.py | python3 - --uninstall

Features

  • Path Validation: Blocks rm, unlink, rmdir, and shred commands targeting paths outside your project directory
  • Shell-Aware Parsing: Uses Python's shlex with punctuation_chars=True for proper handling of pipes, chains, and quoted arguments
  • Recursive Analysis: Detects dangerous commands hidden in sudo, xargs, find -exec, bash -c, and other wrappers
  • Safety-First Blocking: Commands with unresolvable paths (variables, globs, command substitution) are blocked by default
  • Zero Dependencies: Pure Python 3, no external packages required

How It Works

When Claude Code attempts to run a Bash command:

  1. Hook Receives Input: Claude Code sends JSON via stdin with tool_name, tool_input.command, and cwd
  2. Command Parsing: The script uses shlex to tokenize the command, splitting on ;, |, &&, ||
  3. Recursive Analysis: Each subcommand is analyzed, unwrapping sudo, bash -c, etc.
  4. Path Resolution: Target paths