← marketplace
engineerstoolsha:5365188813009f22manual
mp-setup-pre-commit
Use when adding Husky pre-commit hooks to a repo — installs husky + lint-staged + Prettier, wires `npx lint-staged`, `npm run typecheck`, and `npm run test` into .husky/pre-commit.
source: https://github.com/mattpocock/skills/blob/main/skills/misc/setup-pre-commit/SKILL.md ↗mattpocock/skills· ★ 76k
One-line install
curl --create-dirs -fsSL https://skillmake.xyz/i/mp-setup-pre-commit -o ~/.claude/skills/mp-setup-pre-commit/SKILL.md
The hash above pins this exact content. The file we serve at /api/marketplace/mp-setup-pre-commit-53651888/raw always matches sha:5365188813009f22.
4,339 chars · ~1,085 tokens
--- name: mp-setup-pre-commit description: Use when adding Husky pre-commit hooks to a repo — installs husky + lint-staged + Prettier, wires `npx lint-staged`, `npm run typecheck`, and `npm run test` into .husky/pre-commit. source: https://github.com/mattpocock/skills/blob/main/skills/misc/setup-pre-commit/SKILL.md generated: 2026-05-12T18:05:18.401Z category: tool audience: engineers --- ## When to use - Greenfielding pre-commit hygiene on a repo that doesn't have any pre-commit hooks yet - Adding Prettier auto-formatting via lint-staged so staged files are cleaned before commit - Gating commits on typecheck and tests so broken main is harder to ship - Adapting the hook for non-npm package managers (pnpm / yarn / bun) ## Key concepts ### husky + lint-staged + prettier trio Husky owns the .husky/ git hook scripts. lint-staged runs commands against only staged files (fast). Prettier is the formatter lint-staged invokes. Three devDependencies, one cohesive flow. ### detect package manager first Check for package-lock.json (npm) / pnpm-lock.yaml (pnpm) / yarn.lock (yarn) / bun.lockb (bun). Use whichever lockfile is present. Default to npm if unclear. The pre-commit script body adapts accordingly. ### no shebang on Husky v9+ Husky v9 dropped the shebang requirement in hook files. Just write the commands. Older Husky scripts that start with `#!/bin/sh` still work but aren't needed. ### omit missing scripts If package.json has no `typecheck` or `test` script, the pre-commit shouldn't reference them — the hook would fail every commit. Omit those lines and tell the user. ### Prettier config only if missing Don't overwrite an existing Prettier config. Only create .prettierrc when no Prettier config exists in the repo (any of .prettierrc, .prettierrc.json, prettier.config.js, prettier key in package.json). ### commit through the new hook as the smoke test Once everything is wired, the natural smoke test is to stage + commit the new pre-commit setup itself. If the commit succeeds, the hook is wired correctly. If it fails, you know which step to fix. ## API reference ``` Install (npm example) ``` Install all three as devDependencies, then init Husky. ``` npm install -D husky lint-staged prettier npx husky init ``` ``` .husky/pre-commit ``` Three commands: format staged files, typecheck, run tests. Adapt `npm` to the detected package manager. ``` npx lint-staged npm run typecheck npm run test ``` ``` .lintstagedrc ``` Run Prettier against every staged file; skip unknown file types (images, binaries). ``` { "*": "prettier --ignore-unknown --write" } ``` ``` .prettierrc (default if none exists) ``` Matt's defaults — 2-space indent, double quotes, semicolons, ES5 trailing commas. ``` { "useTabs": false, "tabWidth": 2, "printWidth": 80, "singleQuote": false, "trailingComma": "es5", "semi": true, "arrowParens": "always" } ``` ``` Verification checklist ``` Confirm the four artefacts exist before the smoke-test commit. ``` [ ] .husky/pre-commit exists and is executable [ ] .lintstagedrc exists [ ] package.json `prepare` script is "husky" [ ] Prettier config exists [ ] `npx lint-staged` runs clean ``` ## Gotchas - Detect the package manager BEFORE editing the pre-commit body — using `npm run` in a pnpm-only repo will fail at commit time. - Omit `typecheck` / `test` lines if those scripts don't exist in package.json — otherwise every commit fails. - Don't overwrite an existing Prettier config. Detect and skip the .prettierrc step if one exists in any supported form. - Husky v9+ does NOT need a shebang in hook files. Older guides that start with `#!/bin/sh` are stale. - `prettier --ignore-unknown` is critical — without it, binary files break lint-staged. - lint-staged runs ONLY on staged files (fast). typecheck and test run against the whole project — those can be slow, plan accordingly. - The final commit is the smoke test. If it fails, the hook is wrong — fix it before staging more changes on top. - If the team already has a different pre-commit setup (e.g. simple-git-hooks, lefthook), this skill will conflict — confirm before installing. --- Generated by SkillMake from https://github.com/mattpocock/skills/blob/main/skills/misc/setup-pre-commit/SKILL.md on 2026-05-12T18:05:18.401Z. Verify against source before relying on details.
File: ~/.claude/skills/mp-setup-pre-commit/SKILL.md