Repository navigation
Description
Problem
scripts/dev-init.sh installs the project's pre-commit hook by symlinking the shared git hooks entry to the checkout's copy of scripts/pre-commit. When run inside a linked git worktree (e.g. the .claude/worktrees/agent-* worktrees Claude Code creates), it re-points the shared hook at the worktree's transient copy of the script. When that worktree is later removed, the symlink dangles and git silently skips the pre-commit hook for all subsequent commits in the main checkout -- with no warning. This defeats the project's "lean on the pre-commit hook" workflow.
This actually happened during an LTM review session: a commit on main bypassed fmt/clippy/tests because five agent worktrees had each run dev-init.sh.
Observed dangling state:
.git/hooks/pre-commit -> /home/bpowers/src/simlin2/.claude/worktrees/agent-ae83caaeb128b9a49/scripts/pre-commit
Root cause
In scripts/dev-init.sh:
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
...
# 1. Git hooks
if HOOK_PATH="$(git rev-parse --git-path hooks/pre-commit 2>/dev/null)"; then
DESIRED="$REPO_ROOT/scripts/pre-commit"
if ! { [ -L "$HOOK_PATH" ] && [ "$(readlink "$HOOK_PATH")" = "$DESIRED" ]; }; then
mkdir -p "$(dirname "$HOOK_PATH")"
rm -f "$HOOK_PATH"
ln -s "$DESIRED" "$HOOK_PATH"
fi
fiThe two sides of the symlink resolve to different repositories when run inside a linked worktree:
REPO_ROOTresolves to the worktree's checkout (the directory containing this copy ofdev-init.sh), soDESIREDpoints at<worktree>/scripts/pre-commit.git rev-parse --git-path hooks/pre-commitresolves to the shared common.git/hooks/pre-commit-- linked worktrees share the main repo's hooks directory (core.hooksPathresolves to the main.git/hooks).
So the script installs <main>/.git/hooks/pre-commit -> <worktree>/scripts/pre-commit. The worktree is transient; once git worktree remove deletes it, the symlink target no longer exists. git treats a non-executable / missing hook as "no hook" and commits silently succeed without running it.
Why it matters
- Correctness / CI gate bypass: commits on
mainskip Rust fmt, clippy, the test suite, TS lint/typecheck, the WASM build, and the Python bindings tests -- exactly the gateCLAUDE.mdinstructs everyone to lean on. The failure is silent: no error, no warning. - Multi-agent amplification: the project's documented workflow spawns multiple worktrees that each run
dev-init.shat session start, so the shared hook is repeatedly clobbered and the dangling state is the steady state after worktrees are cleaned up.
Component(s) affected
scripts/dev-init.sh(hook installation, section "1. Git hooks")- Indirectly: the entire pre-commit gate (
scripts/pre-commit) and any commit made in the main checkout after worktrees are torn down.
Possible approaches
- Skip hook installation in linked worktrees. Detect a linked worktree and do nothing: when
git rev-parse --git-dir!=git rev-parse --git-common-dir, the current checkout is a linked worktree -- leave the shared hook alone. - Resolve
DESIREDagainst the MAIN repository root. Point the shared symlink at the main checkout'sscripts/pre-commit(e.g. the parent ofgit rev-parse --git-common-dir) rather thanREPO_ROOT, so the target survives worktree removal. - Install a relative symlink or a tiny wrapper that always resolves
scripts/pre-commitagainst the checkout being committed (the worktree's own working tree), so the hook is correct no matter which checkout commits. This is the most robust: each commit runs the script from the tree it is committing.
Option 1 is the smallest safe fix; option 3 is the most correct. Worth a guard regardless: if the existing hook symlink is dangling, repair it.
How it was discovered
Identified during an LTM review session after a main commit was observed to bypass the pre-commit gate; traced to five agent worktrees having each run dev-init.sh and left the shared .git/hooks/pre-commit pointing at a since-removed worktree.
Activity
build: resolve pre-commit hook target against the main checkout
bpowers commentedon Jun 8, 2026
Fixed by 26a641e (PR #705): scripts/dev-init.sh now resolves the hook symlink target against the MAIN checkout (the parent of
git rev-parse --git-common-dir) rather than the running worktree's REPO_ROOT, and only installs when that target exists -- so running dev-init in a transient linked worktree can no longer re-point the shared.git/hooks/pre-commitat a path that dangles aftergit worktree remove. The hook-installation block's comment cites this issue. Verified at HEAD:.git/hooks/pre-commitresolves to the main checkout's scripts/pre-commit and the symlink survives worktree removal by construction.