Agent Skills › mattpocock/skills › git-guardrails-claude-code

git-guardrails-claude-code

GitHub

通过配置 PreToolUse 钩子拦截危险 Git 命令,防止误操作。支持项目级或全局安装,提供脚本部署、设置合并及功能验证步骤。

skills/misc/git-guardrails-claude-code/SKILL.md mattpocock/skills

触发场景

用户希望阻止危险的 git 操作 需要添加 git 安全钩子

安装

npx skills add mattpocock/skills --skill git-guardrails-claude-code -g -y
更多选项

非标准路径

npx skills add https://github.com/mattpocock/skills/tree/main/skills/misc/git-guardrails-claude-code -g -y

不安装直接使用

npx skills use mattpocock/skills@git-guardrails-claude-code

指定 Agent (Claude Code)

npx skills add mattpocock/skills --skill git-guardrails-claude-code -a claude-code -g -y

安装 repo 全部 skill

npx skills add mattpocock/skills --all -g -y

预览 repo 内 skill

npx skills add mattpocock/skills --list

SKILL.md

Frontmatter
{
    "name": "git-guardrails-claude-code",
    "description": "Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push\/reset in Claude Code."
}

Setup Git Guardrails

Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.

What Gets Blocked

  • git push (all variants including --force)
  • git reset --hard
  • git clean -f / git clean -fd
  • git branch -D
  • git checkout . / git restore .

When blocked, Claude sees a message telling it that it does not have authority to access these commands.

Steps

1. Ask scope

Ask the user: install for this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?

2. Copy the hook script

The bundled script is at: scripts/block-dangerous-git.sh

Copy it to the target location based on scope:

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

Make it executable with chmod +x.

3. Add hook to settings

Add to the appropriate 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"
          }
        ]
      }
    ]
  }
}

If the settings file already exists, merge the hook into the existing hooks.PreToolUse array. Don't overwrite other settings.

4. Ask about customization

Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.

5. Verify

Run a quick test:

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

Should exit with code 2 and print a BLOCKED message to stderr.

版本历史

  • 1bb9595 当前 2026-08-19 19:44
  • ed37663 2026-07-24 15:57

同 Skill 集合

skills/deprecated/design-an-interface/SKILL.md
skills/deprecated/qa/SKILL.md
skills/deprecated/request-refactor-plan/SKILL.md
skills/deprecated/ubiquitous-language/SKILL.md
skills/engineering/ask-matt/SKILL.md
skills/engineering/code-review/SKILL.md
skills/engineering/codebase-design/SKILL.md
skills/engineering/diagnosing-bugs/SKILL.md
skills/engineering/domain-modeling/SKILL.md
skills/engineering/implement/SKILL.md
skills/engineering/improve-codebase-architecture/SKILL.md
skills/engineering/prototype/SKILL.md
skills/engineering/research/SKILL.md
skills/engineering/resolving-merge-conflicts/SKILL.md
skills/engineering/setup-matt-pocock-skills/SKILL.md
skills/engineering/tdd/SKILL.md
skills/engineering/to-spec/SKILL.md
skills/engineering/to-tickets/SKILL.md
skills/engineering/triage/SKILL.md
skills/engineering/wayfinder/SKILL.md
skills/engineering/wizard/SKILL.md
skills/in-progress/batch-grill-me/SKILL.md
skills/in-progress/claude-handoff/SKILL.md
skills/in-progress/loop-me/SKILL.md
skills/in-progress/setup-ts-deep-modules/SKILL.md
skills/in-progress/to-questionnaire/SKILL.md
skills/in-progress/wizard/SKILL.md
skills/in-progress/writing-beats/SKILL.md
skills/in-progress/writing-fragments/SKILL.md
skills/in-progress/writing-shape/SKILL.md
skills/misc/migrate-to-shoehorn/SKILL.md
skills/misc/scaffold-exercises/SKILL.md
skills/misc/setup-pre-commit/SKILL.md
skills/personal/edit-article/SKILL.md
skills/personal/obsidian-vault/SKILL.md
skills/productivity/grilling/SKILL.md
skills/productivity/handoff/SKILL.md
skills/productivity/teach/SKILL.md
skills/productivity/to-questionnaire/SKILL.md
skills/productivity/wait-what/SKILL.md
skills/productivity/writing-for-agents/SKILL.md
skills/productivity/writing-great-skills/SKILL.md
skills/in-progress/implement-spec/SKILL.md
skills/in-progress/pr/SKILL.md
skills/in-progress/retro/SKILL.md
skills/engineering/grill-with-docs/SKILL.md
skills/productivity/grill-me/SKILL.md

元信息

文件数
0
版本
c55ee46
Hash
69b291d6
收录时间
2026-07-24 15:57

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-12 18:55
浙ICP备14020137号-1