agentleFS
chrislacey89chrislacey89/skills/setup-pre-commit/SKILL.md

setup-pre-commit

Skill3 starsChanged 2 months agoMITView on GitHub

Infrastructure skill for setting up commit-time quality gates. Use when a repo needs Lefthook-based pre-commit hooks for formatting, linting, type checking, and tests. Supports downstream /execute and /pre-merge, but is not part of the normal feature-delivery pipeline.

  • Deletes or force-pushes
  • Installs packages

54 other projects use a version of this, 44 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.
  • qhuang20Skill

    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 33 projects that use this

  • RoentekSkill

    writing-beats

    Writing, exploit — assemble raw material into a journey of beats, grounding each term before a beat leans on it.

    Also in 23 projects that use this

  • RoentekSkill

    writing-shape

    Writing, exploit — shape raw material into an article, paragraph by paragraph.

    Also in 23 projects that use this

  • kayamanSkill

    edit-article

    Edit and improve articles by restructuring sections, improving clarity, and tightening prose. Use when user wants to edit, revise, or improve an article draft.

    Also in 20 projects that use this

  • loulanyueSkill

    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 16 projects that use this

  • qwlabsSkill

    claude-handoff

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

    Also in 16 projects that use this

  • +2 more from Roentek

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 5 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 49 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use /setup-pre-commit when a project needs commit-time formatting, linting, type checking, and test hooks.

    line 12
  2. Very specific:

    Do not use it as part of the default feature pipeline.

    line 14
  3. Very specific:

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

    line 26
  4. Distinctive:

    Before installing anything, check what's already in the project:

    line 32
  5. Distinctive:

    If an existing formatter/linter is detected: use it. Don't install a competing tool.

    line 41
  6. Distinctive:

    Ask: "No formatter/linter detected.

    line 45
  7. Very specific:

    Add a prepare script to package.json so hooks are installed automatically for anyone who clones the repo:

    line 85
  8. Very specific:

    Create lefthook.yml at the repo root.

    line 97
  9. Very specific:

    If the repo has no typecheck script in package.json, omit that command and tell the user

    line 169
  10. Distinctive:

    Only create if no config exists and the user chose to install a new tool.

    line 175
  11. Distinctive:

    If the project previously used Husky:

    line 223
  12. Very specific:

    Update the prepare script in package.json from "husky" to "lefthook install".

    line 234

“Common” is measured: kept by at least 6 in 10 of the 49 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

Invocation Position

This is an infrastructure skill, not a normal feature-delivery stage.

Use /setup-pre-commit when a project needs commit-time formatting, linting, type checking, and test hooks.

Do not use it as part of the default feature pipeline. It prepares the repo so later /execute and /pre-merge steps have stronger feedback loops.

What This Sets Up

  • Lefthook for git hook management (fast, zero-dependency, config-as-code)
  • Formatting + linting on staged files (Biome preferred; Prettier, ESLint, or others supported)
  • Typecheck and test scripts in the pre-commit hook

Steps

1. Detect Package Manager

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

Store the detected package manager — it's used for all install and run commands below.

2. Detect Existing Formatter/Linter

Before installing anything, check what's already in the project:

# Check package.json for existing tools
cat package.json | grep -E "biome|prettier|eslint|oxlint|dprint" 2>/dev/null
# Check for config files
ls biome.json biome.jsonc .prettierrc .prettierrc.* prettier.config.* .eslintrc* eslint.config.* 2>/dev/null

If an existing formatter/linter is detected: use it. Don't install a competing tool.

If nothing is detected: recommend Biome (single tool for formatting + linting, fast, zero-config defaults) and confirm with the user before installing.

Ask: "No formatter/linter detected. I'd recommend Biome — it handles both formatting and linting in one tool, is very fast, and works out of the box. Want to go with Biome, or would you prefer Prettier, ESLint, or something else?"

3. Install Dependencies

Install as devDependencies using the detected package manager:

Lefthook (always):

# pnpm
pnpm add -D lefthook

# npm
npm install -D lefthook

# yarn
yarn add -D lefthook

# bun
bun add -D lefthook

Formatter/linter (based on detection or user choice):

ToolInstallConfig file
Biome (preferred)@biomejs/biomebiome.json
Prettierprettier.prettierrc
ESLinteslinteslint.config.*
Prettier + ESLintprettier eslintboth
oxlintoxlintoxlint.json
dprintdprintdprint.json

4. Initialize Lefthook

npx lefthook install

This creates the git hook symlinks. No .husky/ directory, no prepare script needed — Lefthook manages hooks directly via lefthook.yml.

