setup-pre-commit

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

Updated Apr 6, 2026
One-click install
npx skills add https://github.com/toderian/project_template --skill setup-pre-commit-toderian
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/toderian/project_template/tree/main/plugins/agents-extras/skills/setup-pre-commit
Command: npx skills add https://github.com/toderian/project_template --skill setup-pre-commit-toderian

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually wiring up pre-commit hooks is repetitive and error-prone: you need to install Husky, configure lint-staged, create a Prettier config, and hook in typecheck and test scripts. This Skill automates the entire setup so every commit is formatted, type-checked, and tested before it lands. ## Core Features & Use Cases - Husky initialization: Installs Husky, runs husky init, and creates the .husky/pre-commit hook file. - lint-staged + Prettier: Adds a .lintstagedrc that runs Prettier on staged files and creates 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 start a new TypeScript project and want every commit automatically formatted and verified. Invoke the Skill and it installs the tooling, writes the hook, and commits the setup through the new hook as a smoke test. ## Quick Start Set up Husky pre-commit hooks with lint-staged, Prettier, typecheck, and tests 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 in a Node.js project?

Install husky, lint-staged, and prettier as devDependencies, then run npx husky init to create the .husky directory and prepare script. Create a .husky/pre-commit file that runs lint-staged, typecheck, and test commands.

How to run Prettier only on staged files before commit?

Use lint-staged with a .lintstagedrc containing {"*": "prettier --ignore-unknown --write"}. The pre-commit hook runs npx lint-staged, which applies Prettier only to files staged in Git, keeping commits fast.

Does Husky work with pnpm, yarn, or bun?

Yes, Husky works with any package manager. Detect the package manager from lockfiles (pnpm-lock.yaml, yarn.lock, bun.lockb) and adapt the hook commands accordingly, replacing npm with the detected tool.

Why does my Husky hook not run after setup?

Common causes are a missing prepare script in package.json (it must be "husky") or a non-executable .husky/pre-commit file. Husky v9+ does not need shebang lines in hook files, but the prepare script must have run.

What if my project has no typecheck or test script?

Omit those lines from the .husky/pre-commit file and inform the user. The hook should only reference scripts that actually exist in package.json, otherwise every commit will fail.