The git-guardrails-claude-code skill installs a PreToolUse hook that blocks nine destructive git patterns before Claude Code runs them, and the whole mechanism is a 302-word SKILL.md plus a 20-line bash script. It is not a permission system or a sandbox — it is a grep against the command string, and it stops the specific mistakes that agents make. On skills.pub it is listed as git-guardrails-claude-code from a repository with 328,182 stars.
What exactly gets blocked?
Nine patterns, matched with grep -qE against the shell command:
| Pattern | Why it is on the list |
|---|---|
git push | Covers all variants, including --force |
git reset --hard | Discards uncommitted work irrecoverably |
git clean -fd | Deletes untracked files and directories |
git clean -f | Deletes untracked files |
git branch -D | Deletes a branch without a merge check |
git checkout \. | Discards all working-tree changes |
git restore \. | Same, in the newer syntax |
push --force | Catches the version without the git prefix |
reset --hard | Same reason — matches when the command is piped or wrapped |
The last two are redundancies, and they are deliberate. push --force without a git prefix appears when a command is constructed through a shell pipeline or a variable, so matching only git push would miss it.
How does the hook actually stop anything?
By exiting with code 2 and writing to stderr. The script is short enough to read in full:
#!/bin/bash INPUT=$(cat) COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command') DANGEROUS_PATTERNS=( "git push" "git reset --hard" "git clean -fd" "git clean -f" "git branch -D" "git checkout \." "git restore \." "push --force" "reset --hard" ) for pattern in "${DANGEROUS_PATTERNS[@]}"; do if echo "$COMMAND" | grep -qE "$pattern"; then echo "BLOCKED: '$COMMAND' matches dangerous pattern '$pattern'. The user has prevented you from doing this." >&2 exit 2 fi done exit 0 Exit code 2 is the mechanism: Claude Code treats a non-zero exit from a PreToolUse hook as a refusal, so the tool call never happens. The stderr message reaches the model, and the wording matters — "The user has prevented you from doing this" tells the agent it hit a policy boundary rather than a bug it should work around.
| Mechanism | What it relies on |
|---|---|
| Interception point | PreToolUse with matcher Bash |
| Signal | Exit code 2 plus stderr |
| Dependency | jq, to read .tool_input.command from the JSON payload |
| Scope | Project (.claude/settings.json) or global (~/.claude/settings.json) |
Is this a security boundary?
No, and it is worth being precise about what it is. The pattern list matches a substring of the command. git push inside a string literal, a path named git press, or a command that assembles the words at runtime will not be caught — and a command that contains the phrase for an unrelated reason will be blocked.
What it actually defends against is a specific behaviour: an agent deciding on its own to push, force-push, or hard-reset to make a plan work. Those are the operations where an autonomous loop can destroy work that was never committed, and they are exactly the commands where the agent has enough context to want to run them.
The SKILL.md's own framing is honest about this. The blocked message says the agent lacks authority, which is a policy statement, not a security claim.
Why a hook instead of an instruction?
Because instructions are advisory and hooks are not. A CLAUDE.md line saying "never force-push" is text the model may or may not weight correctly under pressure; a PreToolUse hook runs outside the model's discretion. The skill picks the mechanism that matches the guarantee.
There is a cost: the hook runs on every Bash call, so it adds a shell invocation and a jq parse to each one. For a guard against data loss that is a reasonable tax, and the script exits 0 immediately when nothing matches.
How is it installed?
Five steps, and the skill asks two questions along the way rather than deciding for you:
- Ask scope — this project only, or all projects.
- Copy the script to
.claude/hooks/block-dangerous-git.shor~/.claude/hooks/block-dangerous-git.sh, thenchmod +x. - Merge the hook into the settings file. The skill is explicit: "If the settings file already exists, merge the hook into the existing
hooks.PreToolUsearray. Don't overwrite other settings." - Ask about customization — whether to add or remove patterns, editing the copied script.
- Verify with a real command.
Step 3 is the one that matters operationally. Overwriting settings.json would silently drop every other hook you have, and the skill calls that out.
How do you verify it works?
The skill gives a one-liner that tests the script in isolation, without needing Claude Code:
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script> Expected: exit code 2 and a BLOCKED message on stderr. If you get exit 0, either the script is not executable, jq is missing, or the path is wrong.
| Test | Expected | If it fails |
|---|---|---|
git push origin main | exit 2, BLOCKED | jq missing, or wrong script path |
git status | exit 0, silent | A pattern is too broad |
git reset --hard HEAD~1 | exit 2, BLOCKED | The array lost an entry during editing |
What are the gaps worth knowing?
- No
git commitprotection. An agent can still commit anything, including secrets, before being stopped at push. If that matters, the guard needs a pre-commit secret scan, which this skill does not provide. -
jqis an undeclared dependency. The SKILL.md does not mention it; the script uses it. Withoutjq,COMMANDis empty, and an empty string matches no pattern — the guard fails open, silently. - Global scope is per-user, not per-repo. If you install globally, every project on the machine inherits the block, including projects where pushing is the agent's job.
- Patterns are substring matches.
git branch -Dis blocked, butgit branch --delete --forceis a different spelling of the same operation and is not in the list.
That second point is the one to fix first: add a jq presence check that exits non-zero, so a missing dependency blocks rather than silently permits.
Should you install it?
If you let an agent run Bash in a repository with uncommitted work, yes — the cost is one hook and a small latency increase, and the failure it prevents is unrecoverable. If you already run agents in a sandbox where the working tree is disposable, the guard is redundant with the sandbox.
The general pattern is worth stealing even if you do not use this skill: a PreToolUse hook that matches a command string and exits 2 is the cheapest way to turn "please don't" into "cannot", and it works in any harness that honours hook exit codes.
The pattern list, the script body, the install steps and the verification command were read from the repository on 2026-11-20: SKILL.md and block-dangerous-git.sh. The claim that Claude Code treats exit code 2 as a refusal is stated in the SKILL.md and NOT independently verified here.

