Token导航 LogoToken导航

Agent Skill · 运维和基础设施

git-hooks(git 钩子)

git-hooks 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

git-hooks 是运维和基础设施类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为只读;许可证为 MIT,暂无第三方扫描结果,按安装量在运维和基础设施类的 2,449 个 Skill 里排第 2,146。

总安装 267周安装 11GitHub Stars 38下载 87核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:git-hooks(git 钩子)
来源仓库:https://github.com/bitsoex/bitso-java
仓库路径:skills/git-hooks
安装命令:
npx skills add https://github.com/bitsoex/bitso-java --skill git-hooks
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/bitsoex/bitso-java --skill git-hooks

这个 Skill 是做什么的

运维和基础设施类 Skill 处理部署、监控、日志和云资源,多数需要较高的执行权限。

git-hooks 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。通过 npx skills add 命令从指定 GitHub 仓库安装使用。

安装前需确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写操作。git-hooks 属于运维和基础设施类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/git-hooks

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/bitsoex/bitso-java --skill git-hooks;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它标注为只读,先用只读任务试一次,确认行为符合预期再扩大使用范围。

常见问题

6 条

git-hooks 怎么安装?

在终端执行 npx skills add https://github.com/bitsoex/bitso-java --skill git-hooks。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

git-hooks 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

git-hooks 需要什么权限?

权限级别是只读。该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

git-hooks 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

git-hooks 用的人多吗?

公开数据是累计安装 267 次,近一周安装 11 次,下载 87 次,GitHub 38 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

git-hooks 安全吗?

没有查到第三方扫描结果,安全性无法从公开资料判断,安装前请自行审查源码、依赖和命令行为。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 标注为只读权限,试用阶段不容易误改本地文件。

先想清楚的地方

  • 没有第三方扫描结果,安全性只能靠自己读源码判断。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理运维和基础设施类任务、又不想每次都手写提示词的人。
  • 只想先试试效果、不希望它改动本地文件的人。

不太适合

  • 要求有安全扫描结论才肯安装的团队。
  • 需要厂商级技术支持和 SLA 的生产系统。

运维和基础设施类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
brainstorming

头脑风暴 · Codex、Claude

3,148,776173,131操作浏览器MIT通过
copywriting

文案写作 · Codex、Claude

1,996,72425,583需要联网MIT通过
openclaw-secure-linux-cloud

OpenClaw secure linux cloud 命令行 · Codex、Claude

1,853,08840接触敏感数据未明确未通过
xget

xget 命令行 · Codex、Claude

1,799,28040执行命令未明确未通过
requesting-code-review

代码审查请求 · Codex、Claude

1,590,144173,103权限未标注MIT通过
git-hooks

git 钩子 · 本页

26738只读MIT未收录

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Git Hooks

This skill provides guidance for implementing and maintaining Git hooks that enforce code quality standards before commits and pushes reach the repository.

When to use this skill

  • Setting up Git hooks in a new repository
  • Creating new pre-commit or pre-push hooks
  • Debugging hook installation or execution issues
  • Ensuring hooks follow team standards
  • Migrating from manual hooks to version-controlled hooks
  • Integrating with existing hook systems (Husky, pre-commit, lefthook)

Skill Contents

Sections

Available Resources

📚 references/ - Detailed documentation

📦 assets/ - Templates and resources


Distributed Hooks (Informative Mode)

For repositories receiving distributed AI rules, we provide informative hooks that:

  • Never block commits or pushes (always exit 0)
  • Warn about issues with clear fix commands
  • Auto-detect Node.js via nvm, fnm, or system PATH (shows setup instructions if not found)
  • Coexist with existing hook setups (Husky, pre-commit, lefthook)

How It Works

# Source location: global/skills/git-hooks/assets/
# Deployed to target repo as:

.git-hooks/
├── pre-commit          → Delegates to hooks-bootstrap.sh (same directory)
├── pre-push            → Delegates to hooks-bootstrap.sh (same directory)
├── ensure-node.sh      → Ensures Node.js 20+ is available
├── hooks-bootstrap.sh  → Entry point, loads Node, runs checks
└── hooks-checks.js     → Multi-language quality checks

Enabling Distributed Hooks

# Set Git to use our hooks directory
git config core.hooksPath .git-hooks

