$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Scaffoldingbeginner

Husky Setup

Share

Set up Husky with Git hooks

Works with OpenClaude

You 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 --version to confirm Git is installed and initialized in your project directory
  • Run npm list husky to see if Husky is already installed
  • Verify you're in the root directory of your Node.js project with a package.json file

Steps

  1. Install Husky as a dev dependency with npm install husky --save-dev
  2. Initialize Husky in your project by running npx husky install — this creates the .husky directory
  3. Verify the .husky directory and prepare script were added to package.json (check for "prepare": "husky install")
  4. Create a pre-commit hook with npx husky add .husky/pre-commit "npm run lint" — replace npm run lint with your actual command
  5. Create a pre-push hook with npx husky add .husky/pre-push "npm run test" — replace with your test command
  6. Test the setup by staging changes with git add . and attempting git commit -m "test" to verify the hook executes
  7. Make hook files executable by checking chmod +x .husky/pre-commit and chmod +x .husky/pre-push (Linux/Mac)
  8. Commit the .husky directory to Git so other developers get hooks when they clone and run npm 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" to package.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

Quick Info

CategoryScaffolding
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
scaffoldinghuskyhooks

Install command:

curl -o ~/.claude/skills/husky-setup.md https://claude-skills-hub.vercel.app/skills/scaffolding/husky-setup.md

Related Scaffolding Skills

Other Claude Code skills in the same category — free to download.

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.