Agent skill · AI & Agents

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.

stevesolungithub.com/stevesolunGitHub ↗
claude-codeships scriptsMIT
Install
npx skills add stevesolun/ctx --skill git-guardrails-claude-code --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 2
SKILL.md size: 2 KB
Bundled scripts: yes
Path: imported-skills/mattpocock/git-guardrails-claude-code/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 569
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# 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's inside
Steps it walks through
  1. What Gets Blocked
  2. Steps
  3. 1. Ask scope
  4. 2. Copy the hook script
  5. 3. Add hook to settings
  6. 4. Ask about customization
  7. 5. Verify
Ships with 1 file
  • scripts/block-dangerous-git.sh
Commands it runs
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>
More from ctx
All skills →
About this skill
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.

Keep going