git-guardrails-claude-code
设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。
Security Assessment
About git-guardrails-claude-code
A setup guide (documented bilingually in Chinese and English) for installing a Claude Code PreToolUse hook that intercepts and blocks dangerous git commands before Claude runs them. It suits users who want to prevent destructive git operations or add git safety guardrails to Claude Code. When a command is blocked, Claude receives a message stating it does not have access to that command.
The hook blocks git push in all variants including --force, git reset --hard, git clean -f and -fd, git branch -D, and git checkout . as well as git restore . The installation steps first ask about scope: install only for the current project via .claude/settings.json or for all projects via ~/.claude/settings.json. A bundled script, block-dangerous-git.sh, is copied into the corresponding hooks directory and made executable with chmod +x.
The hook is then registered under hooks.PreToolUse in the chosen settings file with a Bash matcher pointing at the script, and if a settings file already exists the entry is merged into the existing PreToolUse array rather than overwriting other settings. The guide invites customizing the blocked pattern list by editing the copied script, and finishes with a verification step that pipes a test JSON payload (a git push command) into the script and expects it to exit with code 2 and print a BLOCKED message to stderr.
FAQ
Which git commands does the hook block?
git push including --force, git reset --hard, git clean -f and -fd, git branch -D, and git checkout . or git restore .
Can it be installed globally or only per project?
Either. You choose project scope via .claude/settings.json or all projects via ~/.claude/settings.json.
How does the blocking mechanism work?
A PreToolUse hook with a Bash matcher runs the script; when a dangerous command matches, the script exits with code 2 and prints a BLOCKED message to stderr, and Claude is told it lacks access.
Will installing it overwrite my existing settings?
No. If a settings file already exists, the hook is merged into the existing hooks.PreToolUse array without overwriting other settings.
Can I change which commands are blocked?
Yes. The guide asks whether you want to add or remove patterns and has you edit the copied block-dangerous-git.sh script accordingly.
Install git-guardrails-claude-code
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
vinvcn/mattpocock-skills-zh-cn