setup-pre-commit
- Use it when
- you want every commit in a JavaScript or TypeScript repo formatted, type-checked and tested first
- It does
- installs Husky, lint-staged and Prettier, and writes a pre-commit hook that formats staged files, then runs your type check and tests
- You get
- a .husky/pre-commit hook, a lint-staged config, a Prettier config if you had none, and a commit adding them
- Works with
- npm, pnpm, Yarn or Bun, whichever lockfile it finds
TLDR
Husky runs scripts on git events, and lint-staged runs a command on just the files you staged. The agent picks your package manager from the lockfile, installs the three tools as dev dependencies and initializes Husky. The hook it writes formats staged files with Prettier, skipping files Prettier can't read such as images, then runs your typecheck and test scripts over the whole project. If package.json has no typecheck or test script, it leaves that line out and tells you. An existing Prettier config is kept; otherwise it adds one with common defaults. It ends by committing the new files, which runs the new hook once and shows it works.
Summarizes the skill at 5beb35b.
npx skills add https://github.com/mattpocock/skills --skill setup-pre-commitskills.sh page · Source on GitHub · All skills from mattpocock/skills
- Installs
- 373,523 on skills.sh, Sep 21, 2026
- Repo stars
- 266,454 mattpocock/skills
- First seen
- Feb 13, 2026 on skills.sh
Weekly values
| Week to | Installs |
|---|---|
| Aug 3 | 20,084 |
| Aug 10 | 22,024 |
| Aug 17 | 19,043 |
| Aug 24 | 28,983 |
| Aug 31 | 32,011 |
| Sep 7 | 31,492 |
| Sep 14 | 28,713 |
| Sep 21 | 26,821 |
| Category |
Test-first work, implementation from specs, git hygiene and scope control. Everything for building software: planning, coding, debugging, design, frameworks, cloud, agents and skills. |
|---|---|
| Type |
One-time configuration or scaffolding of a project, account or tool. |
| Effect |
Its own steps create or change files, git state or local tools. |
| Needs |
Instructions only. Works in any agent that supports skills. |
| Publisher |
Everyone else. Unverified vendor claims default to community. |
| Topics | |
| Stack |
SKILL.md
From mattpocock/skills at 5beb35b. Checked daily, last changed Oct 20, 2026.
Frontmatter
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-commitexists and is executable - [ ]
.lintstagedrcexists - [ ]
preparescript in package.json is"husky" - [ ]
prettierconfig exists - [ ] Run
npx lint-stagedto 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-unknownskips files Prettier can't parse (images, etc.)- The pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests