Skip to content

Git Guardrails for Claude Code

Blocks risky git commands like push, reset --hard and branch -D before Claude runs them.

Stars
309,658
Licence
MIT
Files
3 files

What it does

This skill sets up a safety hook in Claude Code, the coding assistant. Once installed, a small script checks every shell command Claude tries to run and stops git commands that could overwrite or discard work, such as pushing, hard-resetting, cleaning files, deleting branches, or discarding local changes. Claude receives a message saying the action was blocked, so it does not run it.

Great for

  • Developers who let Claude Code work in their repositories and want a backstop against destructive git actions
  • Teams that want to keep Claude from pushing code directly to shared branches
  • People new to AI coding agents who want extra protection while they learn how the tool behaves

Skip it if

  • Users who need Claude to push, commit to remote, or reset branches as part of normal work, since those commands will be blocked and must be run manually
  • Non-git projects or non-Claude-Code agents, because the hook relies on Claude Code's PreToolUse hook system and a jq-based script
  • Anyone expecting complete protection: the pattern matching is simple text matching and can be bypassed by alternate command forms, and it only covers Bash tool calls

Try asking

  • “Set up git guardrails so Claude can't push or hard-reset in this project”
  • “Add a hook that blocks git branch -D and git clean in all my projects”
  • “Block git push and git reset in Claude Code for this repo”
Step-by-step guide: how to use Git Guardrails for Claude CodeInstall, first run, examples, tips and FAQs

Install in 3 steps

  1. 1

    Download the skill

    The ZIP contains the 3 original files, the MIT licence and an attribution note.

    git-guardrails-claude-code.zip
  2. 2

    Add it to your agent

    Claude Code (all projects)

    mkdir -p ~/.claude/skills && unzip git-guardrails-claude-code.zip -d ~/.claude/skills/

    Claude Code / Agent SDK (this project only)

    mkdir -p .claude/skills && unzip git-guardrails-claude-code.zip -d .claude/skills/

    Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.

  3. 3

    Ask for the task

    No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.

Get better results

  • Choose project scope for shared repos so teammates are not affected by a personal global hook
  • Test the hook with the included echo command before relying on it, and confirm it exits with code 2
  • Review the pattern list and add or remove entries to fit your workflow, since broad patterns like 'git push' also match harmless text in commands

What's inside

  • agents/openai.yaml
  • scripts/block-dangerous-git.sh
  • SKILL.md

Redistributed unmodified from mattpocock/skills under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.