# Verify
git config --get core.hooksPath
# Should output: .git-hooks

Output Example

============================================================
  Bitso Quality Checks (Informative)
============================================================

  Pre-commit checks found some issues:

  [!] Linting: ESLint errors detected
      Run: mise run lint:fix

  [!] TypeScript: Type errors detected
      Run: npx tsc --noEmit

  These are recommendations. Your commit will proceed.
  For AI agents: Please address these issues before completing.

============================================================

Coexistence with Existing Hooks

See assets/hooks-bridge-strategy.md for detailed integration patterns with:

  • Husky: Add our checks to .husky/pre-commit
  • pre-commit (Python): Add as a local hook in .pre-commit-config.yaml
  • lefthook: Add to lefthook.yml commands

Assets

AssetPurpose
assets/ensure-node.shNode.js detection and auto-installation
assets/hooks-bootstrap.shHook entry point (ensures Node, runs checks)
assets/hooks-checks.jsMulti-language quality checks
assets/pre-commitPre-commit hook entry point
assets/pre-pushPre-push hook entry point
assets/hooks-bridge-strategy.mdIntegration patterns for existing setups

Architecture

Recommended Directory Structure

project/
├── .git-hooks/              # Version-controlled hooks directory
│   ├── pre-commit           # Symlink → ../.scripts/pre-commit-hook.sh
│   └── pre-push             # Symlink → ../.scripts/pre-push-hook.sh
├── .scripts/
│   ├── setup-hooks.ts       # Hook installation script (runs on npm install)
│   ├── pre-commit-hook.sh   # Pre-commit hook implementation
│   ├── pre-push-hook.sh     # Pre-push hook implementation
│   └── lib/skills/          # Skill modules for hook operations
└── package.json             # Contains "prepare": "node .scripts/setup-hooks.ts"

Why This Architecture?

  1. Version-controlled: Hooks live in .git-hooks/, tracked by Git
  2. Automatic installation: npm install configures hooks via prepare script
  3. Team consistency: Everyone gets the same hooks automatically
  4. Implementation separation: Actual logic in .scripts/, symlinks in .git-hooks/
  5. Skippable in CI: Setup script detects CI environment and skips

Instructions

Step 1: Create the Hooks Directory

mkdir -p .git-hooks

Step 2: Create the Setup Script

Create .scripts/setup-hooks.ts:

#!/usr/bin/env node
/**
 * Setup Git Hooks
 *
 * Runs on `npm install` via the "prepare" script.
 * Configures git to use .git-hooks/ for hooks.
 */

import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

if (process.env.CI || process.env.SKIP_HOOKS) {
  console.log('⏭️  Skipping hook setup (CI or SKIP_HOOKS=true)');
  process.exit(0);
}

const ROOT_DIR = path.join(__dirname, '..');
const HOOKS_DIR = '.git-hooks';

function setupHooks() {
  if (!fs.existsSync(path.join(ROOT_DIR, '.git'))) {
    console.log('⚠️  Not a git repository, skipping hook setup');
    return;
  }

  const githooksPath = path.join(ROOT_DIR, HOOKS_DIR);
  if (!fs.existsSync(githooksPath)) {
    console.error(`❌ Hooks directory not found: ${HOOKS_DIR}`);
    process.exit(1);
  }

  // Set core.hooksPath
  try {
    execSync(`git config core.hooksPath ${HOOKS_DIR}`, { cwd: ROOT_DIR });
    console.log(`✅ Git hooks configured: core.hooksPath → ${HOOKS_DIR}`);
  } catch (error) {
    const err = error as Error;
    console.error('❌ Failed to set core.hooksPath:', err.message);
    process.exit(1);
  }
}

setupHooks();

Step 3: Configure package.json

Add the prepare script to automatically set up hooks on install:

{
  "scripts": {
    "prepare": "node .scripts/setup-hooks.ts"
  }
}

Step 4: Create Hook Implementation

Create hook scripts in .scripts/ following the template in the References section.

Step 5: Create Symlinks

Create symlinks in .git-hooks/ pointing to the implementation:

cd .git-hooks
ln -sf ../.scripts/pre-commit-hook.sh pre-commit
ln -sf ../.scripts/pre-push-hook.sh pre-push
chmod +x pre-commit pre-push

