用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/laicluse/agent-fieldkit --skill install-hooks命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | install-hooks |
| description | Install git-discipline git hooks in the current repo so CLI/IDE commits get the same guardrails. |
Place git-discipline's git-native hooks into the current repo, so commits and pushes made outside Claude Code's PreToolUse layer are also guarded. In Codex, these git-native hooks are the enforcement layer.
The hooks:
| Hook | Purpose |
|---|---|
pre-commit | When local laicluse.requireWorktree=true, blocks ordinary commits in the primary checkout and on the dynamically resolved default branch. Without that opt-in, canonical-checkout authoring remains available. |
commit-msg | Validates the commit message against validate-body.sh (the same lib as the PreToolUse guard). |
prepare-commit-msg | Pre-fills the editor window with a structured body template based on the staged diff. |
post-commit | Detects --no-verify usage and logs it to ${LAICLUSE_HOME:-~/.laicluse}/git-discipline/git-discipline-no-verify.log. |
post-rewrite | Runs after git rebase and git commit --amend and validates each rewritten body. git ignores its exit status, so it warns and logs to ${LAICLUSE_HOME:-~/.laicluse}/git-discipline/git-discipline-post-rewrite.log rather than blocking; pre-push is the blocking gate for these commits. It exists because commit-msg does not fire on rebase-picked commits. |
pre-push | Blocks wip or invalid commit bodies and rejects a default update unless it is the verified two-parent merge produced by the shared git-discipline flow. |
The PreToolUse:Bash guard (slice 4) only covers Claude-driven commits.
Commits made directly via git commit from the shell or from an IDE
do not see this guard. Claude Code does not offer a native
PreCommit lifecycle event and will not get one
(https://github.com/anthropics/claude-code/issues/4834 closed not planned),
so the per-repo git-native hooks are the only way to cover non-Claude commits
and pushes.
All hooks share the same validate-body.sh as the PreToolUse guard, so
behavior never diverges.
git rev-parse --git-dir).core.hooksPath, and picks the correct target directory (the common Git directory's hooks/, shared by every linked worktree, or that repo-local path). An inherited global core.hooksPath is never an install target; the installer creates a repo-local override instead of modifying hooks used by unrelated repositories.lib/install.sh script's own location and
bakes that absolute path into each hook (placeholder
__PLUGIN_INSTALL_PATH__ is replaced). Re-running after a plugin update or
reinstall refreshes the path.pre-commit, commit-msg, prepare-commit-msg, post-commit,
pre-push), copies the source from the plugin to the target dir, sets
the executable bit, and logs the result.--force: makes a backup for each conflicting hook
(<hook>.bak.<timestamp>) and then overwrites.--dry-run: shows what would happen without writing anything.Installing git-discipline does not make worktrees mandatory. The canonical checkout and current branch remain the normal authoring location. Use a linked worktree when isolation solves a concrete risk: the canonical checkout is live or consumed by another system, Dibs reports another coding agent there, the change is consequential enough to deserve an isolated candidate, or another concurrency or recovery concern makes shared authoring unsafe. This list is illustrative, not exhaustive.
Repositories that should always use the verified candidate flow can opt in locally:
git config --local laicluse.requireWorktree true
Only that local setting activates the native pre-commit authoring block and default-branch topology check in pre-push. A global setting is deliberately ignored.
/git-discipline:install-hooks
/git-discipline:install-hooks --dry-run
/git-discipline:install-hooks --force
The skill runs lib/install.sh from this skill directory. The script detects
the plugin root from its own path and needs no further arguments.
--force: skill prints a
unified diff (diff -u), refuses to overwrite, and exits 1.--no-verify on git commit is the audit-logged emergency bypass for the
git-native hooks this skill installs; the installed post-commit logs that
usage to
${LAICLUSE_HOME:-~/.laicluse}/git-discipline/git-discipline-no-verify.log so it is reviewable after the fact.Note: inside a Claude session --no-verify does not bypass the
PreToolUse guards; see the --no-verify section of
/git-discipline:commit-discipline for the layer split and the
operator-only off-switch.
git-discipline:install-hooks
hooks dir : .git/hooks (default)
plugin path : /path/to/git-discipline
installed : pre-commit
installed : commit-msg
installed : prepare-commit-msg
installed : post-commit
installed : pre-push
skipped : (none)
backups : (none)
done.
With a conflict without --force:
git-discipline:install-hooks
hooks dir : .git/hooks
WARN: .git/hooks/commit-msg already exists with different content.
--- existing
+++ new
@@ -1,3 +1,5 @@
...
Refusing to overwrite. Re-run with --force to backup-and-replace.
exit 1
After every plugin update or reinstall, the baked plugin path in the installed hooks may be stale. Run in every repo where the hooks are active:
/git-discipline:install-hooks --force
This replaces the existing hooks (with automatic backup) and bakes in the new path. Without this step the hooks will try to source the old plugin path on the next commit, which can fail if the cache directory has been cleaned up.