Skills DirectoryCurated open-source Skills from GitHub

git-guardrails-claude-codecommit 3216582SKILL.md · Hardening

Git Guardrails for Claude Code

Sets up a Claude Code PreToolUse hook that blocks dangerous git commands such as push, reset --hard, clean and branch -D before they run.

Changes Claude Code hook settings (project or global), after which Claude can no longer run git push and the other blocked commands.

npx skills add mattpocock/skills --skill git-guardrails-claude-code
Permissions
  • read-repo
  • write-files
  • shell
  • network
Compatible with
Claude Code, Codex, Copilot, Gemini CLI
GitHub
308.7k
Source
Community · Matt Pocock
Status
Scan passed
License
MIT
Category
Hardening

Core rule

If the settings file already exists, merge the hook into hooks.PreToolUse and never overwrite other settings.

Execution Phases

  1. Phase 01Ask scope

    Ask whether to install for this project only (.claude/settings.json) or for all projects (~/.claude/settings.json).

  2. Phase 02Copy the hook script

    Copy the bundled block-dangerous-git.sh to .claude/hooks/ or ~/.claude/hooks/ and make it executable with chmod +x.

  3. Phase 03Add hook to settings

    Register a PreToolUse hook with matcher Bash in the matching settings.json, merging it with any existing hooks.

  4. Phase 04Customize patterns

    Ask whether to add or remove blocked patterns and edit the copied script accordingly.

  5. Phase 05Verify

    Pipe a sample git push request into the script; it should exit with code 2 and print a BLOCKED message to stderr.

Permissions (summarised from SKILL.md)

CapabilityNeededDetails
File writesLimitedOnly writes the hook script under .claude/hooks/ and the matching settings.json.
Command executionLimitedOnly runs chmod +x and a test invocation of the hook script.
Network outboundNot requiredNo network access is needed.

SKILL.md frontmatter (YAML)

SKILL.md frontmatter (YAML)commit 3216582
---
name: git-guardrails-claude-code
description: 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.
---

Related skills

A rule scan cannot catch every risk. Read this skill's SKILL.md and check its permissions before installing.