Universal Hooks - Zero-Config Quality Gates for Every Project
Install once, forget forever. Your code quality is now on autopilot.
What Is This?
A smart hook system that auto-detects your project stack and installs exactly the quality gates you need. No configuration files to edit. No boilerplate to copy. It just works.
Supported Quality Gates
Code Quality
| Gate |
What It Checks |
Languages |
| Formatter |
Code formatting consistency |
All (Prettier, Biome, Black, gofmt) |
| Linter |
Code quality rules & anti-patterns |
JS/TS (ESLint), Python (Ruff), Rust (Clippy), Go (golint) |
| Type Check |
Type correctness |
TypeScript, Python (pyright/mypy) |
| Import Sort |
Import ordering & cleanup |
JS/TS, Python |
Security
| Gate |
What It Checks |
| Secrets Detection |
API keys, tokens, passwords in code |
| Dependency Audit |
Known vulnerable dependencies |
| License Check |
License compliance of dependencies |
| Permissions Check |
File permission anomalies |
Git Hygiene
| Gate |
What It Checks |
| Commit Message |
Conventional Commits format |
| Branch Name |
Team branch naming convention |
| File Size |
Prevent large file commits |
| Binary Files |
Prevent unexpected binary commits |
| Merge Markers |
Detect leftover conflict markers |
| Debug Code |
Detect console.log, debugger, TODO/FIXME |
| AI Markers |
Track AI-generated code with markers |
Auto-Detection
When you run "setup git hooks", the skill:
- Scans project root for config files (
package.json, pyproject.toml, Cargo.toml, go.mod, etc.)
- Detects languages from file extensions and configs
- Detects tools from devDependencies and config files
- Generates hook scripts tailored to your stack
- Installs hooks via
.husky/ or .git/hooks/
Detection Examples
Detected: package.json → JavaScript/TypeScript project
├─ eslint config found → Enable ESLint hook
├─ prettier config found → Enable Prettier hook
├─ typescript found → Enable TypeScript check hook
└─ No conventional commits → Enable commit message hook
Detected: pyproject.toml → Python project
├─ ruff config found → Enable Ruff hook
├─ mypy config found → Enable type check hook
└─ No black config → Suggest Biome for formatting
Detected: Cargo.toml → Rust project
├─ Enable cargo clippy hook
├─ Enable cargo fmt hook
└─ Enable cargo test hook
Hook Scripts
Pre-Commit Hook
#!/bin/bash
# Auto-generated by Universal Hooks Skill
# Project: my-awesome-project
# Generated: 2026-03-20
set -e
echo "🔍 Running quality gates..."
# === Formatters ===
if command -v prettier &> /dev/null; then
echo " ▶ Checking formatting (Prettier)..."
npx prettier --check "src/**/*.{ts,tsx,js,jsx,json,css,md}" || {
echo " ❌ Formatting issues found. Running auto-fix..."
npx prettier --write "src/**/*.{ts,tsx,js,jsx,json,css,md}"
echo " ✅ Formatting fixed. Please review and re-commit."
exit 1
}
fi
# === Linters ===
if [ -f ".eslintrc*" ] || [ -f "eslint.config.*" ]; then
echo " ▶ Running ESLint..."
npx eslint src/ --max-warnings 0 || {
echo " ❌ ESLint errors found. Fix them before committing."
exit 1
}
fi
# === Type Checking ===
if [ -f "tsconfig.json" ]; then
echo " ▶ Running TypeScript check..."
npx tsc --noEmit || {
echo " ❌ TypeScript errors found."
exit 1
}
fi
# === Security ===
echo " ▶ Scanning for secrets..."
if command -v trufflehog &> /dev/null; then
trufflehog --no-update . 2>/dev/null || {
echo " ❌ Potential secrets detected! Remove them before committing."
exit 1
}
fi
# === AI Code Markers ===
echo " ▶ Checking AI code markers..."
if grep -r "AI-GENERATED" --include="*.ts" --include="*.tsx" --include="*.py" .; then
echo " ⚠️ AI-generated code detected. Ensure it's been reviewed."
fi
# === Debug Code ===
echo " ▶ Checking for debug code..."
if grep -rn "console\.log\|console\.debug\|debugger\|binding\.pry" --include="*.ts" --include="*.tsx" --include="*.js" src/ 2>/dev/null; then
echo " ⚠️ Debug code detected. Remove before committing."
# Warning only, don't block
fi
# === Conflict Markers ===
if grep -rn "<<<<<<\|>>>>>>\|=======" --include="*.ts" --include="*.tsx" --include="*.py" --include="*.js" src/ 2>/dev/null; then
echo " ❌ Merge conflict markers found! Resolve before committing."
exit 1
fi
# === Large Files ===
MAX_FILE_SIZE=500 # KB
LARGE_FILES=$(find . -type f -size +${MAX_FILE_SIZE}k -not -path "./node_modules/*" -not -path "./.git/*" -not -path "./dist/*" -newer .git/HEAD 2>/dev/null)
if [ -n "$LARGE_FILES" ]; then
echo " ⚠️ Large files detected:"
echo "$LARGE_FILES" | while read file; do
echo " - $file ($(du -k "$file" | cut -f1)KB)"
done
echo " Consider using Git LFS for files > ${MAX_FILE_SIZE}KB."
fi
echo "✅ All quality gates passed!"
Commit Message Hook
#!/bin/bash
# Enforces Conventional Commits format
COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
# Conventional Commits pattern:
# type(scope): description
# Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
PATTERN='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?!?:\s.+'
if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
echo "❌ Invalid commit message format!"
echo ""
echo "Expected: type(scope): description"
echo ""
echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
echo ""
echo "Examples:"
echo " feat(auth): add JWT token refresh"
echo " fix(api): handle null response from user endpoint"
echo " docs: update README installation guide"
echo " refactor(utils): extract date formatter to separate module"
echo ""
echo "Your message: $COMMIT_MSG"
exit 1
fi
# Check body line length (72 chars max)
BODY=$(echo "$COMMIT_MSG" | sed '1d' | sed '/^$/d' | head -1)
if [ -n "$BODY" ] && [ ${#BODY} -gt 72 ]; then
echo "⚠️ Commit body line too long (${#BODY} > 72 chars). Consider wrapping."
fi
echo "✅ Commit message format valid."
Pre-Push Hook
#!/bin/bash
# Runs before pushing to remote
set -e
echo "🚀 Pre-push checks..."
# === Run Tests ===
if [ -f "package.json" ]; then
if jq -e '.scripts.test' package.json > /dev/null 2>&1; then
echo " ▶ Running tests..."
npm test -- --passWithNoTests || {
echo " ❌ Tests failed. Fix before pushing."
exit 1
}
fi
fi
# === Check Branch Name ===
BRANCH=$(git branch --show-current)
PROTECTED_BRANCHES=("main" "master" "develop" "staging")
if [[ " ${PROTECTED_BRANCHES[*]} " =~ " ${BRANCH} " ]]; then
echo " ❌ Direct push to '$BRANCH' is not allowed. Use a feature branch and PR."
exit 1
fi
# === Dependency Audit ===
if [ -f "package.json" ]; then
echo " ▶ Running dependency audit..."
npm audit --audit-level=high || {
echo " ❌ High severity vulnerabilities found. Run 'npm audit fix' first."
exit 1
}
fi
echo "✅ Pre-push checks passed! Pushing to origin/$BRANCH..."
AI Code Markers
When the AI agent generates code, it should add markers for traceability:
// AI-GENERATED: This function was generated by an AI coding assistant
// Reviewed-by: <developer-name> on 2026-03-20
// Confidence: high
export function calculateTotal(items: CartItem[]): number {
return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
}
The pre-commit hook checks for unreviewed AI-generated code:
# Check for AI markers that haven't been reviewed
if grep -r "AI-GENERATED" src/ | grep -v "Reviewed-by"; then
echo "⚠️ Unreviewed AI-generated code found. Please review and add 'Reviewed-by' marker."
fi
GitHub Actions Templates
CI Quality Gate
name: Quality Gates
on: [push, pull_request]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Type Check
run: npx tsc --noEmit
- name: Lint
run: npx eslint src/ --max-warnings 0
- name: Format Check
run: npx prettier --check .
- name: Test
run: npm test -- --coverage
- name: Security Audit
run: npm audit --audit-level=high
- name: Check AI Code Reviews
run: |
UNREVIEWED=$(grep -r "AI-GENERATED" src/ | grep -v "Reviewed-by" | wc -l)
if [ "$UNREVIEWED" -gt 0 ]; then
echo "::warning::$UNREVIEWED AI-generated files need review"
fi
Quick Start Commands
| Command |
Description |
"setup git hooks" |
Auto-detect stack and install all hooks |
"setup pre-commit only" |
Install only pre-commit hook |
"setup commit convention" |
Install only commit message hook |
"setup CI pipeline" |
Generate GitHub Actions config |
"check hooks status" |
Show currently active hooks |
"update hooks" |
Re-run detection and update hooks |
Stack Support Matrix
| Stack |
Formatter |
Linter |
Type Check |
Test |
Security |
| React/Next.js |
Prettier |
ESLint |
tsc |
Jest/Vitest |
npm audit |
| Vue/Nuxt |
Prettier |
ESLint |
tsc |
Vitest |
npm audit |
| Python/Django |
Black/Biome |
Ruff |
mypy/pyright |
pytest |
pip audit |
| Go |
gofmt |
golint |
- |
go test |
govulncheck |
| Rust |
rustfmt |
Clippy |
- |
cargo test |
cargo audit |
| Java/Spring |
google-java-format |
Checkstyle |
javac |
JUnit |
OWASP Dep-Check |
Integration Notes
This skill works with any AI coding agent that supports the SKILL.md standard:
- Claude Code, Codex CLI, Cursor, Windsurf, GitHub Copilot
- CodeBuddy, OpenClaw, and any compatible agent
- Hooks are plain bash scripts for maximum portability
- GitHub Actions templates are ready-to-use YAML files
1---2name: universal-hooks3description: Pre-commit and pre-push hook templates for AI agent projects that enforce quality gates automatically. Includes hooks for: code formatting (Prettier/Biome), linting (ESLint/Ruff/Clippy), type checking (TypeScript/pyright), security scanning (secrets detection, dependency audit), commit message convention (Conventional Commits), branch naming policy, and AI-generated code markers. One install, zero configuration - auto-detects your project stack and activates relevant hooks. Works with Git hooks, GitHub Actions, and any CI/CD pipeline. Use when setting up a new project, improving code quality enforcement, preventing bad commits, or automating pre-merge checks. Trigger keywords: git hooks, pre-commit, quality gate, CI/CD, 代码质量, 自动检查, commit convention, code standards, lint, format.4---56# Universal Hooks - Zero-Config Quality Gates for Every Project78> Install once, forget forever. Your code quality is now on autopilot.910## What Is This?1112A smart hook system that **auto-detects your project stack** and installs exactly the quality gates you need. No configuration files to edit. No boilerplate to copy. It just works.1314## Supported Quality Gates1516### Code Quality17| Gate | What It Checks | Languages |18|------|---------------|-----------|19| **Formatter** | Code formatting consistency | All (Prettier, Biome, Black, gofmt) |20| **Linter** | Code quality rules & anti-patterns | JS/TS (ESLint), Python (Ruff), Rust (Clippy), Go (golint) |21| **Type Check** | Type correctness | TypeScript, Python (pyright/mypy) |22| **Import Sort** | Import ordering & cleanup | JS/TS, Python |2324### Security25| Gate | What It Checks |26|------|---------------|27| **Secrets Detection** | API keys, tokens, passwords in code |28| **Dependency Audit** | Known vulnerable dependencies |29| **License Check** | License compliance of dependencies |30| **Permissions Check** | File permission anomalies |3132### Git Hygiene33| Gate | What It Checks |34|------|---------------|35| **Commit Message** | Conventional Commits format |36| **Branch Name** | Team branch naming convention |37| **File Size** | Prevent large file commits |38| **Binary Files** | Prevent unexpected binary commits |39| **Merge Markers** | Detect leftover conflict markers |40| **Debug Code** | Detect console.log, debugger, TODO/FIXME |41| **AI Markers** | Track AI-generated code with markers |4243## Auto-Detection4445When you run `"setup git hooks"`, the skill:46471. **Scans project root** for config files (`package.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, etc.)482. **Detects languages** from file extensions and configs493. **Detects tools** from devDependencies and config files504. **Generates hook scripts** tailored to your stack515. **Installs hooks** via `.husky/` or `.git/hooks/`5253### Detection Examples5455```56Detected: package.json → JavaScript/TypeScript project57 ├─ eslint config found → Enable ESLint hook58 ├─ prettier config found → Enable Prettier hook59 ├─ typescript found → Enable TypeScript check hook60 └─ No conventional commits → Enable commit message hook6162Detected: pyproject.toml → Python project63 ├─ ruff config found → Enable Ruff hook64 ├─ mypy config found → Enable type check hook65 └─ No black config → Suggest Biome for formatting6667Detected: Cargo.toml → Rust project68 ├─ Enable cargo clippy hook69 ├─ Enable cargo fmt hook70 └─ Enable cargo test hook71```7273## Hook Scripts7475### Pre-Commit Hook7677```bash78#!/bin/bash79# Auto-generated by Universal Hooks Skill80# Project: my-awesome-project81# Generated: 2026-03-208283set -e8485echo "🔍 Running quality gates..."8687# === Formatters ===88if command -v prettier &> /dev/null; then89 echo " ▶ Checking formatting (Prettier)..."90 npx prettier --check "src/**/*.{ts,tsx,js,jsx,json,css,md}" || {91 echo " ❌ Formatting issues found. Running auto-fix..."92 npx prettier --write "src/**/*.{ts,tsx,js,jsx,json,css,md}"93 echo " ✅ Formatting fixed. Please review and re-commit."94 exit 195 }96fi9798# === Linters ===99if [ -f ".eslintrc*" ] || [ -f "eslint.config.*" ]; then100 echo " ▶ Running ESLint..."101 npx eslint src/ --max-warnings 0 || {102 echo " ❌ ESLint errors found. Fix them before committing."103 exit 1104 }105fi106107# === Type Checking ===108if [ -f "tsconfig.json" ]; then109 echo " ▶ Running TypeScript check..."110 npx tsc --noEmit || {111 echo " ❌ TypeScript errors found."112 exit 1113 }114fi115116# === Security ===117echo " ▶ Scanning for secrets..."118if command -v trufflehog &> /dev/null; then119 trufflehog --no-update . 2>/dev/null || {120 echo " ❌ Potential secrets detected! Remove them before committing."121 exit 1122 }123fi124125# === AI Code Markers ===126echo " ▶ Checking AI code markers..."127if grep -r "AI-GENERATED" --include="*.ts" --include="*.tsx" --include="*.py" .; then128 echo " ⚠️ AI-generated code detected. Ensure it's been reviewed."129fi130131# === Debug Code ===132echo " ▶ Checking for debug code..."133if grep -rn "console\.log\|console\.debug\|debugger\|binding\.pry" --include="*.ts" --include="*.tsx" --include="*.js" src/ 2>/dev/null; then134 echo " ⚠️ Debug code detected. Remove before committing."135 # Warning only, don't block136fi137138# === Conflict Markers ===139if grep -rn "<<<<<<\|>>>>>>\|=======" --include="*.ts" --include="*.tsx" --include="*.py" --include="*.js" src/ 2>/dev/null; then140 echo " ❌ Merge conflict markers found! Resolve before committing."141 exit 1142fi143144# === Large Files ===145MAX_FILE_SIZE=500 # KB146LARGE_FILES=$(find . -type f -size +${MAX_FILE_SIZE}k -not -path "./node_modules/*" -not -path "./.git/*" -not -path "./dist/*" -newer .git/HEAD 2>/dev/null)147if [ -n "$LARGE_FILES" ]; then148 echo " ⚠️ Large files detected:"149 echo "$LARGE_FILES" | while read file; do150 echo " - $file ($(du -k "$file" | cut -f1)KB)"151 done152 echo " Consider using Git LFS for files > ${MAX_FILE_SIZE}KB."153fi154155echo "✅ All quality gates passed!"156```157158### Commit Message Hook159160```bash161#!/bin/bash162# Enforces Conventional Commits format163164COMMIT_MSG_FILE=$1165COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")166167# Conventional Commits pattern:168# type(scope): description169# Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert170PATTERN='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?!?:\s.+'171172if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then173 echo "❌ Invalid commit message format!"174 echo ""175 echo "Expected: type(scope): description"176 echo ""177 echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"178 echo ""179 echo "Examples:"180 echo " feat(auth): add JWT token refresh"181 echo " fix(api): handle null response from user endpoint"182 echo " docs: update README installation guide"183 echo " refactor(utils): extract date formatter to separate module"184 echo ""185 echo "Your message: $COMMIT_MSG"186 exit 1187fi188189# Check body line length (72 chars max)190BODY=$(echo "$COMMIT_MSG" | sed '1d' | sed '/^$/d' | head -1)191if [ -n "$BODY" ] && [ ${#BODY} -gt 72 ]; then192 echo "⚠️ Commit body line too long (${#BODY} > 72 chars). Consider wrapping."193fi194195echo "✅ Commit message format valid."196```197198### Pre-Push Hook199200```bash201#!/bin/bash202# Runs before pushing to remote203204set -e205206echo "🚀 Pre-push checks..."207208# === Run Tests ===209if [ -f "package.json" ]; then210 if jq -e '.scripts.test' package.json > /dev/null 2>&1; then211 echo " ▶ Running tests..."212 npm test -- --passWithNoTests || {213 echo " ❌ Tests failed. Fix before pushing."214 exit 1215 }216 fi217fi218219# === Check Branch Name ===220BRANCH=$(git branch --show-current)221PROTECTED_BRANCHES=("main" "master" "develop" "staging")222if [[ " ${PROTECTED_BRANCHES[*]} " =~ " ${BRANCH} " ]]; then223 echo " ❌ Direct push to '$BRANCH' is not allowed. Use a feature branch and PR."224 exit 1225fi226227# === Dependency Audit ===228if [ -f "package.json" ]; then229 echo " ▶ Running dependency audit..."230 npm audit --audit-level=high || {231 echo " ❌ High severity vulnerabilities found. Run 'npm audit fix' first."232 exit 1233 }234fi235236echo "✅ Pre-push checks passed! Pushing to origin/$BRANCH..."237```238239## AI Code Markers240241When the AI agent generates code, it should add markers for traceability:242243```typescript244// AI-GENERATED: This function was generated by an AI coding assistant245// Reviewed-by: <developer-name> on 2026-03-20246// Confidence: high247export function calculateTotal(items: CartItem[]): number {248 return items.reduce((sum, item) => sum + item.price * item.quantity, 0);249}250```251252The pre-commit hook checks for unreviewed AI-generated code:253254```bash255# Check for AI markers that haven't been reviewed256if grep -r "AI-GENERATED" src/ | grep -v "Reviewed-by"; then257 echo "⚠️ Unreviewed AI-generated code found. Please review and add 'Reviewed-by' marker."258fi259```260261## GitHub Actions Templates262263### CI Quality Gate264265```yaml266name: Quality Gates267on: [push, pull_request]268269jobs:270 quality:271 runs-on: ubuntu-latest272 steps:273 - uses: actions/checkout@v4274 275 - name: Setup Node.js276 uses: actions/setup-node@v4277 with:278 node-version: '20'279 cache: 'npm'280 281 - name: Install dependencies282 run: npm ci283 284 - name: Type Check285 run: npx tsc --noEmit286 287 - name: Lint288 run: npx eslint src/ --max-warnings 0289 290 - name: Format Check291 run: npx prettier --check .292 293 - name: Test294 run: npm test -- --coverage295 296 - name: Security Audit297 run: npm audit --audit-level=high298 299 - name: Check AI Code Reviews300 run: |301 UNREVIEWED=$(grep -r "AI-GENERATED" src/ | grep -v "Reviewed-by" | wc -l)302 if [ "$UNREVIEWED" -gt 0 ]; then303 echo "::warning::$UNREVIEWED AI-generated files need review"304 fi305```306307## Quick Start Commands308309| Command | Description |310|---------|-------------|311| `"setup git hooks"` | Auto-detect stack and install all hooks |312| `"setup pre-commit only"` | Install only pre-commit hook |313| `"setup commit convention"` | Install only commit message hook |314| `"setup CI pipeline"` | Generate GitHub Actions config |315| `"check hooks status"` | Show currently active hooks |316| `"update hooks"` | Re-run detection and update hooks |317318## Stack Support Matrix319320| Stack | Formatter | Linter | Type Check | Test | Security |321|-------|-----------|--------|------------|------|----------|322| React/Next.js | Prettier | ESLint | tsc | Jest/Vitest | npm audit |323| Vue/Nuxt | Prettier | ESLint | tsc | Vitest | npm audit |324| Python/Django | Black/Biome | Ruff | mypy/pyright | pytest | pip audit |325| Go | gofmt | golint | - | go test | govulncheck |326| Rust | rustfmt | Clippy | - | cargo test | cargo audit |327| Java/Spring | google-java-format | Checkstyle | javac | JUnit | OWASP Dep-Check |328329## Integration Notes330331This skill works with any AI coding agent that supports the SKILL.md standard:332- Claude Code, Codex CLI, Cursor, Windsurf, GitHub Copilot333- CodeBuddy, OpenClaw, and any compatible agent334- Hooks are plain bash scripts for maximum portability335- GitHub Actions templates are ready-to-use YAML files