setup-pre-commit

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Setting up pre-commit quality checks manually involves juggling Husky initialization, lint-staged configuration, Prettier defaults, and package manager differences, which is error-prone and easy to skip. This Skill automates the entire setup so every commit runs formatting, type checking, and tests consistently. ## Core Features & Use Cases - Automated Husky Setup: Installs Husky, initializes the .husky/ directory, and wires the prepare script in package.json. - lint-staged + Prettier Integration: 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 inherit a JavaScript repo with no commit-time checks. Run this Skill to add a pre-commit hook that formats staged files, runs typecheck, and executes tests before every commit. ## 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. Add 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 manager via lockfiles (pnpm-lock.yaml, yarn.lock, bun.lockb) and replace npm with the detected command in the pre-commit hook and install steps.

What if my package.json 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.

Why does my Husky hook fail with a shebang error?

Husky v9 and later does not require shebang lines in hook files, and legacy boilerplate can cause issues. Write the .husky/pre-commit file with plain commands like npx lint-staged and no shebang.