Git Guardrails Claude Code logo

Git Guardrails Claude Code

Community
WenWuZhiDao
git-guardrails-claude-code

设置 Claude Code 钩子,在危险的 git 命令(push、reset --hard、clean、branch -D 等)执行前将其拦截。当用户想阻止破坏性 git 操作、添加 git 安全钩子,或在 Claude Code 中拦截 git push/reset 时使用。

Overview

PublisherWenWuZhiDao
Repositorymattpocock-skills-zh
Skill namegit-guardrails-claude-code
Stars
30
Forks
5
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by WenWuZhiDao on GitHub. Read the source before you install it.

Installation

Install the Git Guardrails Claude Code AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/WenWuZhiDao/mattpocock-skills-zh/tree/main/skills/misc/git-guardrails-claude-code
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/WenWuZhiDao/mattpocock-skills-zh.git /tmp/mattpocock-skills-zh
mkdir -p .claude/skills
cp -r /tmp/mattpocock-skills-zh/skills/misc/git-guardrails-claude-code .claude/skills/git-guardrails-claude-code
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Git Guardrails Claude Code in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Git Guardrails Claude Code on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Git Guardrails Claude Code is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

设置 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):

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

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

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

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

4. 询问是否自定义

询问用户是否想从阻止列表中添加或移除某些模式。相应地编辑复制后的脚本。

5. 验证

运行一个快速测试:

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

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

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Git Guardrails Claude Code AI skill do?

设置 Claude Code 钩子,在危险的 git 命令(push、reset --hard、clean、branch -D 等)执行前将其拦截。当用户想阻止破坏性 git 操作、添加 git 安全钩子,或在 Claude Code 中拦截 git push/reset 时使用。

Why use Git Guardrails Claude Code on TypingMind?

Because you install it once and use it with any model. Git Guardrails Claude Code is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Git Guardrails Claude Code in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/WenWuZhiDao/mattpocock-skills-zh/tree/main/skills/misc/git-guardrails-claude-code. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Git Guardrails Claude Code?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Git Guardrails Claude Code?

As many as you like. As long as a model supports skills, you can use Git Guardrails Claude Code with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Git Guardrails Claude Code AI skill free?

Yes. It is published on GitHub by WenWuZhiDao under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