Skip to content

Block git --no-verify to enforce hook execution #4

@AlexMikhalev

Description

@AlexMikhalev

Summary

Added protection against git commit --no-verify and git push --no-verify commands that bypass git hooks.

Changes Made

  1. Updated git-safety-guard skill (skills/git-safety-guard/SKILL.md)

    • Added git commit --no-verify to blocked patterns
    • Added git commit -n (short form) to blocked patterns
    • Added git push --no-verify to blocked patterns
  2. Updated global pre_tool_use.sh hook (~/.claude/hooks/pre_tool_use.sh)

    • Added regex pattern matching for hook bypass flags
    • Properly handles quoted strings to avoid false positives in commit messages
    • Returns deny decision to Claude Code when bypass flags detected

Why This Matters

Git hooks enforce code quality and security checks (linting, tests, commit message validation). Allowing AI agents to bypass these with --no-verify defeats the purpose of having hooks.

Testing

Verified that:

  • Normal commits pass through
  • git commit --no-verify is blocked
  • git commit -n is blocked
  • git push --no-verify is blocked
  • Commit messages containing '--no-verify' as text are NOT blocked

Related Commit

37bd4e1 feat(git-safety-guard): block hook bypass flags

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions