Agent SkillsRemocn/remocn › git-guardrails-claude-code

git-guardrails-claude-code

GitHub

在 Claude Code 中配置 PreToolUse 钩子,拦截并阻止 git push、reset --hard 等危险操作。支持项目级或全局安装,通过脚本验证阻断效果,防止误执行破坏性命令。

agent/skills/git-guardrails-claude-code/SKILL.md Remocn/remocn

Trigger Scenarios

用户希望阻止危险的 git 操作 需要为 Claude Code 添加 git 安全钩子 要求禁用 git push 或 reset

Install

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

Non-standard path

npx skills add https://github.com/Remocn/remocn/tree/main/agent/skills/git-guardrails-claude-code -g -y

Use without installing

npx skills use Remocn/remocn@git-guardrails-claude-code

指定 Agent (Claude Code)

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

安装 repo 全部 skill

npx skills add Remocn/remocn --all -g -y

预览 repo 内 skill

npx skills add Remocn/remocn --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 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

  • f77e19e Current 2026-07-19 22:36

Same Skill Collection

.agents/skills/ask-matt/SKILL.md
.agents/skills/claude-handoff/SKILL.md
.agents/skills/code-review/SKILL.md
.agents/skills/codebase-design/SKILL.md
.agents/skills/design-an-interface/SKILL.md
.agents/skills/diagnosing-bugs/SKILL.md
.agents/skills/domain-modeling/SKILL.md
.agents/skills/edit-article/SKILL.md
.agents/skills/git-guardrails-claude-code/SKILL.md
.agents/skills/grilling/SKILL.md
.agents/skills/handoff/SKILL.md
.agents/skills/implement/SKILL.md
.agents/skills/improve-codebase-architecture/SKILL.md
.agents/skills/loop-me/SKILL.md
.agents/skills/migrate-to-shoehorn/SKILL.md
.agents/skills/obsidian-vault/SKILL.md
.agents/skills/prototype/SKILL.md
.agents/skills/qa/SKILL.md
.agents/skills/request-refactor-plan/SKILL.md
.agents/skills/research/SKILL.md
.agents/skills/resolving-merge-conflicts/SKILL.md
.agents/skills/scaffold-exercises/SKILL.md
.agents/skills/setup-matt-pocock-skills/SKILL.md
.agents/skills/setup-pre-commit/SKILL.md
.agents/skills/tdd/SKILL.md
.agents/skills/teach/SKILL.md
.agents/skills/to-spec/SKILL.md
.agents/skills/to-tickets/SKILL.md
.agents/skills/triage/SKILL.md
.agents/skills/ubiquitous-language/SKILL.md
.agents/skills/wayfinder/SKILL.md
.agents/skills/wizard/SKILL.md
.agents/skills/writing-beats/SKILL.md
.agents/skills/writing-fragments/SKILL.md
.agents/skills/writing-great-skills/SKILL.md
.agents/skills/writing-shape/SKILL.md
.claude/skills/interactivity-best-practices/SKILL.md
agent/skills/ask-matt/SKILL.md
agent/skills/claude-handoff/SKILL.md
agent/skills/code-review/SKILL.md
agent/skills/codebase-design/SKILL.md
agent/skills/design-an-interface/SKILL.md
agent/skills/diagnosing-bugs/SKILL.md
agent/skills/domain-modeling/SKILL.md
agent/skills/edit-article/SKILL.md
agent/skills/grilling/SKILL.md
agent/skills/handoff/SKILL.md
agent/skills/implement/SKILL.md
agent/skills/improve-codebase-architecture/SKILL.md
agent/skills/loop-me/SKILL.md
agent/skills/migrate-to-shoehorn/SKILL.md
agent/skills/obsidian-vault/SKILL.md
agent/skills/prototype/SKILL.md
agent/skills/qa/SKILL.md
agent/skills/request-refactor-plan/SKILL.md
agent/skills/research/SKILL.md
agent/skills/resolving-merge-conflicts/SKILL.md
agent/skills/scaffold-exercises/SKILL.md
agent/skills/setup-matt-pocock-skills/SKILL.md
agent/skills/setup-pre-commit/SKILL.md
agent/skills/tdd/SKILL.md
agent/skills/teach/SKILL.md
agent/skills/to-spec/SKILL.md
agent/skills/to-tickets/SKILL.md
agent/skills/triage/SKILL.md
agent/skills/ubiquitous-language/SKILL.md
agent/skills/wayfinder/SKILL.md
agent/skills/wizard/SKILL.md
agent/skills/writing-beats/SKILL.md
agent/skills/writing-fragments/SKILL.md
agent/skills/writing-great-skills/SKILL.md
agent/skills/writing-shape/SKILL.md
skills/remocn/SKILL.md
.agents/skills/grill-me/SKILL.md
.agents/skills/grill-with-docs/SKILL.md
agent/skills/grill-me/SKILL.md
agent/skills/grill-with-docs/SKILL.md

Metadata

Files
0
Version
140c226
Hash
eb3a0121
Indexed
2026-07-19 22:36

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