Skip to content
Setup Pre-Commit (Matt Pocock)

Setup Pre-Commit (Matt Pocock) Skill

Matt Pocock's skill that wires Husky, lint-staged and Prettier into a JavaScript or TypeScript repo, so every commit is formatted, type-checked and tested before it lands.

GitHub Docs

Install

Install with the skills CLI

One command for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf and dozens of other agents. Needs Node.js; the skill is fetched straight from mattpocock/skills.

$ npx skills add mattpocock/skills --skill setup-pre-commit

Run it in a terminal. The CLI finds the agents installed on your machine, asks which ones to add the skill to, and whether to install it into the folder you ran it from or for all your projects.

Other ways to install

Copy the whole skill folder — SKILL.md and any scripts or references beside it — into ~/.claude/skills/setup-pre-commit/, where Claude Code picks it up in every project. Only git is needed.

tmp=$(mktemp -d) && \
  git clone --depth 1 --branch main https://github.com/mattpocock/skills.git "$tmp" && \
  mkdir -p ~/.claude/skills && \
  cp -R "$tmp"/skills/misc/setup-pre-commit ~/.claude/skills/setup-pre-commit

No scripts or references next to it? Saving the SKILL.md alone as ~/.claude/skills/setup-pre-commit/SKILL.md works too.

Using another agent? Its personal skills folder
Codex
~/.agents/skills/
Cursor
~/.cursor/skills/
GitHub Copilot
~/.copilot/skills/
Gemini CLI
~/.gemini/skills/
Windsurf
~/.codeium/windsurf/skills/
OpenCode
~/.config/opencode/skills/

About

  • Detects npm, pnpm, Yarn or Bun from the lockfile
  • Installs Husky, lint-staged and Prettier as dev dependencies
  • Pre-commit hook runs lint-staged, then typecheck and test scripts when they exist
  • Formats only staged files with prettier --ignore-unknown
  • Writes a default .prettierrc only when none exists
  • Verification checklist and a smoke-test commit

Setup Pre-Commit is a short, procedural skill from Matt Pocock's public mattpocock/skills collection. Ask an agent to "add pre-commit hooks" or "set up Husky" and it carries out the whole chore in one pass instead of improvising a configuration.

The skill first detects the package manager from the lockfile (npm, pnpm, Yarn or Bun) and uses it throughout. It installs husky, lint-staged and prettier as dev dependencies, runs npx husky init, and writes a .husky/pre-commit hook that runs lint-staged and then the repository's own typecheck and test scripts, leaving out any script the project does not have and telling you so. lint-staged is configured to run prettier --ignore-unknown --write on staged files only, and a default .prettierrc is written only when the project has no Prettier config yet.

It ends with a checklist (hook file present and executable, prepare script set to husky, Prettier config present) and commits the result, so the new hook runs on its own commit as a smoke test. It targets Husky v9 and later, where hook files need no shebang.

Useful for anyone starting a Node.js or TypeScript project with Claude Code, Codex or Cursor who wants commit-time formatting and checks without looking up the current Husky setup. MIT licensed.

SKILL.md

The instructions your agent loads, as published by Matt Pocock.

SKILL.md
name
setup-pre-commit
description
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.

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
Install

Skill: Codebase Design

by Matt Pocock

New

Matt Pocock's skill that gives coding agents a shared vocabulary for designing deep modules: interfaces, seams, adapters, depth, leverage and locality, plus rules for testable design.

Skill: TDD

by Matt Pocock

Matt Pocock's test-driven development skill: one red-to-green slice at a time, tests only at seams agreed with you first, and a named list of test anti-patterns to avoid.

Skill: Diagnosing Bugs

by Matt Pocock

Matt Pocock's discipline for hard bugs and performance regressions: build a tight, red-capable feedback loop first, then reproduce, minimise, hypothesise, instrument, fix with a regression test and clean up.

Browse all skills →