Hooks
Hooks allow you to run commands automatically during the worktree lifecycle.
Available Hooks
Section titled “Available Hooks”| Hook | When | Working Directory |
|---|---|---|
pre_start | Before worktree creation | Origin repository |
post_start | After worktree creation | New worktree |
pre_clean | Before worktree removal | Current worktree |
post_clean | After worktree removal | Main repository |
Configuration
Section titled “Configuration”[hooks]pre_start = ["echo 'Preparing worktree...'"]post_start = [ "pnpm install", "pnpm db:migrate"]pre_clean = ["git stash"]post_clean = ["echo 'Cleanup complete'"]Environment Variables
Section titled “Environment Variables”The following environment variables are available in all hook commands:
| Variable | Description |
|---|---|
VIBE_WORKTREE_PATH | Absolute path to the created worktree |
VIBE_ORIGIN_PATH | Absolute path to the original repository |
Example Usage
Section titled “Example Usage”[hooks]post_start = [ "echo 'Worktree created at: $VIBE_WORKTREE_PATH'", "echo 'Origin repository: $VIBE_ORIGIN_PATH'"]Hook Output Behavior
Section titled “Hook Output Behavior”vibe displays a real-time progress tree during hook execution:
✶ Setting up worktree feature/new-ui…┗ ☒ Pre-start hooks ┗ ☒ npm install ☒ cargo build --release ⠋ Copying files ┗ ⠋ .env.local ☐ node_modules/Output Handling
Section titled “Output Handling”| Situation | stdout | stderr |
|---|---|---|
| Progress display active | Suppressed | Always shown |
| Progress display inactive | Written to stderr | Always shown |
| Failed hooks | N/A | Always shown |
Hook Execution Order
Section titled “Hook Execution Order”For vibe start:
pre_starthooks run in origin repository- Worktree is created
- Files/directories are copied
post_starthooks run in new worktree
For vibe clean:
pre_cleanhooks run in current worktree- Worktree is removed
post_cleanhooks run in main repository
Common Patterns
Section titled “Common Patterns”Node.js Project
Section titled “Node.js Project”[hooks]post_start = [ "pnpm install", "pnpm build"]pre_clean = ["git stash --include-untracked"]Bun Project
Section titled “Bun Project”[hooks]post_start = [ "bun install", "bun run build"]pre_clean = ["git stash --include-untracked"]Database Migration
Section titled “Database Migration”[hooks]post_start = [ "pnpm install", "pnpm db:migrate", "pnpm db:seed"]Docker Environment
Section titled “Docker Environment”[hooks]post_start = [ "docker-compose up -d", "sleep 5", "pnpm db:migrate"]pre_clean = ["docker-compose down"]Skipping Hooks
Section titled “Skipping Hooks”You can skip hooks with the --no-hooks option:
vibe start feat/quick-fix --no-hooksClaude Code Integration
Section titled “Claude Code Integration”vibe integrates with Claude Code’s WorktreeCreate and WorktreeRemove hooks. This replaces Claude Code’s default git worktree add behavior with vibe’s full workflow, including hooks, CoW file copying, and configuration.
Add the following to your Claude Code settings.json:
{ "hooks": { "WorktreeCreate": [ { "hooks": [ { "type": "command", "command": "vibe start --claude-code-worktree-hook --quiet 2>/dev/null" } ] } ], "WorktreeRemove": [ { "hooks": [ { "type": "command", "command": "vibe clean --claude-code-worktree-hook --force 2>/dev/null" } ] } ] }}How It Works
Section titled “How It Works”When Claude Code creates a worktree (via natural language, isolation: "worktree", or the /worktree command), vibe handles the full lifecycle:
WorktreeCreate:
- Reads worktree name from stdin (Claude Code hook protocol)
- Runs
pre_starthooks in the origin repository - Creates the git worktree
- Copies files/directories using CoW
- Runs
post_starthooks in the new worktree (e.g.,pnpm install) - Outputs the worktree path to stdout for Claude Code
WorktreeRemove:
- Reads worktree path from stdin (Claude Code hook protocol)
- Runs
pre_cleanhooks in the worktree - Removes the git worktree
- Runs
post_cleanhooks in the main repository
Benefits
Section titled “Benefits”Without this integration, Claude Code’s worktree creation only runs git worktree add. By using vibe’s hooks, you get:
- Automatic dependency installation (
pnpm install,bun install, etc.) - CoW file copying (
.env,node_modules, etc.) - Custom setup scripts (database migrations, Docker containers, etc.)
- Cleanup hooks on worktree removal