Add a prepare script to package.json so hooks are installed automatically for anyone who clones the repo:

{
  "scripts": {
    "prepare": "lefthook install"
  }
}

5. Create lefthook.yml

Create lefthook.yml at the repo root. The configuration depends on which formatter/linter was detected or chosen.

With Biome (preferred):

pre-commit:
  parallel: true
  commands:
    format-and-lint:
      glob: "*.{js,ts,jsx,tsx,json,css}"
      run: npx @biomejs/biome check --write --staged {staged_files}
      stage_fixed: true
    typecheck:
      run: {package_manager} run typecheck
    test:
      run: {package_manager} run test

With Prettier:

pre-commit:
  parallel: true
  commands:
    format:
      glob: "*.{js,ts,jsx,tsx,json,css,md,yml,yaml}"
      run: npx prettier --write {staged_files}
      stage_fixed: true
    typecheck:
      run: {package_manager} run typecheck
    test:
      run: {package_manager} run test

With ESLint:

pre-commit:
  parallel: true
  commands:
    lint:
      glob: "*.{js,ts,jsx,tsx}"
      run: npx eslint --fix {staged_files}
      stage_fixed: true
    typecheck:
      run: {package_manager} run typecheck
    test:
      run: {package_manager} run test

With Prettier + ESLint:

pre-commit:
  parallel: true
  commands:
    format:
      glob: "*.{js,ts,jsx,tsx,json,css,md,yml,yaml}"
      run: npx prettier --write {staged_files}
      stage_fixed: true
    lint:
      glob: "*.{js,ts,jsx,tsx}"
      run: npx eslint --fix {staged_files}
      stage_fixed: true
    typecheck:
      run: {package_manager} run typecheck
    test:
      run: {package_manager} run test

Adapt the config:

  • Replace {package_manager} with the detected package manager (pnpm, npm, yarn, bun)
  • If the repo has no typecheck script in package.json, omit that command and tell the user
  • If the repo has no test script in package.json, omit that command and tell the user
  • Adjust glob patterns to match the project's file types

6. Create Formatter Config (if missing)

Only create if no config exists and the user chose to install a new tool.

Biome (biome.json):

{
  "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
  "organizeImports": {
    "enabled": true
  },
  "formatter": {
    "indentStyle": "space",
    "indentWidth": 2,
    "lineWidth": 80
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true
    }
  }
}

Prettier (.prettierrc):

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

7. Verify

  • lefthook.yml exists at repo root
  • prepare script in package.json is "lefthook install"
  • Formatter/linter config exists
  • Run npx lefthook run pre-commit to verify hooks work
  • No .husky/ directory exists (if migrating from Husky, remove it)

8. Clean Up Husky (if migrating)

If the project previously used Husky:

# Remove Husky artifacts
rm -rf .husky
# Remove Husky from dependencies
{package_manager} remove husky lint-staged
# Remove .lintstagedrc if it exists and is no longer needed
rm -f .lintstagedrc .lintstagedrc.* lint-staged.config.*

Update the prepare script in package.json from "husky" to "lefthook install".

9. Commit

Stage all changed/created files and commit with message:

chore: add pre-commit hooks (lefthook + biome) (or substitute the actual formatter name)

This will run through the new pre-commit hooks — a good smoke test that everything works.

Why Lefthook over Husky

  • No node_modules dependency at hook runtime — Lefthook hooks run directly, no npx lint-staged wrapper
  • Config as code — lefthook.yml is declarative and version-controlled; Husky uses shell scripts in .husky/
  • Parallel execution — runs formatting, typecheck, and tests in parallel by default
  • {staged_files} built-in — no need for lint-staged as a separate dependency; Lefthook handles staged file filtering natively
  • stage_fixed: true — automatically re-stages files after formatting fixes, no extra tooling
  • Glob filtering — only runs tools on matching file types, no wasted cycles

Why Biome as Default

  • Single tool — replaces both Prettier (formatting) and ESLint (linting)
  • Fast — written in Rust, 10-100x faster than Prettier + ESLint
  • Zero config — works out of the box with sensible defaults
  • Compatible — 97% Prettier-compatible formatting, growing ESLint rule coverage
  • One config file — biome.json instead of .prettierrc + .eslintrc + conflicting rules

Handoff

  • Expected input: a repo that needs commit-time quality gates
  • Produces: working git hooks and tool configuration for commit-time checks
  • Supports downstream: /execute and /pre-merge by making basic verification more automatic
  • What comes next: return to normal feature work with stronger local feedback loops

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.