Husky wires Git hooks into your repo via a committed .husky/ directory.
Setup:
pnpm add -D husky lint-staged
pnpm dlx husky init
.husky/pre-commit becomes:
pnpm exec lint-staged
lint-staged runs commands only on files Git has staged — fast, focused. Configure in package.json:
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md}": ["prettier --write"]
}
Workflow:
- You edit 3 files of 5000.
git add . → git commit.
- Husky fires pre-commit → lint-staged runs ESLint + Prettier on the 3 files only.
- Re-stages corrected files. Commit proceeds.
Sub-second feedback. Caught issues never enter history.