AGENT SKILL

Claude Code Git 安全钩子配置

git-guardrails-claude-code

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

License 许可
MIT
所属仓库
pkking/dotfiles
最近更新
2026-11-14
Stars
★ 0
Forks
0

01 前言 Front Matter

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.

02 资源文件 2

03 SKILL.md 正文

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.

04 同仓库更多 Skills

pkking
pkking/dotfiles

前端界面视觉设计

frontend-design

在构建新 UI 或重塑现有 UI 时,提供有特色、有意为之的视觉设计指导。帮助把握美学方向、排版,并做出不显得千篇一律的模板化选择。

界面设计师前端开发与界面实现
★ 0
pkking
pkking/dotfiles

AIHOT AI 资讯查询

aihot

查询 AIHOT 的中文 AI 资讯、精选、当前热点和日报。用户询问今天或最近的 AI 新闻、AI 圈动态、大模型或产品发布、OpenAI/Anthropic/Google 最新消息、AI 论文、AI 日报、AIHOT 精选、当前最热事件,或需要同步当前全部精选时使用。必须通过 aihot.news 的匿名只读 API 获取当前数据,不凭训练记忆回答新闻;不需要 API Key 或 MCP server。

普通用户工具调用与实时数据查询
★ 0
pkking
pkking/dotfiles

文章段落塑形

writing-shape

写作,深入挖掘(exploit):把原始素材塑造成一篇文章,逐段推进。

内容创作者创意写作与内容编排
★ 0
pkking
pkking/dotfiles

Skill 编写规范参考

writing-great-skills

编写和编辑 skills 的参考指南——介绍让技能变得可预测的语言与原则。

AI 工程师插件与技能管理
★ 0
pkking
pkking/dotfiles

写作素材片段挖掘

writing-fragments

写作,探索(explore):挖掘原始片段,暂不组织结构。

内容创作者创意写作与内容编排
★ 0
pkking
pkking/dotfiles

智能体文档编写

writing-for-agents

为智能体(agent)编写文档。在创建或编辑 skills,或修改 AGENTS.md 或 CLAUDE.md 时使用。

AI 工程师智能体开发
★ 0