Step 6: Validate Hook Setup

# Run validation
npm run skills:hooks

# Or use CLI directly
node .scripts/skills-cli.ts git-hooks validate

Hook Types

HookWhen It RunsTypical Checks
pre-commitBefore commit is createdLinting, formatting, tests, validation
pre-pushBefore push to remoteFull test suite, coverage, build verification
commit-msgAfter commit message writtenMessage format validation
prepare-commit-msgBefore editor opensTemplate insertion
post-checkoutAfter checkout completesDependency updates, cache clearing
post-mergeAfter merge completesDependency updates

Best Practices

1. Exit Codes Matter

# Exit 0 = success, commit/push proceeds
# Exit non-zero = failure, operation aborted
if ! npm test; then
  echo "Tests failed"
  exit 1
fi

2. Provide Clear Feedback

# Use colors and emojis for visibility
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo -e "${YELLOW}🔍 Running tests...${NC}"
if npm test --silent; then
  echo -e "${GREEN}   ✓ Tests passed${NC}"
else
  echo -e "${RED}   ✗ Tests failed${NC}"
  exit 1
fi

3. Keep Hooks Fast

Pre-commit hooks should complete in seconds, not minutes:

  • Run only essential checks
  • Use incremental/cached operations where possible
  • Move heavy checks to pre-push

4. Allow Emergency Bypass

# Document how to skip in emergencies
git commit --no-verify  # Skip pre-commit
git push --no-verify    # Skip pre-push

5. Fail Early, Fail Fast

Order checks from fastest to slowest:

# 1. Fast checks first
echo "Checking for debug statements..."
if grep -r "console.log" src/; then
  echo "Remove debug statements before committing"
  exit 1
fi

# 2. Medium checks
echo "Running linter..."
npm run lint

# 3. Slow checks last
echo "Running tests..."
npm test

6. Handle Auto-Fixes

If a hook auto-fixes files, stage them:

if git diff --name-only | grep -q "formatted-file.js"; then
  git add formatted-file.js
  echo "Auto-formatted file added to commit"
fi

7. Never Add Coverage Exclusions as First Approach

IMPORTANT: When pre-push hooks fail due to coverage thresholds, the correct approach is:

  1. Add tests to increase coverage (preferred)
  2. Use --no-verify as a temporary emergency bypass if absolutely necessary
  3. Never add exclusions to .c8rc.json, .nycrc, or coverage config

Why?

  • Exclusions hide untested code and accumulate over time
  • They defeat the purpose of coverage thresholds
  • They make it harder to identify actual coverage gaps

Correct approach when coverage fails:

# 1. Run coverage report to identify gaps
npm run test:coverage:report

# 2. Add tests for uncovered lines
# ... write tests ...

# 3. Verify coverage now passes
npm run test:coverage

# 4. Commit and push normally
git push

Emergency bypass (use sparingly):

# Only when you MUST push immediately and will add tests in follow-up
git push --no-verify

# Document why in commit message or PR
# Create a ticket to add missing tests

Never do this:

// ❌ DON'T add exclusions to avoid writing tests
{
  "exclude": [
    ".scripts/new-module.ts"  // ❌ WRONG - write tests instead
  ]
}

Hook Modes

Git hooks support a unified mode system controlled via environment variables.

Mode Values

ModeDescription
skipCompletely skip the hook - no execution, no output
infoShow informational messages only; do NOT execute scripts
warnExecute scripts, show results, but never fail (always exit 0)
fullExecute scripts and fail when the script results in a failure (default)

Environment Variables

VariableDescription
BITSO_MISE_MODEGlobal mode for all hooks
BITSO_MISE_GIT_HOOKSCategory-level mode for all git hooks
BITSO_MISE_GIT_HOOKS_COMMITHook-specific mode for pre-commit
BITSO_MISE_GIT_HOOKS_PUSHHook-specific mode for pre-push
BITSO_MISE_GIT_HOOKS_CIHook-specific mode for CI validation

Resolution Order

  1. Hook-specific env var (e.g., BITSO_MISE_GIT_HOOKS_COMMIT)
  2. Category env var (BITSO_MISE_GIT_HOOKS)
  3. Global env var (BITSO_MISE_MODE)
  4. Default: full

