Skip to content

Guide · Agent skill

How to use the Git Guardrails for Claude Code agent skill

Updated · written with AI from the project's own documentation and checked against our catalogue data

Git Guardrails for Claude Code is an agent skill from the mattpocock/skills collection that sets up a safety hook. The hook checks shell commands Claude Code tries to run and stops git commands that could overwrite or discard your work. This guide is for developers who let Claude Code work in their repositories and want a backstop against destructive git actions. By the end you will know what the skill blocks, how to install it, how to trigger it, and what its limits are.

Git Guardrails for Claude Codemattpocock/skills · MIT

Quick start

  1. 1Download and unzip the skill. Download the ZIP from this page and unzip it into .claude/skills/ for one project or ~/.claude/skills/ for all projects.
  2. 2Check the requirements. Confirm Claude Code, bash and jq are available and that you can write to .claude/ or ~/.claude/.
  3. 3Choose the install scope. Decide whether the hook applies to this project only (.claude/settings.json) or to all projects (~/.claude/settings.json).
  4. 4Let Claude copy and register the hook. Ask Claude to set up git guardrails. It copies block-dangerous-git.sh, makes it executable and merges the PreToolUse hook into your settings.
  5. 5Customise the blocked list. Tell Claude which patterns to add or remove, and it will edit the copied script.
  6. 6Verify the block. Run the echo test with a git push command and confirm it exits with code 2 and prints a BLOCKED message.

What is an agent skill, and what does this one do?

An agent skill is a folder containing a SKILL.md file and any supporting files, which an AI agent such as Claude Code can load to learn how to perform a specific task. This skill, git-guardrails-claude-code, sets up a PreToolUse hook. A PreToolUse hook runs before Claude executes a tool call, so it can intercept a command before it happens.

Once installed, a small bash script inspects every Bash command Claude tries to run. If the command matches a blocked git operation, the script stops it, and Claude is told that the action was blocked so it does not run it.

  • git push, including all variants and --force
  • git reset --hard
  • git clean -f and git clean -fd
  • git branch -D
  • git checkout . and git restore .

What do you need before installing?

The skill relies on Claude Code's hook system and a script that parses JSON input with jq. You need Write access to .claude/ or ~/.claude/, because the installer copies a hook file and edits settings.json.

  • Claude Code
  • bash
  • jq
  • Write access to .claude/ or ~/.claude/

How do you install the Git Guardrails skill?

Download the ZIP from this page and unzip it. Then choose where the skill should live. To make it available in one project only, unzip it into that project's .claude/skills/ folder. To make it available in all your projects, unzip it into ~/.claude/skills/.

If you use the Claude apps instead of Claude Code's folders, you can upload the skill under Settings → Capabilities → Skills.

How do you add the hook to Claude Code?

The skill asks whether to install for this project only, which uses .claude/settings.json, or for all projects, which uses ~/.claude/settings.json. It copies the bundled script to .claude/hooks/block-dangerous-git.sh or ~/.claude/hooks/block-dangerous-git.sh, then makes it executable with chmod +x.

The hook is registered under hooks.PreToolUse with the matcher set to Bash. For a project install, the command points to "$CLAUDE_PROJECT_DIR"/.claude/hooks/block-dangerous-git.sh. For a global install, it points to ~/.claude/hooks/block-dangerous-git.sh. If your settings file already exists, the hook is merged into the existing hooks.PreToolUse array and other settings are left alone.

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

How do you trigger the skill with natural requests?

You do not need a special command. Ask Claude in plain language, for example that you want to prevent destructive git operations, add git safety hooks, or block git push and reset in Claude Code. The skill's description is written to match requests like these, so Claude will pick it up and walk through the setup steps.

During setup, Claude asks whether you want a project-only or global install, and whether you want to add or remove any patterns from the blocked list. It then edits the copied script to match your answer.

How do you verify that the hook works?

Run a test that pipes a sample JSON command into the script. The script should exit with code 2 and print a BLOCKED message to stderr. Replace the path with wherever you copied the script.

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

What should you know about limits and safety?

This skill is a backstop, not complete protection. The pattern matching is simple text matching, so alternate command forms may get past it. It only covers Bash tool calls. The skill runs scripts, which is why you should read the bundled script before installing. It does not use the network.

Blocking is also a trade-off. If you need Claude to push, commit to a remote, or reset branches as part of normal work, those commands will be blocked and you must run them yourself. The skill is also designed for git projects and Claude Code, so it does not help with other agents or non-git work.

  • Runs scripts: yes. Read scripts/block-dangerous-git.sh before installing.
  • Uses network: no.
  • Covers Bash tool calls only.
  • Matching is text-based and can be bypassed by alternate command forms.

What people use it for

  • Stopping Claude from pushing code directly to a shared branch while you review its work.
  • Blocking git reset --hard so Claude cannot discard uncommitted changes in a repository.
  • Preventing git clean -fd from deleting untracked files during a refactor.
  • Keeping git branch -D from removing branches while Claude tidies up a project.
  • Learning how Claude Code behaves with extra protection in place.

Frequently asked questions

How do I install the Git Guardrails Claude Code skill?

Download the ZIP from this page and unzip it into .claude/skills/ for a single project or ~/.claude/skills/ for all projects. You can also upload it in the Claude apps under Settings → Capabilities → Skills. Then ask Claude to set up git guardrails so the hook is copied and registered.

What do I need to run this skill?

You need Claude Code, bash, and jq, because the script parses JSON input with jq. You also need write access to .claude/ or ~/.claude/ so the hook file and settings.json can be installed.

Is the Git Guardrails skill free?

The skill is published under the MIT licence. This page does not list pricing, so check the licence and repository for the terms that apply to you.

Does it block every dangerous git command?

No. It blocks the listed commands such as push, reset --hard, clean -f, branch -D, and checkout or restore on the current directory. Because it uses simple text matching, alternate command forms can bypass it, and it only covers Bash tool calls.

How do I stop Claude from pushing code but still let it commit?

The blocked list includes git push, and it does not list git commit, so commits are not blocked by the default script. If you want a different mix, ask Claude to add or remove patterns during setup, which edits the copied script.

Can I use this with agents other than Claude Code?

No. The hook relies on Claude Code's PreToolUse hook system and a jq-based script, so it is not designed for other agents or for non-git projects.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Git Guardrails suits developers who let Claude Code work in their repositories and want a simple backstop against pushes, hard resets, and file or branch deletion. It is also a reasonable first safety layer for people new to AI coding agents. If you need Claude to push or reset as part of normal work, or you need guarantees rather than a text-matching filter, pick a different approach such as branch protection on your git host.

Download the skill