Issue closed - please delete

Status Fixed / completed
Maintainer reply None cached
Activity 4 comments · opened Mar 19, 2026 · closed Mar 29, 2026

This issue was created automatically without the account owner's consent. All content has been removed for privacy reasons. Please delete this issue entirely. Thank you.

View original on GitHub ↗

4 Comments

yurukusa · 6 months ago

This is exactly the scenario that destructive-guard hooks are designed to prevent. A PreToolUse hook can block file operations targeting paths outside the project directory:

#!/bin/bash
# scope-guard.sh — block file operations outside project directory
INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
[[ "$TOOL" != "Bash" || -z "$CMD" ]] && exit 0

# Skip echo/printf (string output, not actual deletion)
echo "$CMD" | grep -qE '^\s*(echo|printf|cat\s*<<)' && exit 0

# Block destructive commands targeting paths outside current project
if echo "$CMD" | grep -qE '\brm\b.*(-[a-zA-Z]*r|-[a-zA-Z]*f|--recursive|--force)'; then
    TARGETS=$(echo "$CMD" | grep -oP 'rm\s+(-[a-zA-Z]+\s+)*\K.*')
    for target in $TARGETS; do
        case "$target" in
            /*)  echo "BLOCKED: absolute path: $target" >&2; exit 2 ;;
            ~/*)  echo "BLOCKED: home directory: $target" >&2; exit 2 ;;
            ../*)  echo "BLOCKED: parent escape: $target" >&2; exit 2 ;;
        esac
    done
fi

# Block targeting system/user directories
if echo "$CMD" | grep -qiE '(rm|del).*(Desktop|Applications|Documents|Downloads|Library|Keychain)'; then
    echo "BLOCKED: targeting system/user directory" >&2
    exit 2
fi
exit 0

Settings:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{ "type": "command", "command": "~/.claude/hooks/scope-guard.sh" }]
    }]
  }
}

This blocks any recursive/force deletion that targets absolute paths, home directory paths, or parent directory escapes. It also specifically blocks deletion of macOS system directories like Desktop, Applications, Library, and Keychain.

For a comprehensive setup, npx cc-safe-setup installs 8 safety hooks including a destructive-guard that catches dangerous patterns automatically.

yurukusa · 6 months ago

This catastrophe would have been prevented by a hook that blocks filesystem-wide destructive commands:

INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
[ -z "$COMMAND" ] && exit 0
if echo "$COMMAND" | grep -qE 'rm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r|--recursive)'; then
    echo "BLOCKED: rm -rf is permanently disabled by safety hook." >&2
    exit 2
fi
if echo "$COMMAND" | grep -qE 'find\s+.*-delete'; then
    echo "BLOCKED: find -delete is permanently disabled." >&2
    exit 2
fi
if echo "$COMMAND" | grep -qE '(chmod|chown)\s+.*-R\s+/'; then
    echo "BLOCKED: Recursive permission change on root." >&2
    exit 2
fi
if echo "$COMMAND" | grep -qE 'dd\s+.*of=/dev/'; then
    echo "BLOCKED: dd write to device." >&2
    exit 2
fi
if echo "$COMMAND" | grep -qE 'sudo\s+rm'; then
    echo "BLOCKED: sudo rm is disabled." >&2
    exit 2
fi
exit 0
{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/catastrophic-guard.sh" }]
    }]
  }
}

This blocks rm -rf, find -delete, sudo rm, dd of=/dev/, and recursive chmod/chown on root — all the vectors that could wipe a Mac filesystem. exit 2 prevents bash from running the command. The hook runs at the process level — Claude cannot bypass it.

ghost · 6 months ago

Please delete this issue entirely. It was created automatically by a Claude Code instance without the user's knowledge or consent, and contained private business information (client names, repository details). The account owner requests complete removal of this issue including all comments. Thank you.

github-actions[bot] · 6 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.