Skip to content

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

Open
EugeneChung wants to merge 1 commit intotirth8205:mainfrom
EugeneChung:fix/hook-git-repo-guard
Open

fix: skip user-level hooks gracefully when not in a git repository#293
EugeneChung wants to merge 1 commit intotirth8205:mainfrom
EugeneChung:fix/hook-git-repo-guard

Conversation

@EugeneChung
Copy link
Copy Markdown

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
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.

1 participant