setup-pre-commit

Configures Husky pre-commit hooks with lint-staged, Prettier, typecheck, and tests.

1|Updated Jul 2, 2026
One-click install
npx skills add https://github.com/filippolmt/skills --skill setup-pre-commit-filippolmt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/filippolmt/skills/tree/main/skills/setup-pre-commit
Command: npx skills add https://github.com/filippolmt/skills --skill setup-pre-commit-filippolmt

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires husky, lint-staged, prettier.

What problem does it solve? Setting up pre-commit hooks manually involves juggling Husky initialization, lint-staged configuration, Prettier defaults, and package manager differences, which is error-prone and easy to get wrong. ## Core Features & Use Cases - Husky Hook Setup: Installs Husky, initializes it, and creates a .husky/pre-commit hook that runs lint-staged, typecheck, and tests. - Lint-Staged + Prettier Config: Creates .lintstagedrc to run Prettier on staged files and generates a .prettierrc with sensible defaults if none exists. - Package Manager Detection: Detects npm, pnpm, yarn, or bun from lockfiles and adapts all commands accordingly. - Use Case: You just scaffolded a new TypeScript project and want every commit automatically formatted, type-checked, and tested before it lands in the repository. ## Quick Start Set up Husky pre-commit hooks with lint-staged and Prettier in this repository.

Frequently Asked Questions about setup-pre-commit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Husky pre-commit hooks with lint-staged?

Install husky, lint-staged, and prettier as devDependencies, run npx husky init, then create a .husky/pre-commit file calling npx lint-staged. Add a .lintstagedrc mapping files to prettier --ignore-unknown --write.

How to run Prettier only on staged files before commit?

Use lint-staged with a .lintstagedrc containing {"*": "prettier --ignore-unknown --write"}. The --ignore-unknown flag skips files Prettier cannot parse, such as images, so commits never fail on binary assets.

Does Husky work with pnpm, yarn, or bun?

Yes, Husky works with any package manager. Detect the manager from lockfiles (pnpm-lock.yaml, yarn.lock, bun.lockb) and replace npm with the detected command in the pre-commit hook and install steps.

Why does my Husky pre-commit hook not run after setup?

Verify that .husky/pre-commit exists and is executable, and that package.json contains a prepare script set to "husky". Without the prepare script, hooks are not installed after npm install.

What if my project has no typecheck or test script?

Omit the typecheck and test lines from the .husky/pre-commit file and inform the user. The hook should only reference scripts that actually exist in package.json to avoid failing every commit.