Tooluck logoTooluck
SKILL.md

git-guardrails-claude-code

Agent skill fromvinvcn/mattpocock-skills-zh-CN

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

How to install git-guardrails-claude-code

install git-guardrails-claude-code
# install the mattpocock-skills-zh-CN pack with the skills CLI
npx skills add vinvcn/mattpocock-skills-zh-CN

# or add only this skill to Claude Code: copy the folder

skills/misc/git-guardrails-claude-code/

# into

~/.claude/skills/git-guardrails-claude-code/ (all projects)

.claude/skills/git-guardrails-claude-code/ (one project)

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

MITFull file
1# 设置 Git Guardrails
2
3设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。
4
5## 会被阻止的命令
6
7- `git push`(包括 `--force` 在内的所有 variants)
8- `git reset --hard`
9- `git clean -f` / `git clean -fd`
10- `git branch -D`
11- `git checkout .` / `git restore .`
12
13被阻止时,Claude 会看到一条 message,说明它无权访问这些 commands。
14
15## 步骤
16
17### 1. 询问安装范围
18
19询问用户:只为**当前 project** 安装(`.claude/settings.json`),还是为**所有 projects** 安装(`~/.claude/settings.json`)?
20
21### 2. 复制 hook 脚本
22
23bundled script 位于:[scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh)
24
25根据 scope 复制到目标位置:
26
27- **Project**: `.claude/hooks/block-dangerous-git.sh`
28- **Global**: `~/.claude/hooks/block-dangerous-git.sh`
29
30用 `chmod +x` 让它可执行。
31
32### 3. 把 hook 加入 settings
33
34添加到对应 settings file:
35
36**Project** (`.claude/settings.json`):
37
38```json
39{
40 "hooks": {
41 "PreToolUse": [
42 {
43 "matcher": "Bash",
44 "hooks": [
45 {
46 "type": "command",
47 "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
48 }
49 ]
50 }
51 ]
52 }
53}
54```
55
56**Global** (`~/.claude/settings.json`):
57
58```json
59{
60 "hooks": {
61 "PreToolUse": [
62 {
63 "matcher": "Bash",
64 "hooks": [
65 {
66 "type": "command",
67 "command": "~/.claude/hooks/block-dangerous-git.sh"
68 }
69 ]
70 }
71 ]
72 }
73}
74```
75
76如果 settings file 已存在,把 hook merge 到现有 `hooks.PreToolUse` array 中,不要覆盖其他 settings。
77
78### 4. 询问是否定制
79
80询问用户是否要在 blocked list 中添加或移除 patterns。相应编辑复制后的 script。
81
82### 5. 验证
83
84运行快速测试:
85…

Excerpt shown under the repository's MIT license.

More skills in mattpocock-skills-zh-CN

Keep exploring

Similar skill repositories

thedotmack /

claude-mem
116k

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

CCCXGHGM+135 skills

Newsletter

Join the Community

Subscribe to our newsletter for the latest news and updates