Skip to content

feat: add pre-switch hook#1094

Merged
max-sixty merged 2 commits intomainfrom
pre-switch
Feb 18, 2026
Merged

feat: add pre-switch hook#1094
max-sixty merged 2 commits intomainfrom
pre-switch

Conversation

@max-sixty
Copy link
Copy Markdown
Owner

Summary

  • Add pre-switch hook that runs before wt switch does anything — before branch validation, planning, or worktree creation
  • Runs in both the direct switch path and the interactive picker path
  • Includes a fetch-if-stale example (check FETCH_HEAD age, fetch if >6 hours)
  • Add orienting sentence in hook docs pointing to post-start as the most common starting point

Closes #1085. Thanks to @jdb8 for reporting.

Test plan

  • test_user_pre_switch_hook_executes — hook runs in source worktree before switch
  • test_user_pre_switch_failure_blocks_switch — failing hook aborts --create
  • test_user_pre_switch_skipped_with_no_verify--no-verify skips hook
  • All 1075 tests pass, all lints pass

This was written by Claude Code on behalf of @max-sixty

Run shell commands before `wt switch` does anything — before branch
validation, planning, or worktree creation. Runs in both the direct
switch path and the interactive picker.

Closes #1085. Thanks to @jdb8 for reporting.

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@worktrunk-bot worktrunk-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean feature addition — the hook plumbing, docs, CLI wiring, and tests all follow the established patterns well.

let config = repo.user_config();

// Run pre-switch hooks before anything else (before branch validation, planning, etc.)
run_pre_switch_hooks(&repo, config, true)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes: true here auto-approves project pre-switch hooks without prompting, while approve_switch_hooks on line 320 uses yes: false (which prompts). This means project-level pre-switch hooks silently auto-approve in the picker, but post-switch/post-create project hooks still prompt — feels inconsistent.

Suggested change
run_pre_switch_hooks(&repo, config, true)?;
run_pre_switch_hooks(&repo, config, false)?;

Covers the hook_commands.rs dispatch path for pre-switch, improving
codecov/patch coverage.

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty max-sixty merged commit d9e1d53 into main Feb 18, 2026
22 checks passed
@max-sixty max-sixty deleted the pre-switch branch February 18, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any way to auto-fetch/pull before a new worktree?

2 participants