| name | Git Hooks Integration |
| description | The agent implements Git hooks that integrate with the workflow config system, automating pre-commit checks, commit message validation, pre-push tests, and post-merge actions. |
| category | devops |
| related_skills | ["devops/workflow-config","devops/github-actions","testing/comprehensive-testing","methodology/test-driven-development"] |
| related_commands | ["/hooks:setup","/hooks:run","/workflow:init","/dev:test"] |
Git Hooks Integration
Overview
Git Hooks Integration provides automated enforcement of workflow rules through Git hooks. Hooks are configured in .omgkit/workflow.yaml and automatically installed to .git/hooks/. This ensures consistent code quality, commit conventions, and testing before code reaches the remote repository.
Available Hooks
| Hook | Trigger | Purpose |
|---|
pre-commit | Before commit | Lint, format, type-check |
commit-msg | After commit message | Validate conventional commits |
pre-push | Before push | Run tests, security scan |
post-merge | After merge/pull | Install deps, run migrations |
post-checkout | After checkout | Environment setup |
Configuration
Basic Configuration
hooks:
pre_commit:
enabled: true
actions:
- lint
- format
commit_msg:
enabled: true
validate_conventional: true
pre_push:
enabled: true
actions:
- test
Full Configuration
hooks:
pre_commit:
enabled: true
actions:
- lint
- type-check
- format
- secrets-check
fail_fast: true
staged_only: true
bypass_key: "SKIP_HOOKS"
commit_msg:
enabled: true
validate_conventional: true
allowed_types:
- feat
- fix
- docs
- style
- refactor
- perf
- test
- chore
- ci
-
Hook Actions
Pre-commit Actions
| Action | Description | Command |
|---|
lint | Run linter | Auto-detected |
format | Format code | Auto-detected |
type-check | Type checking | Auto-detected |
secrets-check | Detect secrets | git-secrets |
test-staged | Test staged files | vitest related |
Auto-detection Logic:
lint: npx eslint --fix
format: npx prettier --write
type-check: npx tsc --noEmit
lint: ruff check --fix
format: black
type-check: mypy
lint: golangci-lint run
format: gofmt -w
type-check: go vet
lint: cargo clippy
format: cargo fmt
type-check: cargo check
Pre-push Actions
| Action | Description | Command |
|---|
test | Run tests | Auto-detected |
test-coverage | With coverage | Auto-detected |
security-scan | Security audit | Auto-detected |
build | Verify build | Auto-detected |
review | Claude review | /dev:review |
Auto-detection Logic:
test: npm test
security-scan: npm audit
build: npm run build
test: pytest
security-scan: safety check
build: python -m build
test: go test ./...
security-scan: gosec ./...
build: go build
Installation
Automatic Setup
/hooks:setup
Manual Setup
Run /hooks:setup which creates executable scripts in .git/hooks/:
.git/hooks/
├── pre-commit
├── commit-msg
├── pre-push
└── post-merge
Hook Script Templates
Pre-commit Hook
#!/bin/bash
set -e
if [ -n "$SKIP_HOOKS" ]; then
echo "Skipping pre-commit hooks (SKIP_HOOKS is set)"
exit 0
fi
echo "Running pre-commit checks..."
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
if [ -z "$STAGED_FILES" ]; then
echo "No staged files to check"
exit 0
fi
echo " Running lint..."
if command -v npx &> /dev/null && [ -f "package.json" ]; then
npx eslint --fix $STAGED_FILES
elif command -v ruff &> /dev/null; then
ruff check --fix $STAGED_FILES
fi
echo " Running format..."
if command -v npx &> /dev/null && [ -f "package.json" ]; then
npx prettier --write $STAGED_FILES
git add $STAGED_FILES
fi
echo
[ -f ];
npx tsc --noEmit
Commit-msg Hook
#!/bin/bash
set -e
COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
PATTERN="^(feat|fix|docs|style|refactor|perf|test|chore|ci|build)(\(.+\))?: .{1,72}$"
FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)
if ! echo "$FIRST_LINE" | grep -qE "$PATTERN"; then
echo "ERROR: Invalid commit message format"
echo ""
echo "Expected format: type(scope): subject"
echo " type: feat|fix|docs|style|refactor|perf|test|chore|ci|build"
echo " scope: optional, in parentheses"
echo " subject: max 72 characters"
echo ""
echo "Examples:"
echo " feat: add user authentication"
echo " fix(api): resolve null pointer exception"
echo " docs(readme): update installation guide"
echo ""
echo "Your message: $FIRST_LINE"
exit 1
SUBJECT_LENGTH=
MAX_LENGTH=72
[ -gt ];
1
Pre-push Hook
#!/bin/bash
set -e
if [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then
echo "Skipping pre-push hooks (CI environment)"
exit 0
fi
if [ -n "$SKIP_HOOKS" ]; then
echo "Skipping pre-push hooks (SKIP_HOOKS is set)"
exit 0
fi
echo "Running pre-push checks..."
echo " Running tests..."
if [ -f "package.json" ]; then
npm test
elif [ -f "pytest.ini" ] || [ -f "pyproject.toml" ]; then
pytest
elif [ -f "go.mod" ]; then
go test ./...
fi
echo " Running security scan..."
if [ -f "package.json" ]; then
npm audit --audit-level=high || true
elif command -v safety &> /dev/null; then
safety check ||
Commands
/hooks:setup
Install or update Git hooks based on workflow config:
/hooks:setup
/hooks:setup --force
/hooks:setup --dry-run
/hooks:setup --hook=pre-commit
/hooks:run
Manually run hook actions:
/hooks:run pre-commit
/hooks:run commit-msg
/hooks:run pre-push
/hooks:run pre-commit --action=lint
/hooks:run pre-commit --action=format
Bypassing Hooks
Temporary Bypass
SKIP_HOOKS=1 git commit -m "wip: temp commit"
git commit --no-verify -m "emergency fix"
Permanent Exclusions
hooks:
pre_commit:
exclude_paths:
- "vendor/**"
- "node_modules/**"
- "*.generated.*"
Troubleshooting
Hook Not Executing
-
Check hook is executable:
ls -la .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
-
Regenerate hooks:
/hooks:setup --force
-
Check config:
hooks:
pre_commit:
enabled: true
Hook Failing
-
Run manually to see errors:
/hooks:run pre-commit
-
Check staged files:
git diff --cached --name-only
-
Bypass temporarily:
SKIP_HOOKS=1 git commit -m "message"
Performance Issues
-
Use staged-only checking:
hooks:
pre_commit:
staged_only: true
-
Skip slow checks locally:
hooks:
pre_push:
skip_on_ci: true
Integration with CI/CD
Hooks complement CI/CD but don't replace it:
| Check | Local Hook | CI/CD |
|---|
| Lint | pre-commit | Yes |
| Format | pre-commit | Yes |
| Type-check | pre-commit | Yes |
| Unit tests | pre-push | Yes |
| Integration tests | No | Yes |
| E2E tests | No | Yes |
| Security scan | pre-push | Yes |
| Build | pre-push | Yes |
| Deploy | No | Yes |
Best Practices
Fast Pre-commit
Keep pre-commit under 5 seconds:
hooks:
pre_commit:
actions:
- lint
- format
staged_only: true
Comprehensive Pre-push
Run thorough checks before pushing:
hooks:
pre_push:
actions:
- test
- type-check
- security-scan
- build
Team Consistency
Commit .omgkit/workflow.yaml to ensure all team members have same hooks:
git add .omgkit/workflow.yaml
git commit -m "chore: add workflow config"
Related Skills
devops/workflow-config - Central configuration system
devops/github-actions - CI/CD workflows
testing/comprehensive-testing - Test strategies
methodology/test-driven-development - TDD practices