feature: Add git context to PreToolUse/PostToolUse hook inputs
Resolved 💬 3 comments Opened Feb 7, 2026 by shuhei0866 Closed Feb 10, 2026
Summary
PreToolUse/PostToolUse hooks currently lack git context needed for intelligent tool blocking/validation.
Problem
When implementing guardrails in hooks, we need to determine:
- Current branch name
- Whether execution is in a worktree
- Worktree root path
- Whether file is in project root vs worktree
Current workaround: Hooks must call git commands themselves, adding latency and complexity.
Proposed Solution
Add standard fields to PreToolUse/PostToolUse hook input JSON:
{
"hookInput": {
"tool_name": "Write",
"tool_input": {...},
"git": {
"branch_name": "release/my-feature",
"is_worktree": true,
"worktree_root": "/path/to/.worktrees/my-feature",
"project_root": "/path/to/repo",
"is_dirty": false,
"staged_count": 3
}
}
}
Use Cases
- WorttreeGuard: Block Write/Edit operations on main worktree (check is_worktree flag)
- MigrationGuard: Warn when creating duplicate migration numbers (check branch_name to filter context-local files)
- CommitGuard: Detect dangerous commands like
git push --force main(branch_name prevents false positives)
Data
- learning_with: 59+ wrong_approach errors from main-worktree edits
- Hook implementations need git context in 70%+ of safety rules
Benefits
- Eliminates subprocess overhead in hooks
- Enables stateless, deterministic validation
- Simpler hook scripts (no shell escaping, git call handling)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