Git Hooks in VibeTunnel
Overview
VibeTunnel uses Git hooks exclusively for its follow mode feature. These hooks monitor repository changes and enable automatic branch synchronization across team members.Purpose
Git hooks in VibeTunnel serve a single, specific purpose:- Follow Mode: Automatically sync worktrees when team members switch branches
- Session Title Updates: Display current git operations in terminal session titles
How It Works
Hook Installation
When follow mode is enabled, VibeTunnel installs two Git hooks:post-commit
: Triggered after commitspost-checkout
: Triggered after branch checkouts
Event Flow
- Git Operation: User performs a commit or checkout
- Hook Trigger: Git executes the VibeTunnel hook
- Event Notification:
vt git event
sends repository path to VibeTunnel server - Server Processing: The
/api/git/event
endpoint:- Updates session titles (e.g.,
Terminal [checkout: feature-branch]
) - Checks follow mode configuration
- Syncs branches if follow mode is active
- Updates session titles (e.g.,
Follow Mode Synchronization
When follow mode is enabled for a branch:- VibeTunnel monitors checkouts to the followed branch
- If detected, it automatically switches your worktree to that branch
- If branches have diverged, follow mode is automatically disabled
Technical Implementation
Hook Script Content
Hook Management
- Installation:
installGitHooks()
inweb/src/server/utils/git-hooks.ts
- Safe Chaining: Existing hooks are backed up and chained
- Cleanup: Original hooks are restored when uninstalling
API Endpoints
POST /api/git/event
: Receives git event notificationsPOST /api/worktrees/follow
: Enables follow mode and installs hooksGET /api/git/follow
: Checks follow mode status
File Locations
- Hook Management:
web/src/server/utils/git-hooks.ts
- Event Handler:
web/src/server/routes/git.ts
(lines 189-481) - Follow Mode:
web/src/server/routes/worktrees.ts
(lines 580-630) - CLI Integration:
web/bin/vt
(git event command)
Configuration
Follow mode stores configuration in git config:Security Considerations
- Hooks run with minimal permissions
- Commands execute in background to avoid blocking Git
- Existing hooks are preserved and chained safely
- Hooks are repository-specific, not global
Troubleshooting
Hooks Not Working
- Verify
vt
command is in PATH - Check hook permissions:
ls -la .git/hooks/post-*
- Ensure hooks are executable:
chmod +x .git/hooks/post-*
Follow Mode Issues
- Check configuration:
git config vibetunnel.followBranch
- Verify hooks installed:
cat .git/hooks/post-checkout
- Review server logs for git event processing
Summary
Git hooks in VibeTunnel are:- Single-purpose: Only used for follow mode functionality
- Optional: Not required unless using follow mode
- Safe: Preserve existing hooks and run non-blocking
- Automatic: Managed by VibeTunnel when enabling/disabling follow mode