Skip to content
Back to skills

Git Guardrails Claude Code

ASecurity

ตั้งค่า hook ของ Claude Code เพื่อบล็อกคำสั่ง git อันตราย (push, reset --hard, clean, branch -D ฯลฯ) ก่อนที่มันจะถูกรัน ใช้เมื่อ user อยากป้องกัน git operation แบบทำลายล้าง อยากเพิ่ม git safety hook หรืออยากบล็อก git push/reset ใน Claude Code

  • 5 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added October 22, 2026
ai-agentsbashrailsgit

Works with

  • claude code

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned October 22, 2026

npx -y skills add Boom-Vitt/skills-thai --skill git-guardrails-claude-code --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Guardrails Claude Code?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Git Guardrails Claude Code
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/boom-vitt-git-guardrails-claude-code/badge)](https://www.skillsdirectory.com/skills/boom-vitt-git-guardrails-claude-code)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-guardrails-claude-code
description: ตั้งค่า hook ของ Claude Code เพื่อบล็อกคำสั่ง git อันตราย (push, reset --hard, clean, branch -D ฯลฯ) ก่อนที่มันจะถูกรัน ใช้เมื่อ user อยากป้องกัน git operation แบบทำลายล้าง อยากเพิ่ม git safety hook หรืออยากบล็อก git push/reset ใน Claude Code
---

# ตั้งค่า Git Guardrails

ตั้งค่า PreToolUse hook ที่คอยดักและบล็อกคำสั่ง git อันตรายก่อนที่ Claude จะรันมัน

## อะไรบ้างที่ถูกบล็อก

- `git push` (ทุก variant รวมถึง `--force`)
- `git reset --hard`
- `git clean -f` / `git clean -fd`
- `git branch -D`
- `git checkout .` / `git restore .`

เมื่อถูกบล็อก Claude จะเห็นข้อความบอกว่ามันไม่มีสิทธิ์เข้าถึงคำสั่งเหล่านี้

## ขั้นตอน

### 1. ถาม scope

ถาม user: จะติดตั้งสำหรับ **โปรเจกต์นี้เท่านั้น** (`.claude/settings.json`) หรือ **ทุกโปรเจกต์** (`~/.claude/settings.json`)?

### 2. copy script ของ hook

script ที่แนบมากับ skill นี้อยู่ที่: [scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh)

copy ไปไว้ที่ตำแหน่งปลายทางตาม scope:

- **Project**: `.claude/hooks/block-dangerous-git.sh`
- **Global**: `~/.claude/hooks/block-dangerous-git.sh`

ทำให้มันรันได้ด้วย `chmod +x`

### 3. เพิ่ม hook ลงใน settings

เพิ่มลงในไฟล์ settings ที่ตรงกับ scope:

**Project** (`.claude/settings.json`):

```json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
          }
        ]
      }
    ]
  }
}
```

**Global** (`~/.claude/settings.json`):

```json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/block-dangerous-git.sh"
          }
        ]
      }
    ]
  }
}
```

ถ้าไฟล์ settings มีอยู่แล้ว ให้ merge hook เข้าไปใน array `hooks.PreToolUse` เดิม — อย่าเขียนทับ setting อื่น

### 4. ถามเรื่องการปรับแต่ง

ถามว่า user อยากเพิ่มหรือลบ pattern จากรายการที่ถูกบล็อกไหม แล้วแก้ script ที่ copy มาให้ตรงตามนั้น

### 5. ตรวจสอบ

รัน test สั้น ๆ:

```bash
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>
```

ควรจบด้วย exit code 2 และ print ข้อความ BLOCKED ออกทาง stderr

Files in this skill

  • SKILL.md3.4 KB
  • scripts/block-dangerous-git.sh507 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.