Skip to content
HUIAHUB

mattpocock/skills/skills/misc/git-guardrails-claude-code

Git guardrails for Claude Code

Sets up Claude Code hooks that block dangerous git commands, such as pushes, hard resets, forced cleans and forced branch deletes, before they run.

Agent skillAgent skillsMIT
Runs scriptsNo networkInstalls hooksNo secretsSee the security check

What Git guardrails for Claude Code does

The skill has the agent install a Claude Code PreToolUse hook that checks each Bash command before it runs and stops dangerous git commands. The blocked list in the SKILL.md covers git push in all its forms, git reset --hard, git clean -f and -fd, git branch -D, and git checkout . and git restore ..

First the agent asks whether to install for the current project or for all projects. It then copies the bundled block-dangerous-git.sh to .claude/hooks/ in the project or to ~/.claude/hooks/, and makes it executable with chmod +x. Next it adds a PreToolUse entry with the matcher Bash to the matching settings.json, merging it into any existing hooks instead of overwriting the file. It asks whether you want to add or remove patterns and edits the copied script to match. Last, it pipes a sample git push origin main request into the script and expects exit code 2 with a BLOCKED message.

The script reads the hook's JSON input from standard input and extracts the command with jq. It then tests that text against its pattern list, which also includes push --force and reset --hard on their own. On a match it prints a message to standard error saying the user has prevented the command, and exits with code 2. Otherwise it exits 0. You end up with one script and one settings entry in the scope you chose.

Install

npx skills@latest add mattpocock/skills -a <agent>

Read the security check below before you run it. The repository's own instructions win if they differ.

Security check

What the skill's files do, from reading them. A flag that nobody has checked yet says "Not checked", never "No".

Runs scripts
Yes
Uses the network
No
Installs hooks
Yes
Asks for secrets
No

The scan found one script, scripts/block-dangerous-git.sh, and no network calls or secret variables. The folder holds no hook definition file, but the SKILL.md tells the agent to set up a hook: it copies the script to .claude/hooks/ or ~/.claude/hooks/ and adds a PreToolUse entry for Bash to .claude/settings.json or ~/.claude/settings.json. From then on Claude Code runs the script before every Bash command. The script only reads the command with jq, matches patterns and exits 0 or 2. Read the script and check the settings change before accepting it.

Scan details: Ships 1 script file: scripts/block-dangerous-git.sh. Checked at commit 5863806dd4e1.

Use cases

  • Stop Claude Code from pushing to a remote without you
  • Block hard resets, forced cleans and forced branch deletes in a repository
  • Apply the same git limits to every project from your user settings

Limitations

  • Works only with Claude Code hooks; other agents get no protection from it.
  • The script needs bash and jq, and the SKILL.md does not mention jq.
  • Matches command text against fixed patterns, so a git command written another way may not match.
  • Kept in the repository's misc folder, which its README says is not promoted in the plugin.

Sources