setup-pre-commit

Configure Husky pre-commit hooks with lint-staged and Prettier for JavaScript projects.

Updated Apr 28, 2026
One-click install
npx skills add https://github.com/rnaarla/agent_skills --skill setup-pre-commit-rnaarla
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: setup-pre-commit
Source: https://github.com/rnaarla/agent_skills/tree/main/skills/misc/setup-pre-commit
Command: npx skills add https://github.com/rnaarla/agent_skills --skill setup-pre-commit-rnaarla

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Install and configure pre-commit hooks to automatically format code, run linting, and execute tests before commits, preventing common quality issues from being introduced.

Core Features & Use Cases

  • Detects the project package manager (npm, pnpm, yarn, or bun) and installs required tooling as devDependencies
  • Initializes Husky and creates a pre-commit hook that runs lint-staged and, where present, typecheck and test scripts
  • Creates lint-staged configuration and Prettier setup if missing
  • Verifies setup and provides guidance to adapt if a repo lacks certain scripts or has custom workflows
  • Use case: standardizes code quality across multiple repos and CI pipelines

Quick Start

Install the skill to automatically add pre-commit hooks to your 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 pre-commit hooks with Husky and lint-staged?

Pre-commit hooks with Husky and lint-staged are configured by installing the tooling as devDependencies, initializing Husky, and creating a pre-commit hook file that executes lint-staged to format code before commits.

What is the best way to automatically format code with Prettier before a git commit?

Automatically formatting code with Prettier before a git commit is achieved by integrating Prettier within a lint-staged configuration, which is triggered by a Husky pre-commit hook to run exclusively on staged files.

Can I use Husky pre-commit hooks with pnpm or bun package managers?

Yes, you can use Husky pre-commit hooks with pnpm or bun. The setup process detects your project's package manager automatically across npm, pnpm, yarn, or bun ecosystems and installs the required dependencies accordingly.

How do pre-commit hooks work when typecheck or test scripts are missing?

When typecheck or test scripts are missing, the pre-commit hook adapts by omitting those commands and exclusively running lint-staged with Prettier formatting, while providing guidance on how to customize the setup for custom workflows.

Why should I use lint-staged instead of running Prettier directly in git hooks?

You should use lint-staged instead of running Prettier directly because lint-staged executes checks only on staged files, preventing slow commits and ensuring code quality enforcement targets only the changes being committed.