Overview
Repo Manager provides hooks that execute after key operations. These hooks allow you to customize behavior like opening editors, switching tmux windows, or running project-specific setup.Available Hooks
All hooks are defined in functions/hooks.zsh with default implementations:post_repo_clone
Executed after cloning a repository with repo get.
Default behavior:
$1- Path to the created worktree (e.g.,~/repos/github.com/user/repo/main)
- After
repo get <url>successfully clones and creates initial worktree (functions/clone.zsh:55) - After
repo converttransforms a standard repository (functions/convert.zsh:83)
post_repo_goto
Executed after navigating to a repository with repo goto.
Default behavior:
$1- Path to the worktree (e.g.,~/repos/github.com/user/repo/main)
- After
repo goto <repo>resolves target worktree (functions/goto.zsh:36, 44, 50, 53) - If multiple worktrees exist and
fzfis installed, runs after user selects from picker
post_repo_new
Executed after creating a new repository with repo new.
Default behavior:
$1- Path to the created repository directory
- After
repo new <name>creates a new repository
post_wt_add
Executed after creating a worktree with repo wt add.
Default behavior:
$1- Path to the created worktree (e.g.,~/repos/github.com/user/repo/feature-auth)
- After
repo wt add <branch>creates a new worktree (functions/worktree.zsh:58) - After
repo wt pr <number>creates a worktree from a PR (functions/worktree.zsh:175) - If worktree already exists, still runs (functions/worktree.zsh:35, 158)
post_wt_go
Executed after switching to a worktree with repo wt go.
Default behavior:
$1- Path to the target worktree
- After
repo wt go <branch>validates the worktree exists (functions/worktree.zsh:119)
post_wt_rm
Executed after removing a worktree with repo wt rm.
Default behavior:
$1- Path to the removed worktree
- After
repo wt rm <branch>successfully removes a worktree (functions/worktree.zsh:97) - Not called by
repo wt clean(which removes multiple worktrees)
Overriding Hooks
Override hooks by redefining them in your.zshrc after loading the plugin:
Real-World Examples
Opening Editor Automatically
Tmux Integration
Create tmux windows for each worktree:Running Project Setup
Automatically install dependencies in new worktrees:Notification on Completion
Send desktop notification when clone completes:Combining Multiple Actions
Conditional Behavior
Different behavior based on repository:Hook Execution Order
Understanding when hooks fire:Clone Workflow
- Clone bare repository to
.bare/ - Create initial worktree (e.g.,
main/) - post_repo_clone fires with path to
main/
Add Worktree Workflow
- Fetch from origin
- Create worktree at
feature-auth/ - Set upstream tracking
- post_wt_add fires with path to
feature-auth/
PR Workflow
- Query GitHub for PR branch name
- Fetch PR ref
- Create worktree
- post_wt_add fires (not a separate hook)
Navigate Workflow
- Validate worktree exists
- post_wt_go fires with path to
main/
Remove Workflow
- Validate not default branch
- Remove worktree
- post_wt_rm fires with path that was removed
Best Practices
Keep Hooks Fast
Hooks run synchronously - slow operations block the command:Handle Errors Gracefully
Use Helper Functions
Repo Manager provides utility functions you can use in hooks:resolve_repo_root()- Find repository root from current directorydetect_default_branch(bare_dir)- Get default branch nameis_worktree_repo(dir)- Check if directory uses worktree layoutclean_repo_path(url)- Normalize repository URLs