/setup-pre-commit:setup-pre-commitfrom 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.
Ships in setup-pre-commit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Applies to: JavaScript / TypeScript projects with package.json. Not applicable to other languages.
Prerequisites: The project must already have package.json (run npm init -y first if missing) and be inside a git repository (git init if not).
Read the project root for lockfiles in this priority order:
| Lockfile | Package manager | Install cmd prefix | Script runner | dlx runner |
|---|---|---|---|---|
pnpm-lock.yaml | pnpm | pnpm add -D | pnpm run | pnpm dlx |
yarn.lock | yarn | yarn add --dev | yarn | yarn dlx |
bun.lockb | bun | bun add -d | bun run | bunx |
package-lock.json | npm | npm install --save-dev | npm run | npx |
If multiple lockfiles exist, use the first match in the order above. If none found, default to npm and inform the user.
Run with the detected package manager's install command:
<install-cmd-prefix> husky lint-staged prettier
Example for pnpm: pnpm add -D husky lint-staged prettier
npx husky init
This creates .husky/ and adds "prepare": "husky" to package.json. It also auto-generates .husky/pre-commit with a default content — Step 4 will overwrite it.
.husky/pre-commitOverwrite .husky/pre-commit with:
<dlx-runner> lint-staged
<script-runner> typecheck
<script-runner> test
Where <dlx-runner> and <script-runner> come from the table in Step 1. Example for pnpm:
pnpm dlx lint-staged
pnpm run typecheck
pnpm run test
Adapt: Check package.json scripts. If no typecheck script exists, omit that line. If no test script exists, omit that line. Tell the user which lines were omitted.
Then make the file executable:
chmod +x .husky/pre-commit
.lintstagedrcIf .lintstagedrc (or .lintstagedrc.json, .lintstagedrc.js) does not already exist, create .lintstagedrc:
{
"*": "prettier --ignore-unknown --write"
}
If it already exists, leave it unchanged and tell the user.
.prettierrc (if missing)Check for any existing Prettier config: .prettierrc, .prettierrc.json, .prettierrc.js, .prettierrc.cjs, prettier.config.js, prettier.config.cjs, or a "prettier" key in package.json. If any exists, skip this step.
If none exists, create .prettierrc:
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"singleQuote": false,
"trailingComma": "es5",
"semi": true,
"arrowParens": "always"
}
.husky/pre-commit exists and is executable (ls -la .husky/pre-commit).lintstagedrc exists"prepare": "husky" is in package.json scripts<dlx-runner> lint-staged to confirm it executes without errorsIf the lint-staged run fails, check: (a) is Prettier installed? (b) does .lintstagedrc point to the right formatter?
Stage the created/modified files and commit:
git add .husky/pre-commit .lintstagedrc package.json
Add .prettierrc only if it was created in Step 6:
git add .prettierrc # only if Step 6 created it
Then commit:
git commit -m "Add pre-commit hooks (husky + lint-staged + prettier)"
This commit will run through the new pre-commit hooks — a good smoke test that everything works.
#!/bin/shprettier --ignore-unknown skips files Prettier can't parse (images, binaries, etc.)npm uninstall husky and delete the old .husky/ config) before running this skillpackage.json scripts; check for existing Prettier/lint-staged config.husky/pre-commit, .lintstagedrc, .prettierrc (if missing), update package.jsonnpx husky init, chmod +x, lint-staged verification, git add, and the final commitWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub tunoc2c/workbuddy-skill-official --plugin setup-pre-commit