git-guardrails-claude-code

仓库创建 2026年7月6日最近提交 22 天前SkillHot 收录 22 天前
▸ 精选理由

极适合防止误操作导致代码/历史被破坏的高风险场景。

▸ 风险提示

安装钩子会修改本地仓库配置,可能执行外部安装脚本。

这个 Skill 做什么

在 Claude Code 中安装拦截钩子,阻止危险的 git 操作。

在 Claude Code 环境里装一个拦截钩子,提前阻止危险的 Git 操作(比如 git push、git reset --hard、git clean、git branch -D 等)被执行。适合不想让 AI 或用户误跑毁灭性命令时加一层保护。特别之处是拦截并返回说明信息,阻止命令执行并提示安全替代方案。

▸ 展开 SKILL.md 英文原文

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.

开发编程git安全钩子Claude CodeClaude Code
0
Stars
0
Forks
38
仓库内 Skill
+0
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/K3639284/skills/main/skills/misc/git-guardrails-claude-code/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/K3639284/skills/main/skills/misc/git-guardrails-claude-code/SKILL.md"
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](scripts/block-dangerous-git.sh)

Copy it t
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有