Kipt

Your prompts and skills, one keystroke away.

Explore

git-guardrails-claude-code skill: block git push and reset --hard in Claude Code

The git guardrails Claude Code skill adds a hook that blocks git push, reset --hard and clean before they run. How it works, how to install it, and its gaps.

By the Kipt team · Updated 26 October 2026

Source: mattpocock/skills · Maintainer: community: Matt Pocock · License: MIT · Checked: 26 October 2026

What is the git-guardrails-claude-code skill?

The git-guardrails-claude-code skill sets up a Claude Code hook that blocks destructive git commands, such as git push, git reset --hard and git clean -f, before Claude can run them. It is a one-time setup skill: Claude copies a bash script into your project or home folder and registers it in your settings file.

It comes from mattpocock/skills, Matt Pocock's collection. The SKILL.md description reads: "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."

As of 26 October 2026, its skills.sh page listed about 505,500 installs (snapshot, 26 October 2026).

One thing to know first: it sits in the repo's misc/ folder. The misc README calls these "Tools I keep around but rarely use, not promoted in the plugin," and a note in the repo says misc skills "are frozen. Bug reports, feature requests and PRs against them are closed."

What does it do?

The folder holds SKILL.md, scripts/block-dangerous-git.sh and agents/openai.yaml (Codex display metadata). The SKILL.md walks Claude through five steps:

  1. Ask scope. This project only (.claude/settings.json) or all projects (~/.claude/settings.json).
  2. Copy the hook script to .claude/hooks/block-dangerous-git.sh or ~/.claude/hooks/block-dangerous-git.sh and make it executable.
  3. Add the hook under hooks.PreToolUse with the matcher Bash, merging into any existing settings rather than overwriting them.
  4. Ask about customization, adding or removing patterns in the copied script.
  5. Verify by piping a fake git push origin main command into the script, which should exit with code 2.

The project version of the settings entry looks like this:

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

The script reads the hook input with jq, pulls out tool_input.command, and checks it with grep -E against these patterns: git push, git reset --hard, git clean -fd, git clean -f, git branch -D, git checkout ., git restore ., push --force and reset --hard. On a match it prints "BLOCKED: '' matches dangerous pattern ''. The user has prevented you from doing this." to stderr and exits with code 2.

That matches how the Claude Code hooks docs describe blocking: "Exit with code 2 to block the action," and "The message that comes with the block is your hook's stderr." The docs also note that Bash as a matcher "matches only the Bash tool," and that CLAUDE_PROJECT_DIR is "the project root where the session started."

How do you install it?

The plugin route in the README (claude plugin install mattpocock-skills@claude-plugins-official) does not include this skill: the repo's own instructions say skills in misc/ must not appear in the plugin. Install it on its own with the command shown on skills.sh:

npx skills add https://github.com/mattpocock/skills --skill git-guardrails-claude-code

The skills CLI installs to the current project by default; add -g for all projects. Per the Claude Code skills docs, project skills live in .claude/skills/<skill-name>/SKILL.md and personal skills in ~/.claude/skills/<skill-name>/SKILL.md.

The skill is written for Claude Code: it edits Claude Code settings files and uses Claude Code's hook format. Codex and Cursor read the same SKILL.md format (see Codex skills and Cursor skills), but the steps target Claude Code's settings files, so they don't carry over as written.

You need jq on your machine. The SKILL.md doesn't list it, but the script depends on it (see the limits below).

How do you use it?

The skill has no disable-model-invocation line, so Claude can load it when your request matches the description, or you can type /git-guardrails-claude-code.

Example prompts (suggestions, not quotes from the repo):

  • Set up git guardrails so you can't push or hard reset in this repo.
  • /git-guardrails-claude-code Install it globally for all my projects.
  • Add git safety hooks, but also block git rebase and allow git checkout .
  • Check that the git guardrail hook is working by testing it against git push.

After setup, a blocked command doesn't run, and Claude gets the BLOCKED message from the script's stderr. You run the blocked command yourself when you mean it.

Tips and limits

