Back to Skills

setup-pre-commit

Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.

59,070stars5,086forksUpdated 5/5/2026

Security Assessment

Safe(100/100)
Security Score100/100

About setup-pre-commit

The `setup-pre-commit` skill automates the configuration of pre-commit hooks in a JavaScript or TypeScript repository. It addresses the common problem of ensuring code quality and consistency before changes are committed by integrating Husky, lint-staged, Prettier, type checking, and testing into a seamless workflow. By setting up these tools automatically, the skill reduces manual setup time and minimizes errors, allowing developers to enforce formatting, run type checks, and execute tests on staged files before each commit.

This skill installs and configures Husky for pre-commit hooks, sets up lint-staged to run Prettier on all staged files, and ensures that type checking and test scripts are included in the pre-commit process if they exist in the project. It also generates a default Prettier configuration if one is missing and verifies that all necessary files and scripts are in place. The hooks are optimized to run lint-staged first, which processes only staged files for faster execution, followed by full type checks and tests, providing a comprehensive code quality check at commit time.

`setup-pre-commit` is ideal for developers and teams who want to maintain consistent code formatting, enforce quality checks, and catch errors early in the development process. It is particularly useful for JavaScript and TypeScript projects where multiple contributors are committing changes frequently. By automating pre-commit hooks, the skill helps maintain a clean and reliable codebase, reduces the risk of introducing errors, and streamlines the development workflow, making it suitable for open-source contributors, team projects, and individual developers seeking automated code quality enforcement.

FAQ

Which package managers are supported by this skill?

The skill detects npm, pnpm, yarn, and bun based on the presence of their respective lock files and defaults to npm if none are found.

Do I need an existing Prettier configuration to use this skill?

No, the skill will create a default `.prettierrc` file if none exists in the repository.

What happens if my project does not have typecheck or test scripts?

If `typecheck` or `test` scripts are missing from package.json, those lines are omitted from the pre-commit hook, and the user is informed.

Is this compatible with Husky versions before v9?

The documentation specifies Husky v9+, which does not require shebangs in hook files. Compatibility with earlier versions is not covered.

How can I verify that the pre-commit hooks are working?

You can verify by checking that `.husky/pre-commit` and `.lintstagedrc` exist, the `prepare` script in package.json is set to 'husky', a Prettier config exists, and by running `npx lint-staged` to ensure it executes correctly.

Install setup-pre-commit

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill