git-guardrails
Set up Codex or 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.
How do I install this agent skill?
npx skills add https://github.com/christofferbergj/agent-skills --skill git-guardrailsIs this agent skill safe to install?
- Gen Agent Trust Hubpass
This skill is a security guardrail designed to prevent AI agents from executing destructive Git commands. It works by installing a Python-based hook that inspects shell commands before they are run. No malicious patterns, data exfiltration, or unauthorized network operations were detected.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
Set up Git guardrails
What Gets Blocked
git push(all variants including--force)git reset --hardgit clean -f/git clean -fdgit branch -Dgit checkout ./git restore .
When blocked, the agent sees a message telling it that it does not have authority to access these commands.
Steps
- Resolve the user's requested host, project/global scope, and blocked operations. Ask if user wants to add or remove any patterns from the blocked list. Inspect existing settings and actual hook capability before editing. Merely installing this skill changes no host settings. Complete when the target and policy are authorized and concrete.
- Copy the Python detector to the agreed hook location and verify Python 3 is available. Edit the copied detector for any added or removed patterns. It inspects ordinary literal Git shell commands, including common Git options and shell separators. It is an accidental-operation guardrail, not a complete shell sandbox: aliases, opaque scripts, indirect language runtimes, or unsupported host paths can bypass it. Use host permissions for enforcement. Complete when the detector passes its fixture cases and limitations match the requested policy.
- Read the matching host reference below and merge a command hook into existing settings without replacing unrelated hooks. Resolve an absolute script path, or the host's documented project-directory form for a project hook; never build a command from untrusted issue text. Complete when the saved matcher and command use that host's documented schema.
- Test harmless allowed and denied events using stdin fixtures; a denied fixture such as
git push origin mainshould exit with code 2 and print a BLOCKED message to stderr, then verify the host actually invokes the hook without running a destructive command. Codex hooks require native review/trust; report a pending trust step accurately and never bypass it. Complete when observed host behavior matches the policy or activation remains an explicit gap.
Host adapters
- For Codex, read the Codex adapter.
- For Claude Code, read the Claude Code adapter.
The optional scripts/block-dangerous-git.sh wrapper invokes the Python detector for existing shell-hook launchers. Both adapters use the same detector and JSON deny response. Run python3 -m unittest discover -s scripts/tests -v from this skill to exercise its bounded command coverage.
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/christofferbergj/agent-skills/git-guardrails">View git-guardrails on skillZs</a>