A Claude Code hook that intercepts any git push to main/master and shows Claude Code's native permission prompt — works even in --dangerously-skip-permissions (yolo) mode.
-
Install
jqif you don't have it:brew install jq # macOS sudo apt install jq # Debian/Ubuntu
-
Save the hook script and make it executable:
mkdir -p ~/.claude/hooks # copy block-push-main.sh from this gist to ~/.claude/hooks/ chmod +x ~/.claude/hooks/block-push-main.sh
-
Add to
~/.claude/settings.jsonunderhooks.PreToolUse:{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "bash ~/.claude/hooks/block-push-main.sh" } ] } ] } }
- Claude attempts
git push origin main(or any push to main/master) - Hook outputs
permissionDecision: "ask"— Claude Code shows its native allow/deny prompt - User accepts → push proceeds
- User rejects → push is cancelled
Requires jq and Claude Code with hooks support.