Skip to content
cccskills
FreePublished on GitHub

git-guardrails-claude-code

Set up Claude Code hooks that block specified Git commands before they run, including push and destructive cleanup operations. Choose project or global installation, adjust the blocked commands, and test that the hook rejects a sample command.

OriginalShow the original description

设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。

See how to install

Good for

  • Blocking git push from Claude Code
  • Preventing commands that discard local changes
  • Installing Git guardrails across projects
  • Customizing which Git commands are blocked

Files included (3)

  • SKILL.md2.3 KB
  • agents/openai.yaml112 B
  • scripts/block-dangerous-git.sh507 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

设置 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。

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

ask-matt

FreeSummary

Find the right skill and sequence for your current development task, from shaping an idea to implementation, debugging, and review. The guide also explains when to prototype, prepare specifications, or move work into a fresh session.

  • Choose a workflow for turning an idea into working software
  • Find the starting point for a difficult bug investigation
  • Plan specifications and tickets for work across multiple sessions
vinvcn/mattpocock-skills-zh-CN5.2KUpdated Oct 20, 2026

claude-handoff

FreeSummary

Summarize the current conversation and launch a fresh background agent to continue the work. The handoff includes references to existing artifacts and suggested skills, removes sensitive information, and can emphasize the next session’s intended focus.

  • Continue ongoing work with a fresh agent
  • Focus the next session on a specific task
  • Hand off work using references to existing documents
vinvcn/mattpocock-skills-zh-CN5.2KUpdated Oct 20, 2026

code-review

FreeSummary

Review changes from a chosen Git reference against both project coding standards and issue or specification requirements. Separate parallel reviews report rule violations, possible design problems, missing requirements, and changes beyond the intended scope.

  • Review a branch or pull request
  • Check changes since a specific commit
  • Find missing requirements or unintended scope
vinvcn/mattpocock-skills-zh-CN5.2KUpdated Oct 20, 2026

codebase-design

FreeSummary

Design modules that expose simple interfaces while hiding substantial behavior. Use shared terms and principles to assess interface complexity, decide where behavior can be swapped, and organize code so callers and tests use the same interface.

  • Simplify a module interface
  • Review module structure during refactoring
  • Decide where behavior should be swappable
vinvcn/mattpocock-skills-zh-CN5.2KUpdated Oct 20, 2026

diagnosing-bugs

FreeSummary

Diagnose difficult bugs and performance regressions by first building a repeatable check for the exact symptom. Minimize the reproduction, test ranked hypotheses, apply a fix, and verify the original scenario with regression tests where suitable.

  • Investigating persistent errors or incorrect output
  • Increasing reproduction rates for intermittent bugs
  • Measuring and diagnosing performance regressions
vinvcn/mattpocock-skills-zh-CN5.2KUpdated Oct 20, 2026

domain-modeling

FreeSummary

Clarify project terminology and the relationships between business concepts. Check definitions against concrete scenarios and code, update GLOSSARY.md as terms are agreed, and record significant design decisions with their trade-offs when the stated criteria are met.

  • Clarifying ambiguous project terminology
  • Creating or updating GLOSSARY.md
  • Checking concept boundaries against code and edge cases
vinvcn/mattpocock-skills-zh-CN5.2KUpdated Oct 20, 2026

See all skills by vinvcn

Report a problem with this skill