Skip to content
Agentmart
Submit a tool

git-guardrails

Set up Claude Code hooks to block dangerous Git commands (push, reset --hard, clean, branch -D, etc.) before they execute.

Skill by petemcw

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/petemcw-git-guardrails

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

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.

Use cases: agent-building

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Shell scripts

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/git-guardrails

What's inside

Skill name
git-guardrails
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.
License
MIT
Instructions
94 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Files (2)

  • SKILL.md
  • block-dangerous-commands.sh · scripts/

SKILL.md (first lines)

# Git Guardrails

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

## What Gets Blocked

- `git push` (all variants including `--force`)
- `git reset --hard`
- `git clean` with any force flag (`-f`, `-fd`, `-xfd`, `--force`)
- `git branch -D`, and `--delete` combined with `--force`
- `git checkout .` / `git checkout -- .` / `git restore .`

The script checks each command in a chain (`cd x && git push`) and sees through git's global options (`git -C dir push`, `git --no-pager push`). Text that merely mentions a command, like `echo "git push"`, is allowed. It needs `jq`, and blocks everything if `jq` is missing rather than silently allowing it. It is a guardrail against accidents, not a security boundary: `bash -c "git push"` is not inspected.

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

## Steps

### 1. Ask Scope

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

### 2. Copy the Hook script

The bundled script is at: [scripts/block-dangerous-commands.sh](scripts/block-dangerous-commands.sh)

Copy it to the target location based on scope:

- **Project**: `.claude/hooks/block-dangerous-commands.sh`
- **Global**: `~/.claude/hooks/block-dangerous-commands.sh`

Make it executable with `chmod +x`.

### 3. Add Hook to Settings

Add to the appropriate settings file:

**Project** (`.claude/settings.json`):

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

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

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

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

### 4. Ask About Customization

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

### 5. Verify

Run a quick test:

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

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

From petemcw/farseer, MIT.

More from petemcw/farseer

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Oct 15, 2026 (13 days ago)
Last release
Oct 15, 2026 (13 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

Same skill elsewhere

Copies of this SKILL.md published by others; search shows only one of them.

More from petemcw

Cite this page

git-guardrails skill. Agent Mart. https://agentmart.dev/skills/petemcw-git-guardrails (last updated 2026-10-24)