Skip to content
cccskills
FreePublished on GitHubEnglish overview

git-guardrails-claude-code

Set up Claude Code hooks that block Git commands such as push, hard reset, and forced deletion before execution. Choose project-wide or global settings, customize the blocked commands, and verify that the hook rejects a test command.

OriginalShow the original 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.

AI rating100/ 100See how to install

Good for

  • Block Git pushes from Claude Code
  • Prevent commands that discard changes or delete branches
  • Apply Git restrictions to one project or all projects
  • Customize and test the blocked command list

Overview

What it does

Set up a hook that stops selected Git operations just before Claude Code executes them. A hook is a check that runs automatically at a particular point, such as before an operation. By default, it blocks every form of git push, git reset --hard, forced deletion with git clean, git branch -D, git checkout ., and git restore ..

When it helps

Use it to prevent an agent from sending changes to a remote repository, discarding work in progress, or deleting branches. Apply the restrictions to one project or all projects. You can also add commands to the blocked list or remove them.

Example requests

  • “Block Claude Code from running git push in this project.”
  • “Set up Git restrictions for all projects and verify that they work.”

Notes

The setup uses Claude Code’s PreToolUse hook and a bundled shell script, which needs execute permission. It adds entries to existing settings in .claude/settings.json or ~/.claude/settings.json. It covers commands executed through Bash. After setup, test input is passed to the script to check its exit code and blocking message.

This overview was written by AI (OpenAI Codex) from the public SKILL.md. Check the original below for the exact behavior.

Objective evaluation

AI rated this skill on four points using only the contents of its SKILL.md. Stars and popularity are not taken into account.

Clear instructionsIs it clear when to use it and what it does?
AGoodThe purpose of blocking Git operations before execution and the default blocked commands are explicitly listed.
Concrete stepsAre steps, inputs, outputs, and examples spelled out?
AGoodIt specifies script locations, configuration examples, test input, exit code 2, and the blocking message to check.
SafetyAre sending data, deleting files, and running commands disclosed?
AGoodIt asks about scope and customization, and instructs merging the hook without overwriting existing settings.
Easy setupDoes it need few tools or API keys, and are they documented?
AGoodIt provides Claude Code settings paths, bundled script placement, and the chmod +x step.

The total counts each point as A = 25, B = 15, C = 5. Rated by AI (OpenAI Codex) as of Oct 19, 2026. Treat it as a guide and read the original before installing.

Disagree? Request a re-evaluation

Tell us which point is wrong and why. No login needed. We will check it against the SKILL.md, redo the evaluation, and show the result here.

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

Files included (3)

  • SKILL.md2.3 KB
  • agents/openai.yaml112 B
  • scripts/block-dangerous-git.sh507 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

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

Steps

1. Ask scope

Ask the user: 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-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.

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.

4. Ask about customization

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

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.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

ask-matt

FreeSummaryAI rating 90

Choose which related skill to use and in what order for planning, building, debugging, or maintaining software. It explains routes through the available workflows and helps select the next step based on your situation and project size.

  • Choosing a workflow from idea to implementation
  • Finding the right starting point for bug investigation
  • Planning a build that spans multiple sessions
mattpocock/skills296.7KUpdated Oct 13, 2026

chief-of-staff

FreeSummaryAI rating 60

Coordinate subagents, separate agents assigned tasks, to pursue a long-running goal in one session. Maintain dialogue with the user while improving working conditions, shared rules, and access to information needed for future tasks.

  • Coordinating agents around a long-term goal
  • Continuing user dialogue during background work
  • Improving shared rules and working conditions
mattpocock/skills296.7KUpdated Oct 13, 2026

claude-handoff

FreeSummaryAI rating 90

Summarize an ongoing conversation and launch a fresh background agent to continue the work. The handoff includes the next focus, references to existing documents, and suggested skills, with sensitive information removed.

  • Continue ongoing work with a fresh agent
  • Hand off work with a specific next focus
  • Organize document references for the next session
mattpocock/skills296.7KUpdated Oct 13, 2026

code-review

FreeSummaryAI rating 90

Review code changes from a chosen Git reference against two separate criteria: documented coding standards and the original requirements. Independent reviewers check each criterion, then present findings separately so convention problems and requirement gaps remain visible.

  • Reviewing changes on a branch or pull request
  • Checking changes since a chosen commit or tag
  • Checking compliance with documented coding standards
mattpocock/skills296.7KUpdated Oct 13, 2026

codebase-design

FreeSummaryAI rating 90

Design modules that offer substantial behavior through a small interface, the rules callers must understand. Use shared design terms to simplify usage, contain complexity, choose where implementations can vary, and make behavior easier to test.

  • Simplifying a module's interface
  • Bringing scattered complexity into one module
  • Choosing where implementations can be swapped
mattpocock/skills296.7KUpdated Oct 13, 2026

diagnosing-bugs

FreeSummaryAI rating 80

Investigate difficult bugs and performance slowdowns by building a repeatable test or script that detects the exact symptom. Reduce the failing case, compare possible causes, and verify the fix with checks that catch the bug if it returns.

  • Investigating an error that is hard to reproduce
  • Finding the cause of a performance slowdown
  • Testing an intermittent failure repeatedly
mattpocock/skills296.7KUpdated Oct 13, 2026

See all skills by mattpocock

Report a problem with this skill