Skip to content
SkillModel-led514 tokens in use

Git Guardrails for Claude Code

Installs a Claude Code PreToolUse hook that blocks git push, hard resets, forced cleans and other destructive git commands before the agent runs them.

328,791 stars on the repository MIT Licensemattpocock/skills · skills/misc/git-guardrails-claude-code
claude plugin install mattpocock-skills@claude-plugins-official
View source

Install command as written in the repository's README

Skill label

measured from its files

What installing Git Guardrails for Claude Code costs

61tokens idle
514tokens in use

Idle is what sits in context while the skill is installed. In use is its instructions, loaded when it runs. Counts are approximate, made offline with cl100k_base.

Model dependence Model-led

Script-ledMixedModel-led

Mostly instructions, so how well it works depends on the model that follows them.

This describes the skill's structure, how much of it is scripts. It does not say how well it works. Scripts: scripts/block-dangerous-git.sh.

Touches

shelldetectedwrites filesdetectedgitdetected

Declared tags come from the skill's frontmatter; detected ones from its scripts, its code blocks and the commands it names in inline code. This is detected, not audited.

How it scores

Quality

How well the skill is written, counted from its own files: its frontmatter, its steps, examples, stated output and constraints, its size and whether every file it ships is one it names.How we score it →
Good
  • Frontmatter12/15
  • Structure14/25
  • Examples9/15
  • Output10/15
  • Size15/15
  • Resources7/15

Security

Starts at 100 and loses points for each thing in the skill's files that a reader should look at first.How we score it →
Excellent
  • Runs git commands−5

    does this on the machine, and the frontmatter does not say so

    SKILL.md, line 92
  • Runs shell commands−5

    does this on the machine, and the frontmatter does not say so

    SKILL.md, line 92

Repository health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
Excellent
  • Development activity96
  • Maintenance100
  • Community56
  • Maturity32
  • Momentum40

Git Guardrails sets up a shell hook on the Bash tool in Claude Code. Each command the agent tries to run is checked against a list of dangerous git patterns, and a match is refused with a message that the agent has no authority to run it.

The skill asks whether to install for one project or all projects, copies the script, merges the hook into the settings file and tests it.

What You Get

  • A hook script that blocks git push, reset —hard, clean -f, branch -D, checkout . and restore .
  • A settings.json entry at project or user scope
  • A customised pattern list if you ask for one
  • A test run showing exit code 2 and a BLOCKED message

Common Use Cases

  • Stopping an agent from pushing to a remote while you review its work
  • Protecting uncommitted changes from a reset or clean
  • Adding the same safety net to every project through the global settings
  • Tightening or loosening the blocked list for one team

What Makes It Unique

Most safety advice for agents lives in prompts, which a model can ignore. This skill installs a deterministic hook that runs outside the model and exits with code 2, so the command never reaches the shell. The pattern list is a bash array that is easy to read and edit.

Under The Hood

The skill ships a bash script that reads the hook JSON from stdin, extracts the command with jq, and loops over a list of patterns with grep. A match prints a BLOCKED message to stderr and exits with code 2. The skill itself copies that file, runs chmod, edits a settings.json file and runs one echo test against the script. The script needs jq on the machine. Matching is by text pattern, so it checks the command string only.

Join founders building with open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on SubstackJoin 750+ subscribers