Example Configuration

In mise.local.toml:

[env]
# Run git hooks but don't fail locally
BITSO_MISE_GIT_HOOKS = "warn"

# Or: Fine-grained control
BITSO_MISE_GIT_HOOKS_COMMIT = "warn"  # Don't block commits
BITSO_MISE_GIT_HOOKS_PUSH = "full"    # But enforce on push

References

Technology-specific hook patterns are available in the references/ folder:

TechnologyReference
Javareferences/java/hook-patterns.md
TypeScript/JavaScriptreferences/typescript/hook-patterns.md
Pythonreferences/python/hook-patterns.md
Goreferences/go/hook-patterns.md

Documentation

For comprehensive documentation in the repository's docs/ directory, see:

  • docs/ai-ide-management/concepts/git-hooks-architecture.md - System design and flow diagrams
  • docs/ai-ide-management/how-tos/enable-git-hooks.md - Setup and troubleshooting
  • docs/ai-ide-management/concepts/conflict-detection.md - How conflicts are detected during distribution

Related Skills

SkillPurpose
agent-hooksAI IDE hooks (Claude Code, Cursor) with enforcing mode
quality-checksQuality gate orchestration
coding-standardsCode style enforcement

hk (ai-code-instructions only)

Note: This section is specific to the ai-code-instructions repository which uses hk as its git hook manager.

hk provides:

  • Parallel execution: Runs multiple linters simultaneously
  • Smart stashing: Safely stashes unstaged changes during hooks
  • Progress reporting: Clear visual feedback during hook execution
  • Profile-based configuration: Enable/disable checks via profiles

Configuration

hk is configured via hk.pkl in the repository root:

hooks {
  ["pre-commit"] {
    stash = "git"
    steps {
      ["eslint-staged"] = new Step { check = "node mise-tasks/check.ts eslint-staged" }
      ["tests-changed"] = new Step { check = "node mise-tasks/check.ts tests-changed" }
    }
  }
}

Common Commands

# Run hooks manually
hk run pre-commit     # Run pre-commit checks
hk run pre-push       # Run pre-push checks
hk run ci             # Run CI checks

# Check and fix
hk check              # Run all checks (read-only)
hk check --pr         # Check only files changed in current PR/branch
hk fix                # Auto-fix where possible
hk fix --pr           # Fix only files changed in current PR/branch

# Test step definitions
hk test               # Run step-defined tests

# Validate configuration
hk validate           # Validate hk.pkl

# Skip hooks
git commit --no-verify                    # Standard git bypass
HK_SKIP_HOOKS=pre-commit git commit       # Skip specific hook

Installation

# Install via Homebrew
brew install hk

# Download pkl packages (required for SSL cert compatibility)
pkl download-package --ca-certificates=/path/to/ca.pem \
  package://github.com/jdx/hk/releases/download/v1.36.0/hk@1.36.0

# Install hooks
hk install

Troubleshooting

Hooks not running

  1. Verify hooks are installed: git config --get core.hooksPath # Should output:.git-hooks
  2. Check symlinks are valid: ls -la.git-hooks/ # Should show symlinks pointing to.scripts/*-hook.sh
  3. Verify execute permissions: chmod +x.git-hooks/* chmod +x.scripts/*-hook.sh

Hooks running but failing

  1. Run hooks manually to see full output: ./.scripts/pre-commit-hook.sh
  2. Check for missing dependencies: npm install
  3. Run with DEBUG mode: DEBUG=1./.scripts/pre-commit-hook.sh

Hooks too slow

  1. Profile each check: time npm run lint time npm test
  2. Move slow checks to pre-push
  3. Use incremental/cached operations
  4. Consider staged-files-only validation

Different behavior locally vs CI

  1. CI should skip hooks (set CI=true)
  2. CI runs validations directly, not via hooks
  3. Ensure setup-hooks.ts checks for CI environment

平台分布

Claude Code

30.08%
按下载量换算26

windsurf

20.95%
按下载量换算18

Antigravity

16.19%
按下载量换算14

OpenCode

11.61%
按下载量换算10

Gemini CLI

7.78%
按下载量换算7

Codex

3.49%
按下载量换算3

安全审计

暂无安全审计结果可展示。

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills