agentleFS
DROOdotFOODROOdotFOO/agent-skills/skills/git-guardrails/SKILL.md

git-guardrails

Skill1 starsChanged 3 months agoMITView on GitHub

Set up Codex or Claude Code hooks to block dangerous git commands before they execute. TRIGGER when: user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in an agent coding host. DO NOT TRIGGER when: user is asking about git workflow or branching strategy.

  • Deletes or force-pushes
  • Commits and pushes

3 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When blocked, the host receives a message explaining why the command is denied.

    line 34

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Git Guardrails

Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before the coding agent executes them.

What You Get

  • PreToolUse hook blocking destructive git operations
  • Project-scoped or global installation
  • Customizable blocked command patterns
  • Verification test command

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 host receives a message explaining why the command is denied.

WRONG: no guardrails, Claude runs destructive commands silently

# The coding agent decides to "clean up" and runs:
git reset --hard HEAD~3   # 3 commits of work gone
git clean -fd             # untracked files deleted
git push --force          # rewrites shared history

CORRECT: hook blocks before execution

$ echo '{"tool_input":{"command":"git push --force"}}' | block-dangerous-git.sh
BLOCKED: git push is not allowed. Ask the user to run it manually.

Setup Steps

  1. Identify host and scope -- Codex or Claude Code; project or global.
  2. Copy hook script -- bundled at scripts/block-dangerous-git.sh. Put it in the host's project or global hooks directory and make it executable.
  3. Add to settings -- see settings-config.md for Codex and Claude Code examples.
  4. Customize -- ask if user wants to add/remove patterns from the blocked list
  5. Verify -- echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script> should exit code 2 with BLOCKED message

Reference

FileTopic
settings-config.mdCodex and Claude Code hook configuration
scripts/block-dangerous-git.shThe hook script

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.