setup-pre-commit

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

Updated May 11, 2026
One-click install
npx skills add https://github.com/mmnavarr/harness --skill setup-pre-commit-mmnavarr
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/mmnavarr/harness/tree/main/skills/setup-pre-commit
Command: npx skills add https://github.com/mmnavarr/harness --skill setup-pre-commit-mmnavarr

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually wiring up pre-commit hooks in a JavaScript or TypeScript repo is repetitive and error-prone: you must pick the right package manager, install Husky and lint-staged, write hook files, and keep Prettier config consistent. This Skill automates the entire setup so every commit is formatted, type-checked, and tested before it lands. ## Core Features & Use Cases - Package manager detection: Detects npm, pnpm, yarn, or bun from lockfiles and adapts all commands accordingly. - Hook scaffolding: Installs husky, lint-staged, and prettier, runs husky init, and writes a .husky/pre-commit hook that runs lint-staged, typecheck, and tests. - Config generation: Creates .lintstagedrc and a sensible .prettierrc only when no Prettier config already exists. - Use Case: You clone a fresh TypeScript project with no commit automation. Invoke this Skill and it installs the tooling, writes the hook files, verifies the setup, and commits everything through the new hooks 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 with lint-staged?▼

Install husky, lint-staged, and prettier as devDependencies, run npx husky init, then create a .husky/pre-commit file that runs npx lint-staged followed by your typecheck and test scripts. Add a .lintstagedrc mapping files to prettier --write.

How to run Prettier 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 the hook never fails on binary assets.

Does Husky v9 need a shebang in hook files?▼

No, Husky v9 and later do not require shebang lines in hook files like .husky/pre-commit. You can write plain commands such as npx lint-staged directly in the file.

Can I use Husky with pnpm, yarn, or bun instead of npm?▼

Yes, Husky works with any package manager. Detect the manager from the lockfile (pnpm-lock.yaml, yarn.lock, bun.lockb) and substitute its commands 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.