setup-pre-commit
by mattpococksetup-pre-commit helps you add Husky pre-commit hooks with lint-staged, Prettier, and optional typecheck/test runs. Use this setup-pre-commit guide when your repo needs a fast, repeatable pre-commit safety net and you want to preserve existing config while adding the right scripts for the current package manager.
This skill scores 78/100, which means it is a solid listing candidate for directory users: it provides a real, triggerable workflow for setting up Husky pre-commit hooks with lint-staged, Prettier, type checking, and tests, though it still has some adoption caveats around verification and edge-case handling.
- The trigger is explicit and practical: it targets adding Husky pre-commit hooks, configuring lint-staged, and commit-time formatting/typechecking/testing.
- Operational steps are concrete and sequence-based, including package manager detection, dependency install, Husky init, hook file creation, and Prettier setup.
- The description and body give enough workflow detail for an agent to execute with less guesswork than a generic prompt, including exact commands and file contents.
- No install command or supporting scripts/resources are included, so users must rely on the SKILL.md instructions alone.
- The repo is marked with a test signal and the guidance says to omit typecheck/test lines if scripts are missing, which makes the workflow somewhat conditional rather than fully turnkey.
Overview of setup-pre-commit skill
The setup-pre-commit skill helps you add a practical Git hook workflow: Husky pre-commit checks, lint-staged formatting with Prettier, and optional typecheck/test runs before code lands in a commit. It is best for repos that already have a Node-based toolchain and need a fast, repeatable setup instead of a hand-built hook.
What setup-pre-commit is for
Use the setup-pre-commit skill when you want a commit-time safety net that standardizes formatting and catches obvious breakages early. The real job is not “install Husky” in isolation; it is to make local commits safer without forcing you to redesign the repo.
When it is a strong fit
It is a good fit if your repo already uses or can use Prettier, typecheck, and test scripts, and you want a straightforward convention that works across npm, pnpm, Yarn, or Bun. It is also useful when you need a setup that can be applied quickly in an existing project with minimal policy debate.
Where it is limited
This skill is less useful if your project is not Node-based, if you want commit-msg or pre-push logic instead of pre-commit, or if your checks need custom orchestration beyond a simple hook. It also assumes you are comfortable verifying which scripts exist before adding them to the hook.
How to Use setup-pre-commit skill
Install and open the right files
Install with npx skills add mattpocock/skills --skill setup-pre-commit. Then read SKILL.md first, because it contains the actual workflow and decision points. If your directory view exposes only one file, that is enough to follow the setup, but you should still inspect the repository tree for package-manager and script clues.
Feed it the right repo context
For best results, tell the skill which lockfile exists, whether package.json already has typecheck and test, and whether Prettier is already configured. A strong request looks like: “Set up setup-pre-commit in this repo using pnpm; keep existing Prettier config; add only the scripts that already exist.” That is better than “add pre-commit hooks,” because it removes guesswork about package manager and hook contents.
Follow the workflow in the right order
The skill is designed around a simple sequence: detect the package manager, install dev dependencies, initialize Husky, write .husky/pre-commit, add lint-staged, and create or reuse a Prettier config. In practice, the important decision is whether to include npm run typecheck and npm run test or omit them when those scripts are missing. That choice keeps the hook useful instead of brittle.
Practical prompt pattern
Use a prompt that names the repo state and the desired policy. For example: “Use setup-pre-commit to add Husky, lint-staged, and Prettier to this monorepo. The lockfile is pnpm-lock.yaml, typecheck exists, test does not, and there is already a .prettierrc.” This gives the skill enough detail to produce a correct setup without inventing scripts or overwriting config.
setup-pre-commit skill FAQ
Is setup-pre-commit only for new repositories?
No. The setup-pre-commit skill is often more valuable in existing repos because it helps you add a consistent hook policy without manually reconstructing files. It works best when you already know what scripts and config are present.
Do I need both Husky and lint-staged?
For this workflow, yes, that is the point. Husky triggers the hook, and lint-staged scopes formatting to staged files so commits stay fast. If you only want one of those pieces, a generic prompt may be simpler than the setup-pre-commit skill.
Will it overwrite my Prettier setup?
It should not if used carefully. The skill creates .prettierrc only when one is missing, and the main decision is whether your repo already has a formatter config that should be preserved. If you have an existing style policy, mention it explicitly.
Is it good for CI or only local commits?
The main value is local pre-commit enforcement, but the same checks often mirror CI expectations. If your CI uses different commands, make sure you do not blindly copy the hook; align the hook with the scripts your pipeline actually runs. This is the main setup-pre-commit for CI Troubleshooting concern.
How to Improve setup-pre-commit skill
Give the skill your repo’s real constraints
The biggest quality jump comes from telling setup-pre-commit which package manager, scripts, and config files already exist. Missing that context leads to wrong command prefixes, unnecessary script creation, or hook steps that fail on the first commit.
Avoid common hook failures
The most common failure mode is adding typecheck or test to .husky/pre-commit when those scripts do not exist. Another frequent issue is formatting every file instead of staged files only, which makes commits slower than necessary. If you want the hook to be reliable, specify what should happen when a script is absent.
Improve the first output with explicit targets
Ask for concrete outcomes, not just installation. A better instruction is: “Add Husky pre-commit hooks that run lint-staged on staged files, preserve the existing Prettier config, and include typecheck only if package.json already defines it.” That produces a more usable setup-pre-commit guide result than a vague request.
Iterate after the first pass
After the initial setup, check whether the hook matches team expectations for speed and strictness. If it feels too heavy, remove expensive checks from pre-commit and move them to CI; if it is too loose, add the missing script or narrow the lint-staged scope. The best setup-pre-commit install outcome is the one that your team will actually keep running.
