git-guardrails-claude-code
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.
npx skills add stevesolun/ctx --skill git-guardrails-claude-code --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# 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 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`): ```json { "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh" } ] } ] } } ``` **Global** (`~/.claude/settings.json`): ``
- What Gets Blocked
- Steps
- 1. Ask scope
- 2. Copy the hook script
- 3. Add hook to settings
- 4. Ask about customization
- 5. Verify
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>What does the git-guardrails-claude-code skill do?
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.
How do I install it?
Run `npx skills add stevesolun/ctx --skill git-guardrails-claude-code --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From stevesolun/ctx, a repository with 569 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
