Skip to content
Back to skills

Setup Pre Commit

ASecurity

Use when setting up Husky pre-commit hooks with lint-staged and formatting

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 10, 2026
ai-agentsrailsgit

Security analysis

A100/100

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill setup-pre-commit --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Setup Pre Commit?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Setup Pre Commit
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-setup-pre-commit/badge)](https://www.skillsdirectory.com/skills/loopyluci-setup-pre-commit)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: setup-pre-commit
description: Use when setting up Husky pre-commit hooks with lint-staged and formatting
tags: [pre-commit, hooks, husky, lint-staged, prettier]
related_skills: [git-guardrails-claude-code, git-hooks-workflow]
---

# Setup Pre Commit

Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repository.

## What this sets up
- Husky pre-commit hook
- lint-staged running Prettier on all staged files
- Prettier config (if missing)
- Typecheck and test scripts in the pre-commit hook

## Steps
1. Detect package manager (npm, pnpm, yarn, bun)
2. Install: husky, lint-staged, prettier as devDependencies
3. Initialize Husky: npx husky init
4. Create .husky/pre-commit with lint-staged, typecheck, and test
5. Create .lintstagedrc with Prettier config
6. Create .prettierrc if missing
7. Verify everything is working

## Common Pitfalls

- **Missing package manager detection**: Check for package-lock.json, pnpm-lock.yaml, yarn.lock, bun.lockb before installing. Defaulting to npm may add the wrong lockfile.
- **Husky v9 does not need a shebang**: For Husky v9+, the .husky/pre-commit file does not need a shebang line. Adding one may cause issues.
- **Not checking for existing typecheck/test scripts**: If the repo has no typecheck or test script, omit those lines from the hook and tell the user.

## Verification Checklist

- [ ] Package manager detected correctly
- [ ] husky, lint-staged, prettier installed as devDependencies
- [ ] .husky/pre-commit exists and is executable
- [ ] .lintstagedrc exists with Prettier configuration
- [ ] .prettierrc exists (or Prettier config detected)
- [ ] prepare script in package.json is 'husky'
- [ ] Hook runs formatting, typecheck, and test on commit

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.