Back to Skills

git-guardrails-claude-code

Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.

46,451stars3,771forksUpdated 4/30/2026

Security Assessment

Safe(100/100)
Security Score100/100

About git-guardrails-claude-code

The git-guardrails-claude-code skill is designed to enhance safety when using Claude Code by intercepting and blocking potentially destructive Git commands before they execute. By setting up PreToolUse hooks, this skill prevents operations such as forced pushes, hard resets, branch deletions, and file cleanups that could result in loss of work or repository corruption. It provides an additional layer of protection, ensuring that users do not accidentally execute commands that could compromise project integrity, especially in collaborative or production environments.

The main capabilities of this skill include blocking specific dangerous Git commands such as `git push` (including `--force`), `git reset --hard`, `git clean -f` or `git clean -fd`, `git branch -D`, and `git checkout .` or `git restore .`. It provides clear feedback to Claude Code whenever a blocked command is attempted, notifying it that it does not have permission to execute the command. The skill also allows for flexible installation, either on a per-project basis or globally across all projects. Users can customize the blocked command list, merging their preferences into the existing hook script without overwriting other settings, and verify functionality through a simple test command.

This skill is particularly useful for developers, DevOps engineers, and teams working with Git in Claude Code who want to enforce safe practices and prevent accidental destructive operations. It is ideal for scenarios where repository safety is critical, such as shared development environments, open-source contributions, or production deployments. By implementing these guardrails, users can confidently interact with Git, reducing the risk of accidental data loss while maintaining workflow efficiency.

FAQ

How do I install git-guardrails-claude-code for a single project versus all projects?

During setup, you are prompted to choose the scope. Selecting 'this project only' installs the hook in `.claude/settings.json` for the current project. Choosing 'all projects' installs it globally in `~/.claude/settings.json`.

Which Git commands are blocked by this skill?

It blocks `git push` (including `--force`), `git reset --hard`, `git clean -f` or `git clean -fd`, `git branch -D`, and `git checkout .` or `git restore .` to prevent destructive operations.

Can I customize the list of blocked commands?

Yes. During setup, you are asked if you want to add or remove patterns from the blocked list. You can edit the copied hook script accordingly.

Will installing this skill overwrite my existing hooks or settings?

No. If the settings file already exists, the skill merges the new hook into the existing `hooks.PreToolUse` array, preserving other settings.

How can I verify that the hook is working correctly?

You can run a test command by echoing a JSON command to the script, for example: `echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>`. It should exit with code 2 and print a BLOCKED message to stderr.

All Files

2 files
scripts/block-dangerous-git.sh0.5 KB
View
SKILL.md2.3 KB
View

Install git-guardrails-claude-code

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill