Agent Skillsmattpocock/skills › git-guardrails-claude-code

git-guardrails-claude-code

GitHub

通过配置 PreToolUse 钩子拦截并阻止危险的 Git 命令(如 push、reset --hard),防止误操作。支持按项目或全局范围安装,提供脚本定制与验证步骤,增强 Claude Code 使用安全性。

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

Trigger Scenarios

用户希望阻止危险 git 操作 需要添加 git 安全钩子 想在 Claude Code 中限制 git push/reset

Install

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

Non-standard path

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

Use without installing

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.

Version History

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

Same Skill Collection

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/retro/SKILL.md
skills/engineering/grill-with-docs/SKILL.md
skills/productivity/grill-me/SKILL.md

Metadata

Files
0
Version
6654f6b
Hash
69b291d6
Indexed
2026-07-24 15:57

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-30 08:14
浙ICP备14020137号-1 $お客様$