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 (627 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 — 38 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 · 5,317 stars · on GitHub · skills.sh

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 38 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 627 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 14 Sept 2026
  • Snyk pass 14 Sept 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.00627
Opus 5.5 $0.00027 $0.00251
Sonnet 5.5 $0.00014 $0.00125
Haiku 4.5 $0.00007 $0.00063

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

设置 Git Guardrails

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

会被阻止的命令

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

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

步骤

1. 询问安装范围

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

2. 复制 hook 脚本

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. 把 hook 加入 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. 询问是否定制

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

5. 验证

运行快速测试:

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. 18d ago Changed 3bfcf331a62c
  2. 1mo 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 (5,317 stars, last pushed 7d ago), licensed MIT. It adds 68 tokens to every session and 627 once invoked, about $0.0003 per session on Opus 5.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

setup-pre-commit

A setup guide for Git pre-commit checks, which run automatically before a commit is created. It configures Husky, lint-staged, Prettier, type checking, and tests in a repository.

devcxl/mattpocock-skills-zh · 70 tokens

claude-handoff

A handoff tool that prepares a summary of the current conversation for another coding agent and starts that agent in the background.

devcxl/mattpocock-skills-zh · 25 tokens

git-guardrails-claude-code

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

devcxl/mattpocock-skills-zh · 75 tokens

agentic-jujutsu

Quantum-resistant, self-learning version control for AI agents, with ReasoningBank intelligence and multi-agent coordination. Use when designing agent memory/versioning, coordinating multiple agents over shared state, or building experience-replay and learning loops into an agentic system.

frankxai/claude-skills-library · 57 tokens

github-multi-repo

Multi-repository coordination, synchronization, and architecture management across many GitHub repos. Use when changes span several repositories, keeping repos in sync, or planning cross-repo architecture and dependency work.

frankxai/claude-skills-library · 44 tokens

verification-loop

After a feature or refactor on this Windows estate, run six checks in order and write a PASS or FAIL note before a draft pull request. Use when work is about to be committed, pushed, or handed to another harness.

frankxai/claude-skills-library · 49 tokens