Pre-commit hooks setup
Sets up Husky and lint-staged in a Node repo so each commit runs Prettier on staged files, then the typecheck and test scripts, matched to the lockfile, and makes the first commit through the hook. Use when a repo has no commit-time checks.
setup-pre-commit- Author
- Matt Pocock
- Source
- mattpocock/skills/skills/misc/setup-pre-commit @ abeeaf9
- License
- MIT · Copyright (c) 2026 Matt Pocock
About this skill
What it does
The skill adds commit-time checks to a JavaScript or TypeScript repo. The agent detects the package manager by lockfile (npm, pnpm, yarn or bun; npm when unclear), installs husky, lint-staged and prettier as dev dependencies, runs npx husky init and writes .husky/pre-commit with three commands: npx lint-staged, then the typecheck script, then test. A script the project does not have is left out, and the agent tells you.
It also writes .lintstagedrc (prettier --ignore-unknown --write on staged files) and, only if the repo has no Prettier config, a .prettierrc with the author's defaults. Then it checks the result, runs npx lint-staged, stages what it changed and commits with Add pre-commit hooks (husky + lint-staged + prettier). That commit goes through the new hook as a smoke test.
The skill is SKILL.md alone; agents/openai.yaml holds the name and short description for Codex.
When to use it, and when not
Use it on a Node project with no commit-time checks yet, to verify formatting, types and tests before anything is committed.
Skip it outside the Node ecosystem. Weigh the cost: only Prettier is limited to staged files; the type check and full test suite run on every commit, slow on a large project. The commands target Husky v9 and later. The skill commits by itself at the end; if you want to read the diff first, say so.
How to run it
The install command below puts the whole folder in place. The agent picks the skill up by its description; to call it yourself:
- Claude Code:
/setup-pre-commit, or ask for the skill by name. - Codex:
$setup-pre-commit. - Cursor: type
/in the Agent chat and picksetup-pre-commit.
Example: /setup-pre-commit We use pnpm. Set it up, but show me the diff before you commit.
How it differs from similar skills
Git workflow and versioning lists the same pre-commit checks and shows a lint-staged config, but leaves the setup to you; this skill does it, fitted to your lockfile and scripts. CI/CD pipeline setup and GitHub Actions CI put the same gates on every pull request; a pre-commit hook catches problems earlier, on your machine. Git guardrails for Claude Code also installs a hook, but in Claude Code, to stop the agent's dangerous git commands. Coding session retrospective flags a repo with no pre-commit hook and no CI job; this skill is one fix.
Install
Run one command — it saves SKILL.md and the files it uses into your agent's skills folder. Claude Code and Codex pick up a new skill without a restart; if it does not show up, restart the agent.
curl -fsSL --create-dirs -o ~/.claude/skills/setup-pre-commit/SKILL.md https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/SKILL.md -o ~/.claude/skills/setup-pre-commit/LICENSE https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/LICENSE -o ~/.claude/skills/setup-pre-commit/agents/openai.yaml https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/agents/openai.yaml
curl -fsSL --create-dirs -o ~/.agents/skills/setup-pre-commit/SKILL.md https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/SKILL.md -o ~/.agents/skills/setup-pre-commit/LICENSE https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/LICENSE -o ~/.agents/skills/setup-pre-commit/agents/openai.yaml https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/agents/openai.yaml
foreach ($f in 'SKILL.md','LICENSE','agents/openai.yaml') { $p = Join-Path "$HOME\.claude\skills\setup-pre-commit" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/$f" -UseBasicParsing -OutFile $p }foreach ($f in 'SKILL.md','LICENSE','agents/openai.yaml') { $p = Join-Path "$HOME\.agents\skills\setup-pre-commit" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/$f" -UseBasicParsing -OutFile $p }Any other agent: save the file into its skills folder, or give it the link to the file: https://anymodel.org/en/skills/matt-pocock/setup-pre-commit/SKILL.md
SKILL.md
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
Connect through AnyModel API
This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.
AnyModel