Most of these come from closed issues on the repo and from Claude Code's own docs, not from testing:

  • It fails open without jq. Issue #898 points at line 4 of the script, COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command'), and reports that with no set -e and no status check, a machine without jq gets an empty command, no pattern matches, and every command is allowed. Install jq before you rely on it.
  • Rewording slips past it. Issue #301 reports that git global options between git and the subcommand, as in git -C /any/repo push, defeat the patterns. Issue #898 adds git branch --delete --force and git clean -d -f. Both issues were closed as not planned, with the maintainer's triage reply pointing to the frozen status and advising not to rely on the hook as a safety guarantee.
  • It can also over-block. Line 19 of the script is if echo "$COMMAND" | grep -qE "$pattern"; then, which searches the whole command string with no anchors. Read that way, any command that merely contains the text git push, such as a commit message mentioning it, matches too. Issue #301 reports the same false positive for echo "remember to git push later".
  • Deny rules do similar work. Issue #465 asked what the skill adds over built-in deny rules. The Claude Code permissions docs show a Bash(git push *) deny rule, and say it isn't matched by git -C . push origin main, so it "isn't a security boundary around the program." For filesystem and network enforcement that doesn't depend on command text, the docs point to sandboxing.
  • Hooks beat allow rules. Per the permissions docs, "A hook that exits with code 2 stops the tool call before permission rules are evaluated," so the block holds even if Bash is on your allow list.
  • Keep the exit code at 2. The hooks docs say exit code 1 is a non-blocking error: "If your hook is meant to enforce a policy, use exit 2."

As of 26 October 2026, its skills.sh audits (Gen Agent Trust Hub, Socket and Snyk) all showed Pass, dated 15 September 2026. Gen Agent Trust Hub noted that the skill writes a persistent hook into your settings, which it judged acceptable because providing guardrails is the skill's stated purpose. The MIT License lets you copy and change the script, which the frozen-skills note encourages.

Save it in your Kipt library

In Kipt, open Skills and paste the skill's GitHub folder link into the import box. Kipt reads the SKILL.md and its files, including scripts/block-dangerous-git.sh; for a repo with many skills it shows a list to pick from. You can also drop the folder or a .zip. Your skills live in your own private GitHub repo and install into Claude Code or Codex with one command:

npx skills add https://github.com/<you>/<repo>.git --all -g

Kipt is not affiliated with Matt Pocock or mattpocock/skills.

Similar skills

  • Setup pre-commit skill: another frozen misc skill from the same repo, which adds Husky hooks that check code before each commit.
  • Claude Code hooks: how PreToolUse and other hook events work, if you'd rather write your own guard.
  • Claude Code permissions: allow, ask and deny rules for Bash commands.
  • Git commit skill: a skill for writing commits, the other side of git hygiene with an agent.

Questions

What does the git-guardrails-claude-code skill do?

It has Claude Code install a small bash script as a PreToolUse hook on the Bash tool. Before any shell command runs, the script checks it against a list of patterns such as git push, git reset --hard, git clean -f and git branch -D, and blocks matches with exit code 2 and a BLOCKED message that Claude sees.

How do I install the git-guardrails-claude-code skill?

Run npx skills add https://github.com/mattpocock/skills --skill git-guardrails-claude-code, then ask Claude Code to set up git guardrails. The skill lives in the repo's misc folder, which does not ship in the mattpocock-skills Claude Code plugin, so the plugin install does not include it.

Is the git guardrails hook a security boundary?

No. It matches text in the command, so rewording slips past it. Issues #301 and #898 on the repo, both closed as not planned, report that git -C <dir> push, git branch --delete --force and git clean -d -f get through, and that the hook allows everything if jq is not installed. Treat it as a guard against accidents, not a sandbox.

Should I use this skill or Claude Code deny rules?

Both work on command text. A deny rule such as Bash(git push *) needs no script, while a hook lets you write your own matching logic. Claude Code's permissions docs say a deny rule isn't matched by a push written another way, such as git -C . push, and this skill's hook has the same gap according to issue #301. For filesystem and network enforcement that doesn't depend on command text, the docs point to sandboxing.

Is the git-guardrails-claude-code skill still maintained?

No. The repo marks every skill in its misc folder as frozen: they stay in the repo because they still work for some people, but bug reports, feature requests and pull requests against them are closed. The maintainer suggests installing with skills.sh and fixing your own copy.

More in Skill directory

All guides

Keep your prompts and skills in one place, in your own GitHub. Install every skill with one command.

Get started

Kipt is an independent product, not affiliated with or endorsed by Anthropic, OpenAI, Cursor or GitHub. Claude, ChatGPT, Codex, Cursor and GitHub are trademarks of their owners.