Skip to content

fix: don't write an install-time lefthook path into AI hook configs - #1544

Merged
mrexox merged 2 commits into
evilmartians:masterfrom
anandghegde:fix/ai-hooks-portable-command
Oct 7, 2026
Merged

mrexox merged 2 commits into
evilmartians:masterfrom
anandghegde:fix/ai-hooks-portable-command

Conversation

@anandghegde

@anandghegde anandghegde commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1482

Context

lefthook install with an ai: section writes the result of os.Executable() into the generated hook commands. With the npm package that ends up as something like /Users/me/project/node_modules/.pnpm/lefthook-darwin-arm64@2.1.10/.../bin/lefthook run validate in .claude/settings.json. That file is normally committed, so the command only works for whoever ran install, and breaks on other machines, on CI and after upgrades.

Changes

  • When the lefthook config option is set it is still used as is.
  • Otherwise the generated command is plain lefthook (per review). Projects that run lefthook from a package manager can set lefthook: npx lefthook / pnpm exec lefthook.
  • Paths are no longer embedded, so the shell-quoting helper is gone.
  • Entries written by earlier versions still contain lefthook run , so re-running install replaces them. Added a test for that.
  • Updated the note in docs/configuration/ai.md.

This is the AI-hook counterpart of #1398. #1526 (open) removes the os.Executable() branch from the git hook shim; this PR touches different files and doesn't depend on it.

Verified:

  • go test ./... passes, golangci-lint run reports no new issues.
  • Before the change, a binary under node_modules/lefthook-darwin-arm64/bin/ wrote its absolute path; now it writes lefthook run validate, and lefthook: pnpm exec lefthook still produces pnpm exec lefthook run validate.

@anandghegde
anandghegde requested a review from mrexox as a code owner September 14, 2026 07:39
@greptile-apps

greptile-apps Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge with no outstanding correctness or repository-rule issues.

No new changes were made after the previous review, and the sole previous finding was resolved after Greptile accepted anandghegde’s explanation and withdrew it.

Reviews (3): Last reviewed commit: "fix: use plain lefthook in generated AI ..." | Re-trigger Greptile

Comment thread internal/command/install_ai.go Outdated
// lives under node_modules, which is not on PATH, so it is called via npx.
func portableLefthookBin(exe string) string {
if slices.Contains(strings.Split(filepath.ToSlash(exe), "/"), "node_modules") {
return npxLefthookBin

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should be better just to rely on globally installed lefthook, rather than npx. I guess some users may want to use the lefthook binary from their repo, some will use pnpm for managing packages, and npx will download the lefthook for them.
What do you thin about having just lefthook here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, switched to plain lefthook in 0d70824. The npx guess was too narrow anyway (pnpm/yarn/bun users), and anyone running lefthook from a package manager can already set lefthook: pnpm exec lefthook etc., which is still used as is. Docs and the PR description are updated to match.

Comment thread internal/command/install_ai.go Resolved
@anandghegde
anandghegde force-pushed the fix/ai-hooks-portable-command branch from 0d70824 to bf7d731 Compare September 15, 2026 16:38
@anandghegde
anandghegde force-pushed the fix/ai-hooks-portable-command branch from bf7d731 to 7a2229a Compare October 5, 2026 11:42
The generated AI hook settings (e.g. .claude/settings.json) are usually
committed, but the command embedded the absolute path of the binary that
ran install, which includes the home dir, OS/arch and version.

Use `npx lefthook` when the running binary comes from node_modules and
plain `lefthook` otherwise. The `lefthook` config option still wins.
@mrexox
mrexox force-pushed the fix/ai-hooks-portable-command branch from 7a2229a to 1e9d419 Compare October 7, 2026 18:56
@mrexox

mrexox commented Oct 7, 2026

Copy link
Copy Markdown
Member

Thank you for bringing this change!

@mrexox
mrexox merged commit 37f1713 into evilmartians:master Oct 7, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai hooks write an absolute binary path into committed .claude/settings.json

2 participants