Skill Tracer
Skills › Skills For Real Engineers › git-guardrails-claude-code

git-guardrails-claude-code

skill · 95 lines · MIT · skills/misc/git-guardrails-claude-code/SKILL.md

The facts

Its 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.

The description the agent reads to decide when to use it.

From its settingsline 3

When it starts

The agent picks this when someone wants to stop Claude Code from running destructive git commands — push, reset --hard, clean, branch -D, checkout . — by installing a PreToolUse hook. It is a one-off setup task for a project or for all projects, not a code-change task.

Things a person might say (the model's guesses)

  • “Can you make sure Claude never runs git push in this repo?”
  • “Set up a hook that blocks git reset --hard and git clean -fd before they execute.”
  • “I want git safety guardrails installed for all my projects, not just this one.”

A model's summary of when it is used.

A model's reading

Runs scripts

scripts/block-dangerous-git.sh

Scripts the text names. Found by matching words, so treat them as pointers.

Found by matching wordsline 28

Files it mentions

scripts/block-dangerous-git.sh

Files the text names, such as ones to read or write. Found by matching words, so treat them as pointers.

Found by matching wordsline 28

Stops for a person

1 line stops to ask a person

Lines that stop and wait for a person before going on. Found by matching words, so treat them as pointers.

Found by matching wordsline 24

Licence

MIT, from LICENSE

The terms its author shares it under, which let it be shown here.

From the repositorylicence text
Other files in this skill (2) Close

The text

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1---
2name: git-guardrails-claude-code
3description: 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.
4---
5
6# Setup Git Guardrails
7
8Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.
9

Setup Git Guardrails

Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.

Raw lines 1 to 9
10## What Gets Blocked
12- `git push` (all variants including `--force`)
13- `git reset --hard`
14- `git clean -f` / `git clean -fd`
15- `git branch -D`
16- `git checkout .` / `git restore .`
18When blocked, Claude sees a message telling it that it does not have authority to access these commands.

What Gets Blocked

  • git push (all variants including --force)
  • git reset --hard
  • git clean -f / git clean -fd
  • git branch -D
  • git checkout . / git restore .

When blocked, Claude sees a message telling it that it does not have authority to access these commands.

Raw lines 10 to 19
22### 1. Ask scope
24Ask the user: install for **this project only** (`.claude/settings.json`) or **all projects** (`~/.claude/settings.json`)?

1. Ask scope

Ask the user: install for this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?

Raw lines 22 to 25
Involves a person Ask the user :24
26### 2. Copy the hook script
28The bundled script is at: [scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh)
30Copy it to the target location based on scope:
32- **Project**: `.claude/hooks/block-dangerous-git.sh`
33- **Global**: `~/.claude/hooks/block-dangerous-git.sh`
35Make it executable with `chmod +x`.

2. Copy the hook script

The bundled script is at: scripts/block-dangerous-git.sh

Copy it to the target location based on scope:

  • Project: .claude/hooks/block-dangerous-git.sh
  • Global: ~/.claude/hooks/block-dangerous-git.sh

Make it executable with chmod +x.

Raw lines 26 to 36
Runs code scripts/block-dangerous-git.sh :28
37### 3. Add hook to settings
39Add to the appropriate settings file:
41**Project** (`.claude/settings.json`):
43```json
45 "hooks": {
46 "PreToolUse": [
47 {
48 "matcher": "Bash",
49 "hooks": [
50 {
51 "type": "command",
52 "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
53 }
54 ]
55 }
56 ]
57 }
59```
61**Global** (`~/.claude/settings.json`):
63```json
65 "hooks": {
66 "PreToolUse": [
67 {
68 "matcher": "Bash",
69 "hooks": [
70 {
71 "type": "command",
72 "command": "~/.claude/hooks/block-dangerous-git.sh"
73 }
74 ]
75 }
76 ]
77 }
79```
81If the settings file already exists, merge the hook into the existing `hooks.PreToolUse` array. Don't overwrite other settings.

3. Add hook to settings

Add to the appropriate settings file:

Project (.claude/settings.json):

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
          }
        ]
      }
    ]
  }
}

Global (~/.claude/settings.json):

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/block-dangerous-git.sh"
          }
        ]
      }
    ]
  }
}

If the settings file already exists, merge the hook into the existing hooks.PreToolUse array. Don't overwrite other settings.

Raw lines 37 to 82
83### 4. Ask about customization
85Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.

4. Ask about customization

Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.

Raw lines 83 to 86
87### 5. Verify
89Run a quick test:
91```bash
92echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>
93```
95Should exit with code 2 and print a BLOCKED message to stderr.

5. Verify

Run a quick test:

echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>

Should exit with code 2 and print a BLOCKED message to stderr.

Raw lines 87 to 95

From mattpocock/skills at 4ae2317, 2026-10-31. Skills read by DeepSeek V4.1 Flash on 2026-11-04. Summary and techniques by Claude Opus 5.5 on 2026-11-06.