Set up Husky with Git hooks
✓Works with OpenClaudeYou are a Node.js developer setting up Git hooks automation. The user wants to install and configure Husky to run scripts automatically on Git events like pre-commit and pre-push.
What to check first
- Run
git --versionto confirm Git is installed and initialized in your project directory - Run
npm list huskyto see if Husky is already installed - Verify you're in the root directory of your Node.js project with a
package.jsonfile
Steps
- Install Husky as a dev dependency with
npm install husky --save-dev - Initialize Husky in your project by running
npx husky install— this creates the.huskydirectory - Verify the
.huskydirectory andpreparescript were added topackage.json(check for"prepare": "husky install") - Create a pre-commit hook with
npx husky add .husky/pre-commit "npm run lint"— replacenpm run lintwith your actual command - Create a pre-push hook with
npx husky add .husky/pre-push "npm run test"— replace with your test command - Test the setup by staging changes with
git add .and attemptinggit commit -m "test"to verify the hook executes - Make hook files executable by checking
chmod +x .husky/pre-commitandchmod +x .husky/pre-push(Linux/Mac) - Commit the
.huskydirectory to Git so other developers get hooks when they clone and runnpm install
Code
// package.json (after husky install)
{
"name": "my-app",
"version": "1.0.0",
"scripts": {
"lint": "eslint .",
"test": "jest",
"prepare": "husky install"
},
"devDependencies": {
"husky": "^8.0.0",
"eslint": "^8.0.0",
"jest": "^29.0.0"
}
}
// .husky/pre-commit (created by husky add)
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint
// .husky/pre-push (created by husky add)
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run test
// Shell commands to execute in sequence
npm install husky --save-dev
npx husky install
npx husky add .husky/pre-commit "npm run lint"
npx husky add .husky/pre-push "npm run test"
git add .
git commit -m "chore: setup husky hooks"
Pitfalls
- Forgetting to add
"prepare": "husky install"topackage.json— this script ensures hooks are installed for other developers
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Scaffolding Skills
Other Claude Code skills in the same category — free to download.
Next.js Starter
Scaffold Next.js project with common setup
Express Starter
Scaffold Express.js project with structure
React Starter
Scaffold React project with Vite
TypeScript Config
Set up TypeScript configuration
ESLint Config
Configure ESLint with custom rules
Prettier Config
Set up Prettier configuration
Monorepo Setup
Set up monorepo with Turborepo/Nx
Jest Config
Configure Jest testing framework
Want a Scaffolding skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.