Initialize Lefthook
Set up lefthook with standard pre-commit checks for this project.
Steps
-
Detect environment:
- Package manager from lock file (bun.lock/pnpm-lock.yaml/package-lock.json)
- Nix project: check for
flake.nix(if yes, ask if hooks should usenix develop -c) - Beads: check for
.beads/directory
-
Install lefthook:
[bun/pnpm/npm] add -D lefthook -
Create
lefthook.yml:Standard (with beads):
pre-commit: commands: beads-sync: run: | if command -v bd >/dev/null 2>&1 && [ -d .beads ]; then bd sync --flush-only >/dev/null 2>&1 || echo "Warning: bd sync failed" git add .beads/issues.jsonl 2>/dev/null || true fi priority: 1 format-fix: glob: "*.{ts,tsx,mjs,js,jsx}" run: bunx oxfmt {staged_files} stage_fixed: true priority: 2 lint-fix: glob: "*.{ts,tsx,mjs,js,jsx}" run: bunx oxlint --fix {staged_files} stage_fixed: true priority: 3 typecheck: run: bun run typecheck priority: 4 test: run: bun run test priority: 4 post-merge: commands: beads-prime: run: | if command -v bd >/dev/null 2>&1 && [ -d .beads ]; then bd prime >/dev/null 2>&1 || true fi install-deps: run: bun installWithout beads: Omit beads-sync, beads-prime commands.
With nix develop: Prefix commands with
nix develop -cornix develop --command:run: nix develop -c bunx oxfmt {staged_files}run: nix develop -c bun run typecheck
-
Run lefthook install:
[bunx/npx/pnpm] lefthook install -
Add to .gitignore (if not present):
.lefthook-local.yml -
Summary: List created files and note that hooks are active.
Notes
- If project doesn't have
typecheckortestscripts, omit those hooks - Ask for confirmation before creating lefthook.yml if one already exists