husky-and-hooks
Use when the user asks about git hooks, Husky, lint-staged, pre-commit or commit-msg hooks, commitlint, pre-push, lefthook, the pre-commit framework…
от j4flmao★ 47 звёзд на GitHub
Установить husky-and-hooks в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Git Hooks with Husky, lint-staged and Friends
Purpose
Client-side hooks catch formatting, lint and commit-message problems seconds after they are made instead of minutes later in CI. They are a convenience, not enforcement: anyone can bypass them, so CI must run the same checks. This skill sets up fast, cross-platform hooks and explains how to debug them.
Agent Protocol
Trigger
"git hooks", "husky", "lint-staged", "pre-commit hook", "commit-msg", "commitlint", "pre-push", "lefthook", "pre-commit framework", "hooks not running", "core.hooksPath".
Input Context
- Repo languages and package manager (npm/pnpm/yarn/bun, Python uv, polyglot)
- Checks wanted per stage and their run time
- OS mix of contributors (Windows needs a POSIX shell such as Git Bash for shell hooks)
Output Artifact
Hook files, package.json/config snippets, and troubleshooting steps. No file unless requested.
Response Format
Tool: {husky + lint-staged | pre-commit | lefthook}
Hooks: {hook -> command -> target time}
Config: {snippets}
CI parity: {same checks in CI}
Bypass/debug: {how to skip once, how to debug}
1. How Hooks Work
- Git runs executable scripts from
.git/hooks/(or the directory incore.hooksPath) at events. Client-side:pre-commit,prepare-commit-msg,commit-msg,post-commit,pre-rebase,post-checkout,post-merge,pre-push. - A non-zero exit from
pre-commit,commit-msgorpre-pushaborts the operation. .git/hooksis not versioned; tools like Husky setcore.hooksPathto a committed directory so the team shares hooks.- Bypass:
git commit --no-verify/git push --no-verify(skips pre-commit, commit-msg and pre-push). For Husky,HUSKY=0disables hooks (useful in CI and scripted commits).
2. Husky v9 Setup (JavaScript repos)
npm install --save-dev husky lint-staged @commitlint/cli @commitlint/config-conventional
npx husky init # creates .husky/pre-commit and adds "prepare": "husky" to package.json
package.json:
{
"scripts": { "prepare": "husky" },
"lint-staged": {
"*.{js,jsx,ts,tsx}": ["eslint --fix --max-warnings=0", "prettier --write"],
"*.{json,md,yml,yaml,css}": "prettier --write"
}
}
.husky/pre-commit:
npx lint-staged
.husky/commit-msg:
npx --no -- commitlint --edit "$1"
commitlint.config.js (ESM projects use export default; CommonJS module.exports):
export default { extends: ['@commitlint/config-conventional'] };
.husky/pre-push (optional, keep it fast):
npm run typecheck && npm test -- --run
- Husky v9 hook files are plain shell scripts; the old
. "$(dirname -- "$0")/_/husky.sh"line from v8 is no longer needed (and is deprecated). prepareruns onnpm install, so hooks install automatically for contributors. In production/CI installs without devDependencies thehuskybinary is missing; use"prepare": "husky || true"or setHUSKY=0.- Monorepo with the package in a subdirectory: run
huskyfrom that package with the hooks directory path, andcdinto it inside hooks.
3. lint-staged Behaviour
- Runs commands only on staged files that match each glob, passes file paths as arguments, and re-stages files modified by fixers.
- Stashes unstaged changes before running and restores them afterwards, so partially staged files are checked as they will be committed.
- Keep tasks to per-file tools (formatters, linters). Project-wide checks (
tsc --noEmit, full test suite) belong inpre-pushor CI because they ignore the file list and are slow. - For type checking only changed files, use a function config:
"*.ts": () => "tsc --noEmit"(runs once, without file arguments).
4. Language-Agnostic Alternatives
| Tool | Config | Strengths |
|---|---|---|
| pre-commit (pre-commit.com) | .pre-commit-config.yaml |
huge hook catalogue, isolated environments per hook, pre-commit run --all-files in CI; popular in Python/polyglot repos |
| lefthook | lefthook.yml |
single Go binary, parallel hooks, glob filtering, no Node needed |
Plain core.hooksPath |
committed scripts/hooks/ + git config core.hooksPath scripts/hooks |
zero dependencies |
pre-commit example:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9 # pin; update with `pre-commit autoupdate`
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.2
hooks:
- id: gitleaks
Pin revs to tags and update them deliberately (pre-commit autoupdate); check current versions when copying.
5. What to Run Where
| Stage | Target time | Checks |
|---|---|---|
| pre-commit | < 5 s | format, lint fix on staged files, secret scan (gitleaks), large-file and merge-marker checks |
| commit-msg | < 1 s | commitlint / message format |
| pre-push | < 60 s | type check, unit tests for affected packages |
| CI (re |
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл husky-and-hooks?
Use when the user asks about git hooks, Husky, lint-staged, pre-commit or commit-msg hooks, commitlint, pre-push, lefthook, the pre-commit framework, core.hooksPath or hooks not running. Produces client-side hook setup that matches CI. Not for CI pipelines (use github-actions or devops-gitlab-ci) or branching policy (use advanced-workflows).
Как установить скилл husky-and-hooks?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл husky-and-hooks запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…