Overview
Introduction
Husky wires shell scripts up to git hooks so checks like linting or commit-message validation run automatically before a commit lands, but v9 changed the hook file format enough that older tutorials and copy-pasted examples now produce broken or redundant scripts.
This tool generates current, correct Husky v9 hook scripts for pre-commit and commit-msg, plus the package.json "prepare" line Husky v9 relies on.
What Is Husky Git Hooks Generator?
A Husky v9 git hooks generator producing .husky/pre-commit (your chosen commands, one per line) and .husky/commit-msg (wired to commitlint by default), plus the package.json "prepare": "husky" script that reinstalls hooks on every install.
The output intentionally omits the old `#!/usr/bin/env sh` shebang and husky.sh source line that pre-v9 tutorials still show, matching Husky v9's simplified plain-script format.
How Husky Git Hooks Generator Works
Your pre-commit command rows (e.g. `npx lint-staged`) are joined one per line into the .husky/pre-commit script contents, and enabling commit-msg with commitlint produces the standard `npx --no -- commitlint --edit "$1"` invocation.
The package.json prepare script line is always included as `"prepare": "husky"`, matching Husky v9's own `npx husky init` output, so contributors get hooks installed automatically after `npm install`.
When To Use Husky Git Hooks Generator
Use it when adding Husky to a project for the first time and you want v9-correct hook file contents without copying an outdated pre-v9 tutorial.
It's also useful when migrating an existing project's Husky setup from an older version's shebang-and-husky.sh format to v9's simplified scripts.
Often used alongside Commitlint Config Generator, lint-staged Config Generator and package.json Generator.
Features
Advantages
- Produces hook scripts in Husky v9's current format, avoiding the broken/redundant shebang-and-source-line pattern still floating around in older guides.
- Wires commit-msg to commitlint with the exact argument-passing convention (`"$1"`) git hooks require, a common source of copy-paste mistakes.
- Includes the package.json prepare script alongside the hook files, so nothing needed for a working setup is left out.
Limitations
- Doesn't create the .husky directory or set the executable bit on the generated files; those steps still happen locally (`mkdir .husky`, `chmod +x`).
- Covers pre-commit and commit-msg only, the two hooks most projects actually use; other hooks (pre-push, post-merge) need to be added by hand following the same plain-script pattern.
Examples
Best Practices & Notes
Best Practices
- Keep pre-commit hooks fast (lint-staged running only on staged files, not a full project lint) so commits don't feel painfully slow.
- Pair commit-msg with the Commitlint Config Generator's output so the hook actually has rules to validate against.
- Commit the .husky directory itself to version control (Husky expects this), rather than adding it to .gitignore.
Developer Notes
Husky v9 hook files are executed directly by git as shell scripts, without the compatibility shim (`. "$(dirname -- "$0")/_/husky.sh"`) that versions up to 8 sourced; that shim's responsibilities (like skipping hooks in CI via HUSKY=0) are now handled by Husky's install step and environment checks instead of the hook file itself. The `"prepare": "husky"` script relies on npm's (and pnpm/yarn's) convention of automatically running `prepare` after install, which is also why Husky historically recommended this exact script name and value for zero-config hook installation across a team.
Husky Git Hooks Generator Use Cases
- Adding Husky to a project for the first time with lint-staged on pre-commit and commitlint on commit-msg
- Migrating an existing project's hook scripts from pre-v9 Husky's shebang format to v9's plain scripts
- Standardizing git hook setup across multiple repositories on a team
Common Mistakes
- Copying a pre-v9 Husky tutorial's shebang-and-husky.sh hook file into a project using Husky v9, which is unnecessary and can cause confusing errors since that shim file no longer exists.
- Forgetting to make the generated .husky/pre-commit and .husky/commit-msg files executable, so git silently skips a non-executable hook.
Tips
- Use the Lint-Staged Config Generator next to produce the .lintstagedrc.json this pre-commit hook's `npx lint-staged` command reads.