kayforkind/skill-slice/git-hooks-automation
Claude Code and agent skill by kayforkind/skill-slice
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Sets up versioned Git hooks with Husky + lint-staged, the Python pre-commit framework, or core.hooksPath: pre-commit lint/format, commitlint, pre-push tests. Use when the user mentions pre-commit, commit-msg, Husky, lint-staged, commitlint, or githooks. Not for day-to-day git commit/branch/rebase/PR (git-workflow) or CI pipeline YAML unrelated to local hooks.
Install
npx vskill@latest install kayforkind/skill-slice/git-hooks-automationSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as kayforkind/skill-slice/git-hooks-automation.
Git Hooks Automation
Automate code quality enforcement at the Git level. Set up hooks that lint, format, test, and validate before commits and pushes ever reach your CI pipeline — catching issues in seconds instead of minutes.
When to Use
- User asks to "set up git hooks" or "add pre-commit hooks"
- Configuring Husky, lint-staged, or the pre-commit framework
- Enforcing commit message conventions (Conventional Commits, commitlint)
- Automating linting, formatting, or type-checking before commits
- Setting up pre-push hooks for test runners
- Migrating from Husky v4 to v9+ or adopting hooks from scratch
- User mentions "pre-commit", "commit-msg", "pre-push", "lint-staged", or "githooks"
Prerequisites
- Git installed and available on PATH (
git --versionto verify) - For Husky + lint-staged: Node.js 18+ and npm (
node --version,npm --version) - For pre-commit framework: Python 3.8+ (
python --version) - An existing Git repository (
git initalready run) or willingness to initialize one - Windows host (primary): PowerShell is the default shell. Use
npxcommands directly in PowerShell. For shell-based hook scripts, ensure Git Bash is installed (bundled with Git for Windows). Line endings: configure.gitattributeswith* text=autoto avoid CRLF issues in hook scripts.
Procedure
1. Understand Git Hook Types
Git hooks are scripts that run automatically at specific points in the Git workflow. They live in .git/hooks/ and are not version-controlled by default — which is why tools like Husky exist.
| Hook | Fires When | Common Use | |
|---|---|---|---|
pre-commit | Before commit is created | Lint, format, type-check staged files | |
prepare-commit-msg | After default msg, before editor | Auto-populate commit templates | |
commit-msg | After user writes commit message | Enforce commit message format | |
post-commit | After commit is created | Notifications, logging | |
pre-push | Before push to remote | Run tests, check branch policies | |
pre-rebase | Before rebase starts | Prevent rebase on protected branches | |
post-merge | After merge completes | Install deps, run migrations | |
post-checkout | After checkout/switch | Install deps, rebuild assets |
2. Choose Your Approach
| Approach | Best For | Language | |
|---|---|---|---|
| Husky + lint-staged | JavaScript/TypeScript projects | Node.js | |
| pre-commit framework | Python or polyglot projects | Any | |
Custom shell hooks + core.hooksPath | No Node/Python, or full control | Any |
3. Husky + lint-staged (Node.js Projects)
The modern standard for JavaScript/TypeScript projects. Husky manages Git hooks; lint-staged runs commands only on staged files for speed.
3a. Install and Initialize (Husky v9+)
Windows (PowerShell): Theechocommand above works in Git Bash. In PowerShell, use:```powershellSet-Content -Path .husky\pre-commit -Value "npx lint-staged" -NoNewline```Or simply open.husky\pre-commitin your editor and type the command.
3b. Configure lint-staged in package.json
3c. Add Commit Message Linting with commitlint
Windows (PowerShell): UseSet-Contentfor the commit-msg hook:```powershellSet-Content -Path .husky\commit-msg -Value "npx --no -- commitlint --edit `$1" -NoNewline```
3d. Add Pre-Push Hook
3e. Verify Directory Structure
4. pre-commit Framework (Python / Polyglot)
Language-agnostic framework that works with any project. Hooks are defined in YAML and run in isolated environments.
4a. Install and Create Config
4b. Install Hooks and Run First Check
4c. Key Commands Reference
5. Custom Hook Scripts (Any Language)
For projects not using Node or Python, write hooks directly in shell and share them via core.hooksPath.
5a. Create a Portable Pre-Commit Hook
Create .githooks/pre-commit:
5b. Share Custom Hooks via core.hooksPath
Windows (PowerShell):chmodis not available in PowerShell. Use Git Bash for thechmod +xstep, or rely oncore.hooksPathwhich does not require the executable bit on Windows.
6. CI Integration
Hooks are a first line of defense, but CI is the source of truth.
6a. Run pre-commit in CI (GitHub Actions)
6b. Run lint-staged Validation in CI
7. Migration: Husky v4 → v9+
8. Gradual Adoption Strategy
For existing projects, adopt hooks incrementally to reduce team friction:
- Week 1: Start with formatting only —
{ "*.{js,ts}": ["prettier --write"] } - Week 2-3: Add linting —
{ "*.{js,ts}": ["eslint --fix", "prettier --write"] } - Week 4: Add commit message linting with commitlint
- Week 5+: Add pre-push test runner
Pitfalls
Hooks Not Running
| Symptom | Cause | Fix | |
|---|---|---|---|
| Hooks silently skipped | Not installed in .git/hooks/ | Run npx husky init or pre-commit install | |
| "Permission denied" | Hook file not executable | chmod +x .husky/pre-commit (Git Bash on Windows) | |
| Hooks run but wrong ones | Stale hooks from old setup | Delete .git/hooks/ contents, reinstall | |
| Works locally, fails in CI | Different Node/Python versions | Pin versions in CI config |
Performance Issues
Bypassing Hooks (When Needed)
Warning: Bypassing hooks should be rare. If your team frequently bypasses, the hooks are too slow or too strict — fix the hooks, not the workflow.
Windows-Specific Pitfalls
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/git-hooks-automation/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kayforkind/skill-slice/git-hooks-automation)