Feature: Add git context fields to hook input (branch_name, is_worktree, worktree_root)
Status Fixed / completed
Maintainer reply None cached
Workaround ✓ Mentioned in description ↑
Activity 3 comments · opened Feb 7, 2026 · closed Feb 7, 2026
Summary
Add git context (branch name, worktree information) as standard fields in hook input JSON.
Background
Many guardrail hooks (PreToolUse, Stop, etc.) make decisions based on the current branch and worktree state. However, the current hook input does not include this information, requiring hooks to execute git commands internally.
Current Workaround
# Execute git commands in every hook
BRANCH=$(git branch --show-current 2>/dev/null)
GIT_COMMON_DIR=$(git rev-parse --git-common-dir 2>/dev/null)
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
IS_WORKTREE=$( [ "$GIT_DIR" != "$GIT_COMMON_DIR" ] && echo "true" || echo "false" )
Proposal
Add the following fields to hook input:
{
"tool_name": "Write",
"tool_input": { "file_path": "..." },
"git_context": {
"branch_name": "release/my-feature",
"is_worktree": true,
"worktree_root": "/path/to/.worktrees/my-feature",
"main_worktree_root": "/path/to/project",
"has_uncommitted_changes": true
}
}
Benefits
- Dramatically simplifies hook implementation
- Eliminates git command execution overhead
- Provides branch information even in environments where git is unavailable
- Unifies git context retrieval across all hooks
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