shared-tooling-git-hooks
Git hooks、lint-staged、commitlintなどを設定し、CI/本番環境に対応、モノレポ構成やv8からの移行もサポートすることで、開発ワークフローを効率化し、コード品質を向上させるSkill。
📜 元の英語説明(参考)
Husky v9 setup, lint-staged v16 patterns, commitlint with conventional commits, CI/production handling, monorepo setup, migration from v8
🇯🇵 日本人クリエイター向け解説
Git hooks、lint-staged、commitlintなどを設定し、CI/本番環境に対応、モノレポ構成やv8からの移行もサポートすることで、開発ワークフローを効率化し、コード品質を向上させるSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o shared-tooling-git-hooks.zip https://jpskill.com/download/10268.zip && unzip -o shared-tooling-git-hooks.zip && rm shared-tooling-git-hooks.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10268.zip -OutFile "$d\shared-tooling-git-hooks.zip"; Expand-Archive "$d\shared-tooling-git-hooks.zip" -DestinationPath $d -Force; ri "$d\shared-tooling-git-hooks.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
shared-tooling-git-hooks.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
shared-tooling-git-hooksフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Git Hooks
簡単なガイド: git hooks には Husky v9 を使用し、
"prepare": "husky"を指定します ("husky install"ではありません)。ステージングされたファイルのみの lint には lint-staged v16 を使用します。conventional commit メッセージには commitlint を使用します。Pre-commit hooks は 10 秒未満で完了する必要があります。CI/本番環境ではHUSKY=0を設定してください。
<critical_requirements>
重要: この Skill を使用する前に
すべてのコードは CLAUDE.md のプロジェクト規約に従う必要があります (kebab-case、名前付きエクスポート、インポート順序、
import type、名前付き定数)
(package.json で "prepare": "husky" を必ず使用してください - 非推奨の "husky install" ではありません)
(lint-staged を使用してステージングされたファイルのみを lint してください - pre-commit でコードベース全体を lint しないでください)
(CI/本番環境では HUSKY=0 を設定して hooks を無効にしてください)
(.husky/ ディレクトリにプレーンな hook ファイルを使用してください - v9 では shebang 行や husky.sh のソースはありません)
(pre-commit hooks を 10 秒未満に保ってください - 時間のかかるタスクは pre-push または CI に移動してください)
</critical_requirements>
自動検出: Husky, husky init, .husky/, pre-commit hook, lint-staged, commitlint, conventional commits, commit-msg hook, git hooks, prepare script
使用する場面:
- Husky + lint-staged で pre-commit hooks を設定する
- commitlint で commit メッセージの検証を設定する
- Husky v8 から v9 に移行する
- monorepo セットアップで git hooks を設定する
- CI/本番環境で hooks を無効にする
使用しない場面:
- Linter/formatter の設定自体 (別の関心事)
- CI/CD パイプラインの設定 (別の関心事)
- ランタイムアプリケーションコード (これは開発者のワークフローツールのみです)
カバーする主要なパターン:
- Husky v9 のセットアップと hook の作成
- lint-staged v16 の設定パターン
- conventional commits を使用した commitlint
- CI/本番環境での hook の無効化
- Monorepo のセットアップ
- Husky v8 から v9 への移行
詳細なリソース:
- examples/core.md - セットアップ、lint-staged の設定、commitlint、CI の処理、monorepo、移行
- reference.md - 意思決定フレームワーク、ツール比較、アンチパターン
<philosophy>
Philosophy
Git hooks は 開発者のワークフローツール です - 高速で非ブロッキングを維持しながら、問題を早期に検出します。目標は、ステージングされたファイルのみに対する高速なフィードバック (10 秒未満) です。Hooks はオプションのインフラストラクチャです。多くのプロジェクトはそれらなしでも問題なく動作します。
git hooks を使用する場面:
- コード品質ゲートが CI の失敗を防ぐチームプロジェクト
- 確立された lint/フォーマットがあり、それを強制する必要があるプロジェクト
- コードが CI に到達する前に高速なフィードバックが必要な場合
- フル lint の実行が遅すぎる Monorepos
使用しない場面:
- 常に lint を忘れないソロプロジェクト (メリットなしにオーバーヘッド)
- まだ確立された lint/フォーマットルールがないプロジェクト (最初に lint を設定する)
- pre-commit hooks が 10 秒を超える場合 (代わりに CI に移動する)
- hooks が価値なしに摩擦を追加する CI 専用プロジェクト
</philosophy>
<patterns>
Core Patterns
Pattern 1: Husky v9 Setup
Husky v9 は、.husky/ ディレクトリにプレーンなシェルスクリプトを使用します。shebang 行は必要ありません。prepare スクリプトは、すべてのチームメンバーに対して hooks を自動的にインストールします。
# 4 つのコマンドで完全なセットアップ
bun add -D husky
bunx husky init # .husky/ を作成し、package.json に "prepare": "husky" を追加します
bun add -D lint-staged
echo "bunx lint-staged" > .husky/pre-commit
重要なポイント:
"prepare": "husky"("husky install"ではありません - 非推奨、v10 で壊れます)- Hook ファイルはプレーンなシェルスクリプトです (v9 では shebang は不要)
HUSKY=0は hooks を無効にします (CI/本番環境)。HUSKY=2はデバッグモードを有効にします- v9.1.1 以降では、npx/bunx なしでパッケージコマンドを直接実行できます
完全なセットアップと package.json の設定については、examples/core.md を参照してください。
Pattern 2: Pre-commit Hook with lint-staged
lint-staged v16 は、ステージングされたファイルに対してのみコマンドを実行します。glob マッチングには picomatch を使用します (以前の micromatch を置き換えました)。
// lint-staged.config.mjs
export default {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{css,scss}": ["prettier --write"],
};
型チェックには関数構文が必要です (ステージングされたファイルだけでなく、すべてのファイルで実行されます)。
// lint-staged.config.mjs — 型チェックあり
export default {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{ts,tsx,js,jsx}": () => "tsc --noEmit",
};
良い点: ステージングされたファイルのみ、自動修正により手作業が軽減、高速なフィードバック
v16 の破壊的な変更: --shell フラグが削除されました (代わりにシェルスクリプトを使用してください)、Node.js 20.18 以降が必要です
複数のファイルタイプのパターンと v16 の移行の詳細については、examples/core.md を参照してください。
Pattern 3: Commitlint with Conventional Commits
commitlint v20+ は commit メッセージを検証します。ESM ネイティブ - .mjs 設定拡張子を使用します。
bun add -D @commitlint/cli @commitlint/config-conventional
# .husky/commit-msg
bunx commitlint --edit $1
// commitlint.config.mjs (Node v24 との互換性のために .mjs にする必要があります)
export default {
extends: ["@commitlint/config-conventional"],
};
形式: type(scope): description - タイプ: feat, fix, docs, refactor, test, chore など
v20 の変更と高度な設定については、examples/core.md を参照してください。
Pattern 4: CI/Production Environment Handling
hooks を実行すべきでない場所では Husky を無効にします。
# CI パイプライン
HUSKY=0 npm install
# GitHub Actions
env:
HUSKY: 0
理由: 本番環境で devDependencies がインストールされていない場合に、hook のインストールが失敗するのを防ぎます。
条件付きの prepare スクリプトの代替案については、examples/core.md を参照してください。
Pattern 5: Monorepo Setup
package.json がリポジトリのルートにない monorepos の場合。
// apps/frontend/package.json
{
"scripts": {
"prepare": "cd ../.. && husky apps/frontend/.husky"
}
}
キー: リポジトリのルートに移動し、.husky/ ディレクトリのパスを Husky に渡します。
Pattern 6: Migration from Husky v8 to v9
ステップバイステップ: prepare スクリプトを更新し、hook ファイルから shebangs/husky.sh のソースを削除します
(原文はここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Git Hooks
Quick Guide: Husky v9 for git hooks with
"prepare": "husky"(NOT"husky install"). lint-staged v16 for staged-only linting. commitlint for conventional commit messages. Pre-commit hooks should take < 10 seconds. SetHUSKY=0in CI/production.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST use "prepare": "husky" in package.json - NOT the deprecated "husky install")
(You MUST only lint staged files via lint-staged - NEVER lint the entire codebase in pre-commit)
(You MUST set HUSKY=0 in CI/production environments to disable hooks)
(You MUST use plain hook files in .husky/ directory - NO shebang lines or husky.sh sourcing in v9)
(You MUST keep pre-commit hooks under 10 seconds - move slow tasks to pre-push or CI)
</critical_requirements>
Auto-detection: Husky, husky init, .husky/, pre-commit hook, lint-staged, commitlint, conventional commits, commit-msg hook, git hooks, prepare script
When to use:
- Setting up pre-commit hooks with Husky + lint-staged
- Configuring commit message validation with commitlint
- Migrating from Husky v8 to v9
- Configuring git hooks in monorepo setups
- Disabling hooks in CI/production environments
When NOT to use:
- Linter/formatter configuration itself (separate concern)
- CI/CD pipeline configuration (separate concern)
- Runtime application code (this is developer workflow tooling only)
Key patterns covered:
- Husky v9 setup and hook creation
- lint-staged v16 configuration patterns
- commitlint with conventional commits
- CI/production hook disabling
- Monorepo setup
- Migration from Husky v8 to v9
Detailed Resources:
- examples/core.md - Setup, lint-staged config, commitlint, CI handling, monorepo, migration
- reference.md - Decision frameworks, tool comparison, anti-patterns
<philosophy>
Philosophy
Git hooks are a developer workflow tool - they catch issues early while staying fast and non-blocking. The goal is fast feedback (< 10 seconds) on staged files only. Hooks are optional infrastructure; many projects work fine without them.
When to use git hooks:
- Team projects where code quality gates prevent CI failures
- Projects with established linting/formatting that should be enforced
- When you want fast feedback before code reaches CI
- Monorepos where running full lint is too slow
When NOT to use:
- Solo projects where you always remember to lint (overhead without benefit)
- Projects without established linting/formatting rules yet (set up linting first)
- When pre-commit hooks exceed 10 seconds (move to CI instead)
- CI-only projects where hooks add friction without value
</philosophy>
<patterns>
Core Patterns
Pattern 1: Husky v9 Setup
Husky v9 uses plain shell scripts in .husky/ directory. No shebang lines needed. The prepare script auto-installs hooks for all team members.
# Full setup in 4 commands
bun add -D husky
bunx husky init # Creates .husky/ and adds "prepare": "husky" to package.json
bun add -D lint-staged
echo "bunx lint-staged" > .husky/pre-commit
Key points:
"prepare": "husky"(NOT"husky install"- deprecated, will break in v10)- Hook files are plain shell scripts (no shebang required in v9)
HUSKY=0disables hooks (CI/production);HUSKY=2enables debug mode- v9.1.1+ allows running package commands directly without npx/bunx
See examples/core.md for full setup and package.json configuration.
Pattern 2: Pre-commit Hook with lint-staged
lint-staged v16 runs commands only on staged files. Uses picomatch for glob matching (replaced micromatch).
// lint-staged.config.mjs
export default {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{css,scss}": ["prettier --write"],
};
Type checking requires function syntax (runs on ALL files, not just staged):
// lint-staged.config.mjs — with type checking
export default {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{ts,tsx,js,jsx}": () => "tsc --noEmit",
};
Why good: Only staged files, auto-fix reduces manual work, fast feedback
v16 breaking changes: --shell flag removed (use shell scripts instead), requires Node.js 20.18+
See examples/core.md for multiple file type patterns and v16 migration details.
Pattern 3: Commitlint with Conventional Commits
commitlint v20+ validates commit messages. ESM-native - use .mjs config extension.
bun add -D @commitlint/cli @commitlint/config-conventional
# .husky/commit-msg
bunx commitlint --edit $1
// commitlint.config.mjs (MUST be .mjs for Node v24 compatibility)
export default {
extends: ["@commitlint/config-conventional"],
};
Format: type(scope): description - types: feat, fix, docs, refactor, test, chore, etc.
See examples/core.md for v20 changes and advanced configuration.
Pattern 4: CI/Production Environment Handling
Disable Husky where hooks should not run.
# CI pipelines
HUSKY=0 npm install
# GitHub Actions
env:
HUSKY: 0
Why: Prevents hook installation failures when devDependencies not installed in production.
See examples/core.md for conditional prepare script alternatives.
Pattern 5: Monorepo Setup
For monorepos where package.json is not at the repository root.
// apps/frontend/package.json
{
"scripts": {
"prepare": "cd ../.. && husky apps/frontend/.husky"
}
}
Key: Navigate to repo root, then pass the .husky/ directory path to Husky.
Pattern 6: Migration from Husky v8 to v9
Step-by-step: update prepare script, remove shebangs/husky.sh sourcing from hook files, delete .husky/.gitignore, remove pinst if used.
Important: Hooks with deprecated shebang #!/usr/bin/env sh and husky.sh sourcing will fail in v10.0.0. Migrate now.
See examples/core.md for the full migration walkthrough.
</patterns>
<decision_framework>
Decision Framework
What to Run Pre-commit
What to run pre-commit?
├─ Fast (< 10 seconds)?
│ ├─ Lint with auto-fix → YES (lint-staged)
│ ├─ Format → YES (lint-staged)
│ └─ Type check (--noEmit) → YES (lint-staged)
└─ Slow (> 10 seconds)?
├─ Full test suite → NO (pre-push or CI)
├─ Full build → NO (CI)
└─ E2E tests → NO (CI)
Which Hook for Which Task
Which Git hook?
├─ Before committing? → pre-commit (lint-staged)
├─ Validating commit message? → commit-msg (commitlint)
├─ Before pushing? → pre-push (type check, unit tests)
├─ Before merging? → pre-merge-commit (v9.1.5+)
└─ After checkout/merge? → post-checkout / post-merge (install deps)
Pre-commit Timing Guidelines
| Task | Time | Pre-commit? |
|---|---|---|
| lint-staged (staged files only) | < 5s | Yes |
| Code formatting | < 2s | Yes |
| Type check (--noEmit) | < 10s | Yes |
| Full test suite | > 30s | No (CI) |
| E2E tests | > 60s | No (CI) |
| Full build | > 30s | No (CI) |
See reference.md for Husky vs alternatives comparison.
</decision_framework>
<red_flags>
RED FLAGS
High Priority Issues:
- Using deprecated
"prepare": "husky install"instead of"prepare": "husky"(will break in v10) - Running full lint on entire codebase in pre-commit hook (too slow, defeats staged-only purpose)
- Using v4-style
"husky": { "hooks": {} }config in package.json (not supported in v9) - Using
HUSKY_GIT_PARAMSenvironment variable (deprecated, use$1instead)
Medium Priority Issues:
- Pre-commit hooks taking > 10 seconds (encourages
--no-verifyabuse) - Missing
HUSKY=0in CI/production (hooks may fail when devDependencies not installed) - Using deprecated shebang
#!/usr/bin/env shand husky.sh sourcing in hook files (will fail in v10) - Using commitlint config with
.jsextension on Node v24 (use.mjsinstead)
Gotchas & Edge Cases:
git commit --no-verifybypasses hooks entirely - emergency escape hatch, not for regular use- lint-staged function syntax
() => "tsc --noEmit"runs on ALL files, not just staged - Hook file names must match Git's exact names (
pre-commit,commit-msg) - no extensions, case-sensitive HUSKY=2enables debug mode (replaces deprecatedHUSKY_DEBUG=1)- commitlint v20+ is ESM-native -
.mjsconfig extension avoids module loading issues - Windows users need to escape
$1in commit-msg hook - In monorepos,
preparescript must navigate to repo root before running husky ~/.huskyrcsupport will be removed in v10 - migrate to.config/husky/init.sh- lint-staged v16 uses
picomatch(notmicromatch) - glob patterns may differ slightly
</red_flags>
<critical_reminders>
CRITICAL REMINDERS
All code must follow project conventions in CLAUDE.md
(You MUST use "prepare": "husky" in package.json - NOT the deprecated "husky install")
(You MUST only lint staged files via lint-staged - NEVER lint the entire codebase in pre-commit)
(You MUST set HUSKY=0 in CI/production environments to disable hooks)
(You MUST use plain hook files in .husky/ directory - NO shebang lines or husky.sh sourcing in v9)
(You MUST keep pre-commit hooks under 10 seconds - move slow tasks to pre-push or CI)
Failure to follow these rules will cause slow commits, broken CI builds, and deprecated hook patterns that will fail in Husky v10.
</critical_reminders>