| name | setup-pre-commit |
| description | Use this skill when > Configure automated code quality checks at commit time using Husky and lint-staged. Sets up pre-commit hooks for formatting (Prettier), type checking, and tests. Adapts to existing project configurations and omits missing scripts gracefully. |
| allowed-tools | Read Grep Glob Bash Write Edit |
| compatibility | Works with npm, yarn, pnpm, and bun. Requires Node.js project with package.json. Husky v9+ (no shebangs needed in hook files). Pairs with git-workflow and git-guardrails-claude-code.
|
| metadata | {"tags":"git-hooks, pre-commit, husky, lint-staged, prettier, code-quality, automation","platforms":"Claude, ChatGPT, Gemini, Codex","version":"1.0","source":"mattpocock/skills"} |
Setup Pre-Commit
Configure automated code quality checks at commit time using Husky and lint-staged.
When to use this skill
- Setting up a new project's commit-time quality gates
- Adding formatting and type checking to an existing project
- Standardizing pre-commit behavior across a team
When not to use this skill
- CI pipeline setup → use
deployment-automation
- Git workflow strategy → use
git-workflow
- Full testing strategy → use
testing-strategies
Installation process
Step 1 — Detect package manager
ls package-lock.json
ls yarn.lock
ls pnpm-lock.yaml
ls bun.lockb
Step 2 — Install dependencies
npm install --save-dev husky lint-staged prettier
pnpm add -D husky lint-staged prettier
yarn add -D husky lint-staged prettier
Step 3 — Initialize Husky
npx husky init
This creates .husky/ directory and adds a prepare script to package.json.
Step 4 — Create the pre-commit hook
Create .husky/pre-commit:
npx lint-staged
npm run typecheck
npm test
Note: Husky v9+ doesn't need shebangs in hook files.
Step 5 — Configure lint-staged
Create .lintstagedrc:
{
"**/*": "prettier --write --ignore-unknown"
}
Step 6 — Configure Prettier (if absent)
Create .prettierrc only if it doesn't exist:
{
"tabWidth": 2,
"printWidth": 80,
"singleQuote": false,
"trailingComma": "es5",
"semi": true,
"arrowParens": "always"
}
Step 7 — Verify
git add -A
git commit -m "test: verify pre-commit hooks"
Watch for: lint-staged formatting, typecheck passing, tests passing.
Execution order
lint-staged runs first (fast, only staged files) → typecheck (full project) → tests (full suite)
If typecheck or test scripts don't exist in package.json, omit those lines from the pre-commit hook.
Instructions
- Identify the task trigger and expected output.
- Follow the workflow steps in this skill from top to bottom.
- Validate outputs before moving to the next step.
- Capture blockers and fallback path if any step fails.
Examples
- Example: Apply this skill to a small scope first, then scale to full scope after validation passes.
Best practices
- Keep outputs deterministic and auditable.
- Prefer small reversible changes over broad risky edits.
- Record assumptions explicitly.
References
- Project standards:
.agent-skills/skill-standardization/SKILL.md
- Validator script:
.agent-skills/skill-standardization/scripts/validate_skill.sh