Skip to content

fix: skip user-level hooks gracefully when not in a git repository#293

Merged
tirth8205 merged 2 commits intotirth8205:mainfrom
EugeneChung:fix/hook-git-repo-guard
Apr 18, 2026
Merged

fix: skip user-level hooks gracefully when not in a git repository#293
tirth8205 merged 2 commits intotirth8205:mainfrom
EugeneChung:fix/hook-git-repo-guard

Conversation

@EugeneChung
Copy link
Copy Markdown
Contributor

Description

  • generate_hooks_config() now guards both PostToolUse and SessionStart hook commands with git rev-parse --git-dir check
  • Prevents noisy errors when Claude Code runs outside a git repository (e.g. home directory)

Before (error when running outside a git repo):

PostToolUse:Edit hook error
PostToolUse:Bash hook error

After: hooks are silently skipped in non-git directories.

Tested

  • TestGenerateHooksConfig tests pass (5/5)

PostToolUse and SessionStart hooks generated by `generate_hooks_config()`
now check `git rev-parse --git-dir` before running. This prevents noisy
errors when Claude Code is used outside a git repository (e.g. home dir).
@EugeneChung EugeneChung changed the title fix: skip hooks gracefully when not in a git repository fix: skip user-level hooks gracefully when not in a git repository Apr 15, 2026
The PostToolUse hook was missing a fallback, so git rev-parse exit code
128 propagated as a hook error. SessionStart already had || echo '...'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tirth8205 tirth8205 merged commit 4b2e2a0 into tirth8205:main Apr 18, 2026
1 check 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.

2 participants