git-guardrails-claude-code

git-guardrails-claude-code is a skill for Claude Code, Codex from vinvcn/mattpocock-skills-zh-CN. It costs 68 tokens per session (609 once invoked), scanned B, original, MIT.

A Claude Code setup that blocks selected destructive Git commands before they run. Git is a tool for tracking code changes; the blocked commands include pushing, deleting branches, discarding changes, and hard resets.

In plain words
What is it for?
Use it to prevent git push, git reset --hard, git clean, git branch -D, git checkout ., and git restore . in Claude Code. It installs a hook and connects it to Claude's settings.
Why use it?
It reduces the chance that an automated coding session will publish unwanted changes or permanently remove local work. The protection can apply to one project or to all projects.

Skill for Claude CodeCodex

Written for Claude Code and Codex: $CLAUDE_PROJECT_DIR variable, but also agents/openai.yaml present. Also seen: reads .claude/ paths; mentions Claude Code.

Part of the mattpocock-skills plugin — 36 skills shipped together

Good fit Use it to prevent git push, git reset --hard, git clean, git branch -D, git checkout ., and git restore . in Claude Code. It installs a hook and connects it to Claude's settings.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/vinvcn/mattpocock-skills-zh-cn/git-guardrails-claude-code
About the project

mattpocock-skills-zh-CN is a Simplified Chinese localization of a collection of reusable instructions for coding agents. Chinese-speaking developers use the translated skills to support engineering workflows while keeping their original commands, paths, identifiers, and behavior. The catalogue contains the localized skills, instructions, and plugin components.

vinvcn/mattpocock-skills-zh-CN · 4,114 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add vinvcn/mattpocock-skills-zh-CN --skill git-guardrails-claude-code
Clone the repo
git clone --depth 1 https://github.com/vinvcn/mattpocock-skills-zh-CN

Made for: Claude Code, Codex.

Or install mattpocock-skills, the plugin that ships this one along with the rest of its 36 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for git-guardrails-claude-code

README.md
[![agentmods](https://agentmods.dev/badge/skills/vinvcn/mattpocock-skills-zh-cn/git-guardrails-claude-code/github.svg)](https://agentmods.dev/skills/vinvcn/mattpocock-skills-zh-cn/git-guardrails-claude-code)
Your own site
<a href="https://agentmods.dev/skills/vinvcn/mattpocock-skills-zh-cn/git-guardrails-claude-code"><img src="https://agentmods.dev/badge/skills/vinvcn/mattpocock-skills-zh-cn/git-guardrails-claude-code/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for git-guardrails-claude-code

Your own site · 80×15
<a href="https://agentmods.dev/skills/vinvcn/mattpocock-skills-zh-cn/git-guardrails-claude-code"><img src="https://agentmods.dev/badge/skills/vinvcn/mattpocock-skills-zh-cn/git-guardrails-claude-code.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 68 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 609 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • Socket pass 6 May 2026
  • Snyk pass 6 May 2026
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 3 findings, up to high

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • high Tool Misuse · line 13
    Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).
    Fix: Validate all tool parameters against an allowlist. Reject dangerous parameter values (shell=True, --force, -rf /) and use safe defaults.
  • high Agent Snooping · line 24
    Skill reads from agent configuration directories (.claude/, .codex/, .gemini/). These directories may contain API keys, personal settings, and other credentials that the skill has no legitimate need to access.
    Fix: Remove all code or instructions that access agent configuration directories (.claude/, .codex/, .gemini/). If configuration values are needed, pass them explicitly as parameters or environment variabl
  • high Agent Snooping · line 61
    Skill reads from agent configuration directories (.claude/, .codex/, .gemini/). These directories may contain API keys, personal settings, and other credentials that the skill has no legitimate need to access.
    Fix: Remove all code or instructions that access agent configuration directories (.claude/, .codex/, .gemini/). If configuration values are needed, pass them explicitly as parameters or environment variabl
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00068 $0.00609
Opus 5 $0.00034 $0.00304
Sonnet 5 $0.00014 $0.00122
Haiku 4.5 $0.00007 $0.00061

Measured 12d ago against content hash 7c8fccb56153, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade B, and why

git-guardrails-claude-code scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/block-dangerous-git.sh), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

询问用户:只为**当前 project** 安装(`.claude/settings.json`),还是为**所有 projects** 安装(`~/.claude/settings.json`)?
skills/misc/git-guardrails-claude-code/SKILL.md · 96 lines

What it actually says

Setup Git Guardrails

设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。

What Gets Blocked

  • git push(包括 --force 在内的所有 variants)
  • git reset --hard
  • git clean -f / git clean -fd
  • git branch -D
  • git checkout . / git restore .

被阻止时,Claude 会看到一条 message,说明它无权访问这些 commands。

Steps

1. Ask scope

询问用户:只为当前 project 安装(.claude/settings.json),还是为所有 projects 安装(~/.claude/settings.json)?

2. Copy the hook script

bundled script 位于:scripts/block-dangerous-git.sh

根据 scope 复制到目标位置:

  • Project: .claude/hooks/block-dangerous-git.sh
  • Global: ~/.claude/hooks/block-dangerous-git.sh

chmod +x 让它可执行。

3. Add hook to settings

添加到对应 settings file:

Project (.claude/settings.json):

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

Global (~/.claude/settings.json):

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

如果 settings file 已存在,把 hook merge 到现有 hooks.PreToolUse array 中,不要覆盖其他 settings。

4. Ask about customization

询问用户是否要在 blocked list 中添加或移除 patterns。相应编辑复制后的 script。

5. Verify

运行快速测试:

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

应以 code 2 退出,并向 stderr 打印 BLOCKED message。

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 96 lines · 68 tokens per session scan B 7c8fccb56153

Subscribe to this mod's changes

git-guardrails-claude-code is a skill published in the GitHub repository vinvcn/mattpocock-skills-zh-CN (4,114 stars, last pushed 4d ago), licensed MIT. It adds 68 tokens to every session and 609 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it B with 1 finding (reads agent configuration directories). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

prowler-commit

Creates professional git commits following conventional-commits format. Trigger: When creating commits, after completing code changes, when user asks to commit.

prowler-cloud/prowler · 33 tokens

gh-auth-isolation

Safely manage multiple GitHub identities (EMU + personal) in agent workflows.

github/gh-aw · 20 tokens

comet-github

A routing guide for Comet-related GitHub work. It directs requests about pull requests, issues, CI failures, ideas, and fixes to the appropriate review or implementation process.

rpamis/comet · 72 tokens

github-skill

Work with GitHub via the gh CLI — clone repositories, create/list/merge pull requests, create/list issues, and run any other gh command (API calls, workflow runs, releases, repo administration). List operations return parsed JSON.

zeenie-ai/OpenCompany · 51 tokens

changelog-composer

Generates structured changelogs and release notes from git history and PRs, classifying breaking changes, features, fixes, performance, docs. Triggers on: "generate changelog", "write release notes", "what changed since", "prepare release", "release notes for", "diff since tag".

Mathews-Tom/armory · 67 tokens

re0-merge

Review and land an external contribution the way this suite does: gate it against the thesis, land it with the author's credit intact, complete a new skill rather than merging it raw, then approve, credit, and explain before closing. Use when reviewing a pull request, as any collaborator or maintainer, not only the…

LilMGenius/paperthin · 70 tokens