Skip to content
setup-pre-commit logo

Setup Pre-Commit Hooks

setup-pre-commit

Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.

mattpocock/skills421Kinstalls276.6KstarsGit & Pull Requests

SKILL.md

Full skill instructions

Setup Pre-Commit Hooks

What This Sets Up

  • Husky pre-commit hook
  • lint-staged running Prettier on all staged files
  • Prettier config (if missing)
  • typecheck and test scripts in the pre-commit hook

Steps

1. Detect package manager

Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun). Use whichever is present. Default to npm if unclear.

2. Install dependencies

Install as devDependencies:

husky lint-staged prettier

3. Initialize Husky

npx husky init

This creates .husky/ dir and adds prepare: "husky" to package.json.

4. Create .husky/​pre-commit

Write this file (no shebang needed for Husky v9+):

npx lint-staged
npm run typecheck
npm run test

Adapt: Replace npm with detected package manager. If repo has no typecheck or test script in package.json, omit those lines and tell the user.

5. Create .lintstagedrc

{
  "*": "prettier --ignore-unknown --write"
}

6. Create .prettierrc (if missing)

Only create if no Prettier config exists. Use these defaults:

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "arrowParens": "always"
}

7. Verify

  • .husky/​pre-commit exists and is executable
  • .lintstagedrc exists
  • prepare script in package.json is "husky"
  • prettier config exists
  • Run npx lint-staged to verify it works

8. Commit

Stage all changed/​created files and commit with message: Add pre-commit hooks (husky + lint-staged + prettier)

This will run through the new pre-commit hooks — a good smoke test that everything works.

Notes

  • Husky v9+ doesn't need shebangs in hook files
  • prettier --ignore-unknown skips files Prettier can't parse (images, etc.)
  • The pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests

More Git & Pull Requests skills

receiving-code-review logo
Git & Pull Requests

receiving-code-review

Evaluate code review feedback with technical rigor before implementing, avoiding performative agreement and blind implementation.

295.4K 208.8K
View
using-git-worktrees logo
Git & Pull Requests

using-git-worktrees

Isolated git worktrees with smart directory selection and safety verification.

295.4K 205.2K
View

Structured workflow for completing development branches with test verification and merge/PR options.

295.4K 202.3K
View
review logo
Git & Pull Requests

review

review

276.6K 94.8K
View
code-review-and-quality logo
Git & Pull Requests

code-review-and-quality

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch.

101.4K 55.6K
View
git-commit logo
Git & Pull Requests

git-commit

Standardized git commits using Conventional Commits specification with intelligent diff analysis and message generation.

39.7K 46.4K
View
git-workflow-and-versioning logo
Git & Pull Requests

git-workflow-and-versioning

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

101.4K 44.2K
View
ponytail-review logo
Git & Pull Requests

ponytail-review

Code review focused exclusively on over-engineering. Finds what to delete: reinvented standard library, unneeded dependencies, speculative abstractions, dead flexibility. One line per finding: location, what to cut, what replaces it. Complements correctness-focused review, this one only hunts complexity.

155.5K 32.1K
View
excalidraw-diagram-generator logo
Git & Pull Requests

excalidraw-diagram-generator

Generate Excalidraw diagrams from natural language descriptions in multiple formats.

39.7K 31.1K
View
ponytail-audit logo
Git & Pull Requests

ponytail-audit

Whole-repo audit for over-engineering. Like ponytail-review, but scans the entire codebase instead of a diff: a ranked list of what to delete, simplify, or replace with stdlib/native equivalents. One-shot report, does not apply fixes.

155.5K 30K
View
code-review-excellence logo
Git & Pull Requests

code-review-excellence

Systematic code review practices for constructive feedback, bug detection, and team knowledge sharing.

40.2K 29.4K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
Imagica logo
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View