git-guardrails-claude-code
Set up git guardrails for any agentic tool by blocking dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute.
Skill by swport
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/swport-git-guardrails-claude-code
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: agent-building
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
- Runs as
- Shell scripts
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/git-guardrails-claude-code
What's inside
- Skill name
git-guardrails-claude-code- Description
- Set up git guardrails for any agentic tool by blocking dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations with pre-command hooks, wrappers, or command interceptors.
- License
- MIT
- Instructions
- 125 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Files (2)
- SKILL.md
- block-dangerous-git.sh · scripts/
SKILL.md (first lines)
# Setup Git Guardrails
Sets up a command guardrail script that can be used with any agentic tool that supports one of these inputs:
- command arguments: `./block-dangerous-git.sh git push origin main`
- environment variable: `AGENT_COMMAND="git push origin main" ./block-dangerous-git.sh`
- JSON on stdin with a command field (supports `.tool_input.command`, `.toolInput.command`, `.command`, `.input.command`, `.params.command`, `.arguments.command`)
- plain command text on stdin
## 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, the script exits with code `2` and prints a BLOCKED policy message on stderr.
## Steps
### 1. Ask integration model
Ask the user how they want to integrate guardrails:
- **Hook mode (preferred)**: connect script to a pre-command/pre-tool hook
- **Wrapper mode**: route command execution through a wrapper that calls the script first
Then ask scope:
- **Project scope**: only this repository/workspace
- **Global scope**: all repositories on this machine
### 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**: `.agent-guardrails/block-dangerous-git.sh`
- **Global**: `~/.agent-guardrails/block-dangerous-git.sh`
Make it executable with `chmod +x`.
### 3. Wire it into your tool
Use your tool's pre-command hook/interceptor and pass the attempted command to this script.
Any of these invocation styles are valid:
```bash
# Args mode
/path/to/block-dangerous-git.sh git push origin main
# Env var mode
AGENT_COMMAND="git reset --hard" /path/to/block-dangerous-git.sh
# JSON mode
echo '{"command":"git clean -fd"}' | /path/to/block-dangerous-git.sh
```
If your tool can only call a shell command, create a tiny adapter that forwards the command as args or `AGENT_COMMAND`.
### 4. Optional: Claude Code compatibility example
If the user is on Claude Code, this still works with `.claude/settings.json` and `PreToolUse`.
**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"
}
]
}
]
}
}
```
If the settings file already exists, merge the hook into existing `hooks.PreToolUse` array — don't overwrite other settings.
### 5. Ask about customization
Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.
### 6. Verify
Run quick tests for both JSON and arg input styles:
```bash
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>From swport/skills, MIT.
More from swport/skills
- 0.385score
design-an-interface
swport
Generate multiple radically different interface designs for a module using parallel sub-agents.
SkillDFreshness: DClaude Code +9 - 0.380score
grill-me
swport
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree.
SkillDFreshness: DClaude Code +9
Signals
- Stars
- 0
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Mar 28, 2026 (7 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/swport/skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from swport
- 0.385score
design-an-interface
swport
Generate multiple radically different interface designs for a module using parallel sub-agents.
SkillDFreshness: DClaude Code +9 - 0.380score
grill-me
swport
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree.
SkillDFreshness: DClaude Code +9
Cite this page
git-guardrails-claude-code skill. Agent Mart. https://agentmart.dev/skills/swport-git-guardrails-claude-code (last updated 2026-10-24)