git-guardrails-claude-code

โดย mattpocock

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

npx skills add https://github.com/mattpocock/skills --skill git-guardrails-claude-code

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.

Skills เพิ่มเติมจาก mattpocock

writing-for-agents
mattpocock
การเขียนเอกสารสำหรับเอเจนต์ ใช้เมื่อสร้างหรือแก้ไขสกิล หรือแก้ไข AGENTS.md หรือ CLAUDE.md
wait-what
mattpocock
หยุด ข้อความสุดท้ายนั้นไม่เข้าถึง — ลองนำเสนอใหม่
communication
to-questionnaire
mattpocock
เปลี่ยนการตัดสินใจที่คุณตอบไม่ได้อย่างเต็มที่ให้เป็นแบบสอบถามสำหรับให้ผู้อื่นกรอก
grill-me
mattpocock
สัมภาษณ์ผู้ใช้อย่างไม่ลดละเกี่ยวกับแผนหรือการออกแบบจนกว่าจะถึงความเข้าใจร่วมกัน โดยแก้ไขแต่ละกิ่งของแผนผังการตัดสินใจ ใช้เมื่อผู้ใช้ต้องการทดสอบแผนอย่างเข้มข้น ถูกซักถามเกี่ยวกับการออกแบบ หรือพูดถึง "grill me
researchcommunicationproject-management
tdd
mattpocock
การพัฒนาที่ขับเคลื่อนด้วยการทดสอบด้วยวงจรแดง-เขียว-ปรับปรุง ใช้เมื่อผู้ใช้ต้องการสร้างฟีเจอร์หรือแก้ไขบั๊กโดยใช้ TDD กล่าวถึง "แดง-เขียว-ปรับปรุง" ต้องการการทดสอบแบบบูรณาการ หรือขอให้พัฒนาด้วยการทดสอบก่อน
developmenttesting
handoff
mattpocock
ย่อบทสนทนาปัจจุบันให้เป็นเอกสารส่งต่อสำหรับเอเจนต์อื่นเพื่อดำเนินการต่อ
communicationproject-managementdocument
prototype
mattpocock
สร้างต้นแบบที่ใช้แล้วทิ้งเพื่อขยายแบบก่อนตัดสินใจ เส้นทางระหว่างสองสาขา — แอปเทอร์มินัลที่รันได้สำหรับคำถามเกี่ยวกับสถานะ/ตรรกะทางธุรกิจ หรือรูปแบบ UI ที่แตกต่างกันอย่างสิ้นเชิงหลายแบบที่สามารถสลับได้จากเส้นทางเดียว ใช้เมื่อผู้ใช้ต้องการสร้างต้นแบบ ตรวจสอบความถูกต้องของโมเดลข้อมูลหรือสถานะเครื่องจักร สร้าง UI จำลอง สำรวจตัวเลือกการออกแบบ หรือพูดว่า "สร้างต้นแบบนี้" "ให้ฉันลองเล่นดู" "ลองออกแบบสองสามแบบ
developmentdesigncreative
triage
mattpocock
จัดการปัญหาผ่านเครื่องสถานะที่ขับเคลื่อนด้วยบทบาทการคัดแยก ใช้เมื่อผู้ใช้ต้องการสร้างปัญหา คัดแยกปัญหา ตรวจสอบข้อบกพร่องหรือคำขอฟีเจอร์ที่เข้ามา เตรียมปัญหาสำหรับเอเจนต์ AFK หรือจัดการเวิร์กโฟลว์ของปัญหา
developmentproject-managementcommunication