git-guardrails-claude-code

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

A Claude Code hook that blocks selected dangerous Git commands before they run. It can be installed for one project or for all projects.

In plain words
What is it for?
Use it to install a pre-command Git safety check in Claude Code that blocks commands including git push, git reset --hard, git clean, git branch -D, and checkout or restore of all files.
Why use it?
It reduces the chance of accidentally publishing, deleting, or discarding work through commands such as push, hard reset, force-clean, branch deletion, or restoring files.

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 — 37 skills shipped together

Good fit Use it to install a pre-command Git safety check in Claude Code that blocks commands including git push, git reset --hard, git clean, git branch -D, and checkout or restore of all files.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/devcxl/mattpocock-skills-zh/git-guardrails-claude-code
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 devcxl/mattpocock-skills-zh --skill git-guardrails-claude-code
Clone the repo
git clone --depth 1 https://github.com/devcxl/mattpocock-skills-zh

Made for: Claude Code, Codex.

Or install mattpocock-skills, the plugin that ships this one along with the rest of its 37 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/devcxl/mattpocock-skills-zh/git-guardrails-claude-code/github.svg)](https://agentmods.dev/skills/devcxl/mattpocock-skills-zh/git-guardrails-claude-code)
Your own site
<a href="https://agentmods.dev/skills/devcxl/mattpocock-skills-zh/git-guardrails-claude-code"><img src="https://agentmods.dev/badge/skills/devcxl/mattpocock-skills-zh/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/devcxl/mattpocock-skills-zh/git-guardrails-claude-code"><img src="https://agentmods.dev/badge/skills/devcxl/mattpocock-skills-zh/git-guardrails-claude-code.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 75 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 671 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
  • 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.00075 $0.00671
Opus 5 $0.00037 $0.00336
Sonnet 5 $0.00015 $0.00134
Haiku 4.5 $0.00007 $0.00067

Measured 10d ago against content hash 2299fe72bcce, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, 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 10d 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.

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

What it actually says

设置 Git 护栏

设置一个 PreToolUse 钩子,在 Claude 执行危险 Git 命令之前拦截并阻止它们。

会被阻止的命令

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

当命令被阻止时,Claude 会看到一条消息,告知它没有权限访问这些命令。

步骤

1. 询问安装范围

询问用户:是仅针对当前项目安装(.claude/settings.json),还是所有项目安装(~/.claude/settings.json)?

2. 复制钩子脚本

打包的脚本位于:scripts/block-dangerous-git.sh

根据安装范围将其复制到目标位置:

  • 项目级.claude/hooks/block-dangerous-git.sh
  • 全局~/.claude/hooks/block-dangerous-git.sh

使用 chmod +x 使其可执行。

3. 将钩子添加到设置文件

添加到相应的设置文件中:

项目级.claude/settings.json):

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

全局~/.claude/settings.json):

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

如果设置文件已存在,将钩子合并到现有的 hooks.PreToolUse 数组中:不要覆盖其他设置。

4. 询问自定义

询问用户是否需要从阻止列表中添加或移除任何模式。根据需求编辑已复制的脚本。

5. 验证

运行一个快速测试:

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

应退出并返回代码 2,并向 stderr 打印一条 BLOCKED 消息。

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. 10d ago First seen · 96 lines · 75 tokens per session scan B 2299fe72bcce

Subscribe to this mod's changes

git-guardrails-claude-code is a skill published in the GitHub repository devcxl/mattpocock-skills-zh (331 stars, last pushed 5d ago), licensed MIT. It adds 75 tokens to every session and 671 once invoked, about $0.0004 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.