agentleFS
chiruu12chiruu12/claude-skills-template/.claude/skills/setup-pre-commit/SKILL.md

setup-pre-commit

Skill0 starsChanged 6 months agoMITView on GitHub

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.

150 other projects use a version of this, 135 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use migrate-to-shoehorn, writing-beats and 6 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • simo97Skill

    migrate-to-shoehorn

    Migrate test files from `as` type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace `as` in tests, or needs partial test data.

    Also in 88 projects that use this

  • LesaniSkill

    writing-beats

    Shape an article as a journey of beats, choose-your-own-adventure style. The user picks a starting beat from the raw material, you write only that beat, then offer options for where to pivot next, beat by beat, until the article reaches a natural end. Use when the user has raw material and wants to assemble it as a narrative rather than an argument.

    Also in 78 projects that use this

  • LesaniSkill

    writing-shape

    Take a markdown file of raw material and shape it into an article through a conversational session — drafting candidate openings, growing the piece paragraph by paragraph, arguing about format (lists, tables, callouts, quotes) at each step. Use when the user has a pile of notes, fragments, or a rough draft and wants help turning it into something publishable.

    Also in 78 projects that use this

  • liufeng1976Skill

    setup-ts-deep-modules

    Wire dependency-cruiser into a TypeScript repo so each package is a deep module — implementation hidden in subfolders, reachable only through its entry-point files. User-invoked.

    Also in 52 projects that use this

  • RoentekSkill

    loop-me

    Grill me about specs for the workflows I want to build, within this workspace.

    Also in 64 projects that use this

  • richard12511Skill

    claude-handoff

    Hand the current conversation off to a fresh background agent that picks up the work immediately.

    Also in 50 projects that use this

  • +1 more from Lesani

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 136 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    NOT: when project already has working Husky setup — audit/fix instead of reinstalling

    line 20
  2. Very specific:

    Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun).

    line 27
  3. Distinctive:

    DO NOT: add a shebang to Husky v9+ hook files — causes errors on some systems

    line 108

“Common” is measured: kept by at least 6 in 10 of the 136 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Setup Pre-Commit Hooks

Installs a complete pre-commit pipeline — Husky hooks running lint-staged (Prettier), type checking, and tests. Formatting debates die when the machine enforces consistency, and catching type errors at commit time is cheaper than catching them in CI 10 minutes later.

When to Use

  • User wants to add pre-commit hooks to a JavaScript/TypeScript project
  • User asks about Husky, lint-staged, or commit-time formatting
  • New project needs a standard quality gate
  • NOT for Python projects — use pre-commit framework instead
  • NOT when project already has working Husky setup — audit/fix instead of reinstalling
  • NOT for CI-only checks that shouldn't block local commits

Process

1. Detect package manager

Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun). Default to npm if unclear.

2. Install dependencies

husky lint-staged prettier

3. Initialize Husky

npx husky init

Creates .husky/ dir and adds prepare: "husky" to package.json.

4. Create .husky/pre-commit

npx lint-staged
npm run typecheck
npm run test

Adapt: Replace npm with detected package manager. If repo has no typecheck or test script, omit those lines and tell the user.

5. Create .lintstagedrc

{
  "*": "prettier --ignore-unknown --write"
}

6. Create .prettierrc (if missing)

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "arrowParens": "always"
}

7. Verify and commit

Stage all files and commit — the commit itself is the smoke test.

Common Rationalizations

ShortcutWhy It Fails
"I'll skip the test commit, it probably works"The commit IS the test. If Husky fails on the setup commit, you catch config issues immediately.
"I'll add typecheck/test hooks later"Later never comes. Include or explicitly tell user they're missing.
"I'll use --no-verify to skip the hook this once"Once becomes always. Better to fix the hook than skip it.
"Just format everything, not just staged files"Formatting unstaged files creates noise in diffs. lint-staged scopes to staged files only.

Red Flags

  • Project has no package.json (not a JS/TS project — wrong skill)
  • Existing .husky/ directory with custom hooks (could overwrite team config)
  • Monorepo with multiple packages (need per-package lint-staged config)
  • CI already runs these checks and team prefers fast local commits

Verification Checklist

  • .husky/pre-commit exists and is executable
  • .lintstagedrc exists with valid JSON
  • package.json contains "prepare": "husky"
  • Prettier config exists
  • npx lint-staged exits 0
  • A test commit triggers the pre-commit hook
  • If typecheck/test lines omitted, user was told why

Anti-patterns

  • DO NOT install globally — Husky must be a devDependency so it works for all contributors
  • DO NOT add a shebang to Husky v9+ hook files — causes errors on some systems
  • DO NOT format all files in pre-commit (prettier .) — use lint-staged for staged-only
  • DO NOT silently skip missing scripts — always inform the user
  • DO NOT overwrite existing Husky hooks without checking what's there

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.