Available in
Marketplaces, most starred first
Tags
Add to README
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
By karanb192v1.0.1MITIn 1 marketplace
Denies destructive git and gh commands before Claude runs them, such as pushing to main, deleting protected branches or merging PRs. Runs on every Bash call; the strict level also blocks force-pushes, set via HOOK_SAFETY_LEVEL.
Trending plugins
7-day copy clicks
Run automatically on Claude Code events. Claude doesn't decide.
1 caution to review before installing
A hook runs when Claude uses the Bash tool
Static checks of hooks, mods, MCP servers and commands. Not a security audit.
1 marketplace, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Branch-aware git guardrails plus destructive gh CLI protection: denies the operations that rewrite shared history or close things you didn't mean to close.
A PreToolUse hook fires before every Bash call and checks the command against a tiered pattern list. On a match it returns permissionDecision: "deny" with the pattern id and reason, so Claude sees exactly why the command was refused. Branch-aware rules (git commit, merge, rebase, reset, push while on a protected branch) resolve the current branch via git branch --show-current at check time; everything else matches on the command text alone. Protected branches are main and master.
/plugin marketplace add karanb192/claude-code-hooks # once per machine
/plugin install git-safety@claude-code-hooks
Restart Claude Code, done. (Or from a shell: claude plugin install git-safety@claude-code-hooks.)
| Event | Runs | What happens |
|---|---|---|
PreToolUse (Bash) | sync | Checks the command against the active safety level's patterns; on a match, denies with the pattern id and reason, and appends a log row. Non-matching commands pass through untouched ({}). |
Blocked at the default high level:
git push naming main or master as a ref (origin main, HEAD:main, +main, refs/heads/main; any flags). A branch that only contains the word, such as my-main-feature, is not blockedgit branch -d / -D / --delete on main or mastergit commit, git merge, git rebase, git reset, git push while the current branch is main or mastergh pr merge, gh pr close, gh issue close, gh release delete, gh repo deletestrict adds any force-push (--force or -f; --force-with-lease stays allowed). critical applies no git-safety rules at all, deferring entirely to block-dangerous-commands.
Composition with block-dangerous-commands: that hook already blocks force-push (any, and to main/master) and git reset --hard on any branch, so at high the two don't overlap. Run git-safety at strict if you use it on its own.
Optional, set via environment variable:
| Variable | Default | Purpose |
|---|---|---|
HOOK_SAFETY_LEVEL | high | Safety level: critical, high, or strict. Invalid values fall back to high. |
| Level | What's blocked |
|---|---|
critical | Nothing from this hook (defer entirely to block-dangerous-commands) |
high | Branch-aware guardrails, protected-branch deletion, pushes to main/master by name, destructive gh CLI operations |
strict | All of high plus any force-push, so the hook is self-sufficient standalone |
The SAFETY_LEVEL constant in the script still exists, but prefer the env var: plugin updates overwrite installed files, so edits don't survive. This hook always denies; it has no ask mode.
Blocked commands are logged (with timestamp, pattern id, session id, cwd, and permission mode) to ~/.claude/hooks-logs/<date>.jsonl. The only command it runs is git branch --show-current, locally; it makes no network calls.
/plugin uninstall git-safety@claude-code-hooks
Part of claude-code-hooks.
Built from public signals: copy clicks on this site, GitHub stars and activity, the README and the manifest. Not a security audit or an endorsement.
npx claudepluginhub karanb192/claude-code-hooks --plugin git-safetyPlugins from other owners that cover similar ground