Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: Add user-level hooks that run for all repositories, add `wt hook show` (#118)

Maximilian Roosb2048db58a33
diff --git a/CLAUDE.md b/CLAUDE.md
index 9f85c2684..af5e69649 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -552,11 +552,12 @@ let lines: Vec<_> = reader.lines().collect();
All background operation logs are centralized in `.git/wt-logs/` (main worktree's git directory):
-- **Post-start commands**: `{branch}-post-start-{command}.log`
+- **Post-start commands**: `{branch}-{source}-post-start-{command}.log` (source is `user` or `project`)
- **Background removal**: `{branch}-remove.log`
Examples (where command names are from config):
-- `feature-post-start-npm.log`
+- `feature-user-post-start-npm.log`
+- `feature-project-post-start-build.log`
- `bugfix-remove.log`
### Log Behavior
diff --git a/dev/wt.example.toml b/dev/wt.example.toml
index 43f5d2479..474042ba5 100644
--- a/dev/wt.example.toml
+++ b/dev/wt.example.toml
@@ -33,7 +33,7 @@
# Use for: uv sync, npm install, bundle install, build, dev servers, file watchers,
# downloading assets too large for git (images, ML models, binaries), long-running tasks
# The worktree switch completes immediately, these run in parallel
-# Output is logged to .git/wt-logs/{branch}-post-start-{name}.log
+# Output is logged to .git/wt-logs/{branch}-{source}-post-start-{name}.log (source: user/project)
#
# Format options:
# 1. Single string:
diff --git a/docs/content/config.md b/docs/content/config.md
index 787428bf4..0bbd8a1d0 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -100,7 +100,7 @@ stage = "all" # "all" (default), "tracked", or "none"
squash = false # Preserve individual commits (--no-squash)
commit = false # Skip committing uncommitted changes (--no-commit)
remove = false # Keep worktree after merge (--no-remove)
-verify = false # Skip project hooks (--no-verify)
+verify = false # Skip hooks (--no-verify)
```
### LLM commit messages
@@ -129,6 +129,22 @@ approved-commands = [
Manage approvals with `wt config approvals add` to review and pre-approve commands, and `wt config approvals clear` to reset (add `--global` to clear all projects).
+### User hooks
+
+Personal hooks that run for all repositories. Use the same syntax as project hooks:
+
+```toml
+[post-create]
+setup = "echo 'Setting up worktree...'"
+
+[pre-merge]
+notify = "notify-send 'Merging {{ branch }}'"
+```
+
+User hooks run before project hooks and don't require approval. Skip with `--no-verify`.
+
+See [wt hook](@/hook.md#user-hooks) for complete documentation.
+
## Project config
The project config defines lifecycle hooks — commands that run at specific points during worktree operations. This file is checked into version control and shared across the team.
@@ -452,7 +468,7 @@ With `--project`, creates `.config/wt.toml` in the current repository:
# Use for: uv sync, npm install, bundle install, build, dev servers, file watchers,
# downloading assets too large for git (images, ML models, binaries), long-running tasks
# The worktree switch completes immediately, these run in parallel
-# Output is logged to .git/wt-logs/{branch}-post-start-{name}.log
+# Output is logged to .git/wt-logs/{branch}-{source}-post-start-{name}.log (source: user/project)
#
# Format options:
# 1. Single string:
diff --git a/docs/content/hook.md b/docs/content/hook.md
index 771d61c8b..13eb2e9c4 100644
--- a/docs/content/hook.md
+++ b/docs/content/hook.md
@@ -8,13 +8,15 @@ group = "Commands"
<!-- ⚠️ AUTO-GENERATED from `wt hook --help-page` — edit cli.rs to update -->
-Run project-defined lifecycle hooks from `.config/wt.toml`.
+Run hooks independently of normal worktree operations.
-Hooks are commands that run automatically during worktree operations (`wt switch --create`, `wt merge`, `wt remove`). Use `wt hook` to run them manually for testing or CI.
+Hooks normally run automatically during `wt switch --create`, `wt merge`, and `wt remove`. This command runs them on demand — useful for testing hooks during development, running in CI pipelines, or re-running after a failure.
+
+Both user hooks (from `~/.config/worktrunk/config.toml`) and project hooks (from `.config/wt.toml`) are supported.
```bash
-wt hook pre-merge # Run pre-merge hooks (for testing)
-wt hook pre-merge --force # Run in CI (skip approval prompts)
+wt hook pre-merge # Run pre-merge hooks
+wt hook pre-merge --force # Skip approval prompts (for CI)
```
## Hook types
@@ -56,7 +58,7 @@ build = "npm run build"
server = "npm run dev"
```
-Output logged to `.git/wt-logs/{branch}-post-start-{name}.log`.
+Output logged to `.git/wt-logs/{branch}-{source}-post-start-{name}.log` (source is `user` or `project`).
### pre-commit
@@ -141,6 +143,7 @@ Hooks can use template variables that expand at runtime:
| `{{ commit }}` | a1b2c3d4e5f6... | Full HEAD commit SHA |
| `{{ short_commit }}` | a1b2c3d | Short HEAD commit SHA |
| `{{ remote }}` | origin | Primary remote name |
+| `{{ remote_url }}` | [email protected]:user/repo.git | Remote URL |
| `{{ upstream }}` | origin/feature | Upstream tracking branch |
| `{{ target }}` | main | Target branch (merge hooks only) |
@@ -172,10 +175,59 @@ Project commands require approval on first run:
- Approvals are saved to user config (`~/.config/worktrunk/config.toml`)
- If a command changes, new approval is required
- Use `--force` to bypass prompts (useful for CI/automation)
-- Use `--no-verify` to skip all project hooks
+- Use `--no-verify` to skip hooks
Manage approvals with `wt config approvals add` and `wt config approvals clear`.
+## User hooks
+
+Define hooks in `~/.config/worktrunk/config.toml` to run for all repositories. User hooks run before project hooks and don't require approval.
+
+```toml
+# ~/.config/worktrunk/config.toml
+[post-create]
+setup = "echo 'Setting up worktree...'"
+
+[pre-merge]
+notify = "notify-send 'Merging {{ branch }}'"
+```
+
+User hooks support the same hook types and template variables as project hooks.
+
+**Key differences from project hooks:**
+
+| Aspect | Project hooks | User hooks |
+|--------|--------------|------------|
+| Location | `.config/wt.toml` | `~/.config/worktrunk/config.toml` |
+| Scope | Single repository | All repositories |
+| Approval | Required | Not required |
+| Execution order | After user hooks | Before project hooks |
+
+Skip hooks with `--no-verify`.
+
+**Use cases:**
+- Personal notifications or logging
+- Editor/IDE integration
+- Repository-agnostic setup tasks
+- Filtering by repository using JSON context
+
+**Filtering by repository:**
+
+User hooks receive JSON context on stdin, enabling repository-specific behavior:
+
+```toml
+# ~/.config/worktrunk/config.toml
+[post-create]
+gitlab-setup = """
+python3 -c '
+import json, sys, subprocess
+ctx = json.load(sys.stdin)
+if "gitlab" in ctx.get("remote", ""):
+ subprocess.run(["glab", "mr", "create", "--fill"])
+'
+"""
+```
+
## Examples
### Node.js / TypeScript
@@ -296,11 +348,12 @@ env = "cp {{ repo_root }}/.env.local .env"
## Command reference
```
-wt hook - Run project hooks
+wt hook - Run hooks independently
Usage: wt hook [OPTIONS] <COMMAND>
Commands:
+ show Show configured hooks
post-create Run post-create hooks
post-start Run post-start hooks
pre-commit Run pre-commit hooks
diff --git a/docs/content/merge.md b/docs/content/merge.md
index 7d8a955a6..36a10375e 100644
--- a/docs/content/merge.md
+++ b/docs/content/merge.md
@@ -90,7 +90,7 @@ Options:
Keep worktree after merge
--no-verify
- Skip all project hooks
+ Skip hooks
-f, --force
Skip approval prompts
diff --git a/docs/content/remove.md b/docs/content/remove.md
index eacfff924..dd2e76f45 100644
--- a/docs/content/remove.md
+++ b/docs/content/remove.md
@@ -87,7 +87,10 @@ Options:
Run removal in foreground
--no-verify
- Skip pre-remove hooks
+ Skip hooks
+
+ --force
+ Skip approval prompts
-h, --help
Print help (see a summary with '-h')
diff --git a/docs/content/step.md b/docs/content/step.md
index b0f0120ad..f7a4f66f7 100644
--- a/docs/content/step.md
+++ b/docs/content/step.md
@@ -38,7 +38,7 @@ wt step push
## See also
- [wt merge](@/merge.md) — Runs commit → squash → rebase → hooks → push → cleanup automatically
-- [wt hook](@/hook.md) — Run project-defined lifecycle hooks
+- [wt hook](@/hook.md) — Run hooks independently
---
diff --git a/docs/content/switch.md b/docs/content/switch.md
index b78d0dcd2..f5a73d295 100644
--- a/docs/content/switch.md
+++ b/docs/content/switch.md
@@ -104,7 +104,7 @@ Options:
Skip approval prompts
--no-verify
- Skip all project hooks
+ Skip hooks
-h, --help
Print help (see a summary with '-h')
diff --git a/src/cli.rs b/src/cli.rs
index 67bf7e5ba..52f30e6b3 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -590,7 +590,7 @@ pub enum StepCommand {
#[arg(short, long)]
force: bool,
- /// Skip pre-commit hooks
+ /// Skip hooks
#[arg(long = "no-verify", action = clap::ArgAction::SetFalse, default_value_t = true)]
verify: bool,
@@ -616,7 +616,7 @@ pub enum StepCommand {
#[arg(short, long)]
force: bool,
- /// Skip pre-commit hooks
+ /// Skip hooks
#[arg(long = "no-verify", action = clap::ArgAction::SetFalse, default_value_t = true)]
verify: bool,
@@ -651,9 +651,23 @@ pub enum StepCommand {
},
}
-/// Run project hooks
+/// Run hooks independently
#[derive(Subcommand)]
pub enum HookCommand {
+ /// Show configured hooks
+ ///
+ /// Lists all hooks from user config and project config with their commands.
+ /// Project hooks show approval status (❓ = needs approval).
+ Show {
+ /// Hook type to show (default: all)
+ #[arg(value_parser = ["post-create", "post-start", "pre-commit", "pre-merge", "post-merge", "pre-remove"])]
+ hook_type: Option<String>,
+
+ /// Show expanded commands with current variables
+ #[arg(long)]
+ expanded: bool,
+ },
+
/// Run post-create hooks
///
/// Executes blocking commands after worktree creation.
@@ -849,7 +863,7 @@ stage = "all" # "all" (default), "tracked", or "none"
squash = false # Preserve individual commits (--no-squash)
commit = false # Skip committing uncommitted changes (--no-commit)
remove = false # Keep worktree after merge (--no-remove)
-verify = false # Skip project hooks (--no-verify)
+verify = false # Skip hooks (--no-verify)
```
### LLM commit messages
@@ -878,6 +892,22 @@ approved-commands = [
Manage approvals with `wt config approvals add` to review and pre-approve commands, and `wt config approvals clear` to reset (add `--global` to clear all projects).
+### User hooks
+
+Personal hooks that run for all repositories. Use the same syntax as project hooks:
+
+```toml
+[post-create]
+setup = "echo 'Setting up worktree...'"
+
+[pre-merge]
+notify = "notify-send 'Merging {{ branch }}'"
+```
+
+User hooks run before project hooks and don't require approval. Skip with `--no-verify`.
+
+See [wt hook](@/hook.md#user-hooks) for complete documentation.
+
## Project config
The project config defines lifecycle hooks — commands that run at specific points during worktree operations. This file is checked into version control and shared across the team.
@@ -1005,7 +1035,7 @@ wt step push
## See also
- [wt merge](@/merge.md) — Runs commit → squash → rebase → hooks → push → cleanup automatically
-- [wt hook](@/hook.md) — Run project-defined lifecycle hooks
+- [wt hook](@/hook.md) — Run hooks independently
"#
)]
Step {
@@ -1013,16 +1043,18 @@ wt step push
action: StepCommand,
},
- /// Run project hooks
+ /// Run hooks independently
#[command(
name = "hook",
- after_long_help = r#"Run project-defined lifecycle hooks from `.config/wt.toml`.
+ after_long_help = r#"Run hooks independently of normal worktree operations.
-Hooks are commands that run automatically during worktree operations (`wt switch --create`, `wt merge`, `wt remove`). Use `wt hook` to run them manually for testing or CI.
+Hooks normally run automatically during `wt switch --create`, `wt merge`, and `wt remove`. This command runs them on demand — useful for testing hooks during development, running in CI pipelines, or re-running after a failure.
+
+Both user hooks (from `~/.config/worktrunk/config.toml`) and project hooks (from `.config/wt.toml`) are supported.
```console
-wt hook pre-merge # Run pre-merge hooks (for testing)
-wt hook pre-merge --force # Run in CI (skip approval prompts)
+wt hook pre-merge # Run pre-merge hooks
+wt hook pre-merge --force # Skip approval prompts (for CI)
```
## Hook types
@@ -1064,7 +1096,7 @@ build = "npm run build"
server = "npm run dev"
```
-Output logged to `.git/wt-logs/{branch}-post-start-{name}.log`.
+Output logged to `.git/wt-logs/{branch}-{source}-post-start-{name}.log` (source is `user` or `project`).
### pre-commit
@@ -1149,6 +1181,7 @@ Hooks can use template variables that expand at runtime:
| `{{ commit }}` | a1b2c3d4e5f6... | Full HEAD commit SHA |
| `{{ short_commit }}` | a1b2c3d | Short HEAD commit SHA |
| `{{ remote }}` | origin | Primary remote name |
+| `{{ remote_url }}` | [email protected]:user/repo.git | Remote URL |
| `{{ upstream }}` | origin/feature | Upstream tracking branch |
| `{{ target }}` | main | Target branch (merge hooks only) |
@@ -1180,10 +1213,59 @@ Project commands require approval on first run:
- Approvals are saved to user config (`~/.config/worktrunk/config.toml`)
- If a command changes, new approval is required
- Use `--force` to bypass prompts (useful for CI/automation)
-- Use `--no-verify` to skip all project hooks
+- Use `--no-verify` to skip hooks
Manage approvals with `wt config approvals add` and `wt config approvals clear`.
+## User hooks
+
+Define hooks in `~/.config/worktrunk/config.toml` to run for all repositories. User hooks run before project hooks and don't require approval.
+
+```toml
+# ~/.config/worktrunk/config.toml
+[post-create]
+setup = "echo 'Setting up worktree...'"
+
+[pre-merge]
+notify = "notify-send 'Merging {{ branch }}'"
+```
+
+User hooks support the same hook types and template variables as project hooks.
+
+**Key differences from project hooks:**
+
+| Aspect | Project hooks | User hooks |
+|--------|--------------|------------|
+| Location | `.config/wt.toml` | `~/.config/worktrunk/config.toml` |
+| Scope | Single repository | All repositories |
+| Approval | Required | Not required |
+| Execution order | After user hooks | Before project hooks |
+
+Skip hooks with `--no-verify`.
+
+**Use cases:**
+- Personal notifications or logging
+- Editor/IDE integration
+- Repository-agnostic setup tasks
+- Filtering by repository using JSON context
+
+**Filtering by repository:**
+
+User hooks receive JSON context on stdin, enabling repository-specific behavior:
+
+```toml
+# ~/.config/worktrunk/config.toml
+[post-create]
+gitlab-setup = """
+python3 -c '
+import json, sys, subprocess
+ctx = json.load(sys.stdin)
+if "gitlab" in ctx.get("remote", ""):
+ subprocess.run(["glab", "mr", "create", "--fill"])
+'
+"""
+```
+
## Examples
### Node.js / TypeScript
@@ -1620,7 +1702,7 @@ wt switch --create fix --base=@ # Branch from current HEAD
#[arg(short = 'f', long)]
force: bool,
- /// Skip all project hooks
+ /// Skip hooks
#[arg(long = "no-verify", action = clap::ArgAction::SetFalse, default_value_t = true)]
verify: bool,
},
@@ -1700,9 +1782,13 @@ Arguments resolve by path first, then branch name. [Shortcuts](@/switch.md#short
#[arg(long = "no-background", action = clap::ArgAction::SetFalse, default_value_t = true)]
background: bool,
- /// Skip pre-remove hooks
+ /// Skip hooks
#[arg(long = "no-verify", action = clap::ArgAction::SetFalse, default_value_t = true)]
verify: bool,
+
+ /// Skip approval prompts
+ #[arg(long)]
+ force: bool,
},
/// Merge worktree into target branch
@@ -1795,11 +1881,11 @@ Use `--no-commit` to skip all git operations (steps 1-2) and only run hooks and
#[arg(long = "no-remove", overrides_with = "remove")]
no_remove: bool,
- /// Force running project hooks
+ /// Force running hooks
#[arg(long, overrides_with = "no_verify", hide = true)]
verify: bool,
- /// Skip all project hooks
+ /// Skip hooks
#[arg(long = "no-verify", overrides_with = "verify")]
no_verify: bool,
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 3e7801fe0..5d4ce8813 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -1,12 +1,29 @@
//! Command approval and execution utilities
//!
//! Shared helpers for approving commands declared in project configuration.
+//!
+//! # "Approve at the Gate" Pattern
+//!
+//! Commands that run hooks should approve all project commands **upfront** before any execution:
+//!
+//! ```text
+//! User runs command
+//! ↓
+//! approve_hooks() ← Single approval prompt
+//! ↓
+//! Execute hooks (approval already done)
+//! ```
+//!
+//! This ensures approval happens exactly once at the command entry point,
+//! eliminating the need to thread `auto_trust` through execution layers.
+use super::project_config::collect_commands_for_hooks;
+use super::repository_ext::RepositoryCliExt;
use crate::output;
use anyhow::Context;
use color_print::cformat;
use worktrunk::config::{Command, WorktrunkConfig};
-use worktrunk::git::GitError;
+use worktrunk::git::{GitError, HookType};
use worktrunk::styling::{
INFO_EMOJI, PROMPT_EMOJI, WARNING_EMOJI, eprint, eprintln, format_bash_with_gutter,
hint_message, stderr, warning_message,
@@ -133,3 +150,69 @@ fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> anyhow:
Ok(response.trim().eq_ignore_ascii_case("y"))
}
+
+/// Collect project commands for hooks and request batch approval with template expansion.
+///
+/// This is the "gate" function that should be called at command entry points
+/// (like `wt remove`, `wt switch --create`, `wt merge`) before any hooks execute.
+/// It expands template variables before showing the approval prompt, so users see
+/// the actual commands that will run (e.g., with actual branch names) instead of
+/// template placeholders.
+///
+/// # Parameters
+/// - `ctx`: Command context providing template variables (branch, worktree, etc.)
+/// - `hook_types`: Which hook types to collect commands for
+/// - `extra_vars`: Additional template variables
+///
+/// # Example
+///
+/// ```ignore
+/// let ctx = CommandContext::new(&repo, &config, &branch, &worktree_path, &repo_root, force);
+/// let approved = approve_hooks(
+/// &ctx,
+/// &[HookType::PostCreate, HookType::PostStart],
+/// &[],
+/// )?;
+/// ```
+pub fn approve_hooks(
+ ctx: &super::command_executor::CommandContext<'_>,
+ hook_types: &[HookType],
+ extra_vars: &[(&str, &str)],
+) -> anyhow::Result<bool> {
+ approve_hooks_filtered(ctx, hook_types, extra_vars, None)
+}
+
+/// Like `approve_hooks` but with optional name filter for targeted hook approval.
+///
+/// When `name_filter` is provided, only commands matching that name are shown
+/// in the approval prompt. This is used by `wt hook <type> --name <name>` to
+/// approve only the targeted hook rather than all hooks of that type.
+pub fn approve_hooks_filtered(
+ ctx: &super::command_executor::CommandContext<'_>,
+ hook_types: &[HookType],
+ extra_vars: &[(&str, &str)],
+ name_filter: Option<&str>,
+) -> anyhow::Result<bool> {
+ let project_config = match ctx.repo.load_project_config()? {
+ Some(cfg) => cfg,
+ None => return Ok(true), // No project config = no commands to approve
+ };
+
+ let mut commands = collect_commands_for_hooks(&project_config, hook_types);
+
+ // Apply name filter before approval to only prompt for targeted commands
+ if let Some(name) = name_filter {
+ commands.retain(|cmd| cmd.name.as_deref() == Some(name));
+ }
+
+ if commands.is_empty() {
+ return Ok(true);
+ }
+
+ // Expand templates with the provided context
+ let expanded =
+ super::command_executor::expand_commands_for_approval(&commands, ctx, extra_vars)?;
+
+ let project_id = ctx.repo.project_identifier()?;
+ approve_command_batch(&expanded, &project_id, ctx.config, ctx.force, false)
+}
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index 03db49fec..938502aab 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -1,11 +1,10 @@
use std::collections::HashMap;
use std::path::Path;
+use worktrunk::HookType;
use worktrunk::config::{
- Command, CommandConfig, CommandPhase, WorktrunkConfig, expand_template, sanitize_branch_name,
+ Command, CommandConfig, WorktrunkConfig, expand_template, sanitize_branch_name,
};
-use worktrunk::git::{Repository, WorktrunkError};
-
-use super::command_approval::approve_command_batch;
+use worktrunk::git::Repository;
#[derive(Debug)]
pub struct PreparedCommand {
@@ -48,7 +47,7 @@ impl<'a> CommandContext<'a> {
///
/// The resulting HashMap is passed to hook commands as JSON on stdin,
/// and used directly for template variable expansion.
-fn build_hook_context(
+pub fn build_hook_context(
ctx: &CommandContext<'_>,
extra_vars: &[(&str, &str)],
) -> HashMap<String, String> {
@@ -85,7 +84,11 @@ fn build_hook_context(
}
if let Ok(remote) = ctx.repo.primary_remote() {
- map.insert("remote".into(), remote);
+ map.insert("remote".into(), remote.clone());
+ // Add remote URL for conditional hook execution (e.g., GitLab vs GitHub)
+ if let Ok(url) = ctx.repo.run_command(&["remote", "get-url", &remote]) {
+ map.insert("remote_url".into(), url.trim().into());
+ }
if let Ok(Some(upstream)) = ctx.repo.upstream_branch(ctx.branch) {
map.insert("upstream".into(), upstream);
}
@@ -161,54 +164,72 @@ fn expand_commands(
Ok(result)
}
-/// Prepare project commands for execution with approval
+/// Expand commands for approval display (public version for gate approval)
+///
+/// Returns commands with their `expanded` field filled in, showing actual values
+/// instead of template placeholders.
+pub fn expand_commands_for_approval(
+ commands: &[Command],
+ ctx: &CommandContext<'_>,
+ extra_vars: &[(&str, &str)],
+) -> anyhow::Result<Vec<Command>> {
+ let expanded = expand_commands(commands, ctx, extra_vars)?;
+ Ok(expanded.into_iter().map(|(cmd, _json)| cmd).collect())
+}
+
+/// Prepare project commands for execution
///
/// This function:
/// 1. Expands command templates with context variables
-/// 2. Requests user approval for unapproved commands (unless auto_trust or force)
-/// 3. Returns prepared commands ready for execution, each with JSON context for stdin
+/// 2. Returns prepared commands ready for execution, each with JSON context for stdin
///
-/// Returns `Err(WorktrunkError::CommandNotApproved)` if the user declines approval.
+/// Note: Approval is handled at the gate (command entry point), not here.
pub fn prepare_project_commands(
command_config: &CommandConfig,
ctx: &CommandContext<'_>,
- auto_trust: bool,
extra_vars: &[(&str, &str)],
- phase: CommandPhase,
+ hook_type: HookType,
) -> anyhow::Result<Vec<PreparedCommand>> {
- let commands = command_config.commands_with_phase(phase);
+ let commands = command_config.commands_with_phase(hook_type);
if commands.is_empty() {
return Ok(Vec::new());
}
- let project_id = ctx.repo.project_identifier()?;
-
- // Expand commands before approval for transparency
let expanded_with_json = expand_commands(&commands, ctx, extra_vars)?;
- // Extract just the commands for approval
- let expanded_commands: Vec<_> = expanded_with_json
- .iter()
- .map(|(cmd, _)| cmd.clone())
- .collect();
+ Ok(expanded_with_json
+ .into_iter()
+ .map(|(cmd, context_json)| PreparedCommand {
+ name: cmd.name,
+ expanded: cmd.expanded,
+ context_json,
+ })
+ .collect())
+}
- // Flush stdout before prompting on stderr to ensure correct output ordering
- // This prevents the approval prompt from appearing before previous success messages
- crate::output::flush()?;
-
- // Approve using expanded commands (which have both template and expanded forms)
- if !auto_trust
- && !approve_command_batch(
- &expanded_commands,
- &project_id,
- ctx.config,
- ctx.force,
- false,
- )?
- {
- return Err(WorktrunkError::CommandNotApproved.into());
+/// Prepare user hooks for execution without approval
+///
+/// Unlike project commands, user hooks don't require approval because they're
+/// defined in the user's own config file. The user implicitly approves them
+/// by adding them to their config.
+///
+/// This function:
+/// 1. Expands command templates with context variables
+/// 2. Returns prepared commands ready for execution, each with JSON context for stdin
+pub fn prepare_user_commands(
+ command_config: &CommandConfig,
+ ctx: &CommandContext<'_>,
+ extra_vars: &[(&str, &str)],
+ hook_type: HookType,
+) -> anyhow::Result<Vec<PreparedCommand>> {
+ let commands = command_config.commands_with_phase(hook_type);
+ if commands.is_empty() {
+ return Ok(Vec::new());
}
+ // Expand commands (no approval needed for user hooks)
+ let expanded_with_json = expand_commands(&commands, ctx, extra_vars)?;
+
Ok(expanded_with_json
.into_iter()
.map(|(cmd, context_json)| PreparedCommand {
diff --git a/src/commands/commit.rs b/src/commands/commit.rs
index 3ab67e3a5..01aef77f7 100644
--- a/src/commands/commit.rs
+++ b/src/commands/commit.rs
@@ -1,11 +1,12 @@
use anyhow::Context;
use color_print::cformat;
+use worktrunk::HookType;
use worktrunk::config::CommitGenerationConfig;
use worktrunk::git::Repository;
use worktrunk::styling::{format_with_gutter, hint_message, progress_message, success_message};
use super::command_executor::CommandContext;
-use super::hooks::HookPipeline;
+use super::hooks::{HookFailureStrategy, HookPipeline, HookSource};
use super::repository_ext::RepositoryCliExt;
// Re-export StageMode from config for use by CLI
@@ -17,7 +18,6 @@ pub struct CommitOptions<'a> {
pub target_branch: Option<&'a str>,
pub no_verify: bool,
pub stage_mode: StageMode,
- pub auto_trust: bool,
pub warn_about_untracked: bool,
pub show_no_squash_note: bool,
}
@@ -30,7 +30,6 @@ impl<'a> CommitOptions<'a> {
target_branch: None,
no_verify: false,
stage_mode: StageMode::All,
- auto_trust: false,
warn_about_untracked: true,
show_no_squash_note: false,
}
@@ -139,18 +138,44 @@ impl<'a> CommitGenerator<'a> {
impl CommitOptions<'_> {
pub fn commit(self) -> anyhow::Result<()> {
let project_config = self.ctx.repo.load_project_config()?;
- let has_pre_commit = project_config
+ let user_hooks_exist = self.ctx.config.pre_commit.is_some();
+ let project_hooks_exist = project_config
.as_ref()
.map(|c| c.pre_commit.is_some())
.unwrap_or(false);
+ let any_hooks_exist = user_hooks_exist || project_hooks_exist;
- if self.no_verify && has_pre_commit {
+ // Show skip message
+ if self.no_verify && any_hooks_exist {
crate::output::print(hint_message(cformat!(
- "Skipping pre-commit hook (<bright-black>--no-verify</>)"
+ "Skipping pre-commit hooks (<bright-black>--no-verify</>)"
)))?;
- } else if let Some(ref config) = project_config {
+ }
+
+ if !self.no_verify {
let pipeline = HookPipeline::new(*self.ctx);
- pipeline.run_pre_commit(config, self.target_branch, self.auto_trust, None)?;
+ let extra_vars: Vec<(&str, &str)> = self
+ .target_branch
+ .into_iter()
+ .map(|target| ("target", target))
+ .collect();
+
+ // Run user pre-commit hooks first (no approval required)
+ if let Some(user_config) = &self.ctx.config.pre_commit {
+ pipeline.run_sequential(
+ user_config,
+ HookType::PreCommit,
+ HookSource::User,
+ &extra_vars,
+ HookFailureStrategy::FailFast,
+ None,
+ )?;
+ }
+
+ // Then run project pre-commit hooks (require approval)
+ if let Some(ref config) = project_config {
+ pipeline.run_pre_commit(config, self.target_branch, None)?;
+ }
}
if self.warn_about_untracked && self.stage_mode == StageMode::All {
diff --git a/src/commands/hooks.rs b/src/commands/hooks.rs
index 2e3eba6bf..d906dc4e2 100644
--- a/src/commands/hooks.rs
+++ b/src/commands/hooks.rs
@@ -1,10 +1,26 @@
+// TODO(hook-naming): Refine hook display and filtering when user and project have same name
+//
+// Current behavior with `wt hook pre-merge foo`:
+// - Both user's "foo" and project's "foo" run (name filter applied to each source separately)
+// - Output: "Running user pre-merge foo:" then "Running project pre-merge foo:"
+//
+// Alternative approaches to consider:
+// 1. Show source in name: "Running pre-merge user:foo" / "Running pre-merge project:foo"
+// 2. Allow filtering by source: `wt hook pre-merge user:foo` runs only user's foo
+// 3. Current approach: always show "user"/"project" prefix, filter runs both
+//
+// The source prefix in filtering (option 2) would need to be used elsewhere too to justify
+// the syntax. Current behavior is reasonable but worth revisiting if users find it confusing.
+
use color_print::cformat;
use worktrunk::HookType;
-use worktrunk::config::{CommandConfig, CommandPhase, ProjectConfig};
-use worktrunk::git::{GitError, WorktrunkError};
+use worktrunk::config::{CommandConfig, ProjectConfig};
+use worktrunk::git::WorktrunkError;
use worktrunk::styling::{format_bash_with_gutter, progress_message, warning_message};
-use super::command_executor::{CommandContext, PreparedCommand, prepare_project_commands};
+use super::command_executor::{
+ CommandContext, PreparedCommand, prepare_project_commands, prepare_user_commands,
+};
use crate::commands::process::spawn_detached;
use crate::output::execute_command_in_worktree;
@@ -17,7 +33,33 @@ pub enum HookFailureStrategy {
Warn,
}
-/// Helper for preparing and executing project hook commands.
+/// Distinguishes between user hooks and project hooks for command preparation.
+///
+/// Approval for project hooks is handled at the gate (command entry point),
+/// not during hook execution.
+pub enum HookSource {
+ /// User hooks from ~/.config/worktrunk/config.toml (no approval required)
+ User,
+ /// Project hooks from .worktrunk.toml (approval handled at gate)
+ Project,
+}
+
+impl HookSource {
+ /// Returns the label prefix for this source
+ fn label_prefix(&self) -> &'static str {
+ match self {
+ HookSource::User => "user",
+ HookSource::Project => "project",
+ }
+ }
+
+ /// Format a label for display: "user pre-merge" or "project pre-merge"
+ fn format_label(&self, hook_type: HookType) -> String {
+ format!("{} {}", self.label_prefix(), hook_type)
+ }
+}
+
+/// Helper for preparing and executing hook commands.
pub struct HookPipeline<'a> {
ctx: CommandContext<'a>,
}
@@ -30,65 +72,62 @@ impl<'a> HookPipeline<'a> {
fn prepare_commands(
&self,
command_config: &CommandConfig,
- phase: CommandPhase,
- auto_trust: bool,
+ hook_type: HookType,
+ source: &HookSource,
extra_vars: &[(&str, &str)],
name_filter: Option<&str>,
) -> anyhow::Result<Vec<PreparedCommand>> {
- let commands =
- prepare_project_commands(command_config, &self.ctx, auto_trust, extra_vars, phase)?;
+ let commands = match source {
+ HookSource::User => {
+ prepare_user_commands(command_config, &self.ctx, extra_vars, hook_type)?
+ }
+ HookSource::Project => {
+ prepare_project_commands(command_config, &self.ctx, extra_vars, hook_type)?
+ }
+ };
+ Ok(Self::filter_by_name(commands, name_filter))
+ }
- // Filter by name if specified
+ /// Filter commands by name (returns empty vec if name not found - caller decides if that's an error)
+ fn filter_by_name(
+ commands: Vec<PreparedCommand>,
+ name_filter: Option<&str>,
+ ) -> Vec<PreparedCommand> {
match name_filter {
- Some(name) => {
- // Collect available names before consuming the iterator
- let available: Vec<String> =
- commands.iter().filter_map(|cmd| cmd.name.clone()).collect();
-
- let filtered: Vec<_> = commands
- .into_iter()
- .filter(|cmd| cmd.name.as_deref() == Some(name))
- .collect();
-
- if filtered.is_empty() {
- return Err(GitError::HookCommandNotFound {
- name: name.to_string(),
- available,
- }
- .into());
- }
-
- Ok(filtered)
- }
- None => Ok(commands),
+ Some(name) => commands
+ .into_iter()
+ .filter(|cmd| cmd.name.as_deref() == Some(name))
+ .collect(),
+ None => commands,
}
}
/// Run hook commands sequentially, using the provided failure strategy.
- #[allow(clippy::too_many_arguments)]
+ /// Returns the number of commands that were run.
pub fn run_sequential(
&self,
command_config: &CommandConfig,
- phase: CommandPhase,
- auto_trust: bool,
- extra_vars: &[(&str, &str)],
- label_prefix: &str,
hook_type: HookType,
+ source: HookSource,
+ extra_vars: &[(&str, &str)],
failure_strategy: HookFailureStrategy,
name_filter: Option<&str>,
- ) -> anyhow::Result<()> {
+ ) -> anyhow::Result<usize> {
let commands =
- self.prepare_commands(command_config, phase, auto_trust, extra_vars, name_filter)?;
+ self.prepare_commands(command_config, hook_type, &source, extra_vars, name_filter)?;
if commands.is_empty() {
- return Ok(());
+ return Ok(0);
}
+ let command_count = commands.len();
// Track first failure for Warn strategy (to propagate exit code after all commands run)
let mut first_failure: Option<(String, Option<String>, i32)> = None;
+ let label_prefix = source.format_label(hook_type);
+
for prepared in commands {
let label =
- crate::commands::format_command_label(label_prefix, prepared.name.as_deref());
+ crate::commands::format_command_label(&label_prefix, prepared.name.as_deref());
crate::output::print(progress_message(format!("{label}:")))?;
crate::output::gutter(format_bash_with_gutter(&prepared.expanded, ""))?;
@@ -153,34 +192,38 @@ impl<'a> HookPipeline<'a> {
.into());
}
- Ok(())
+ Ok(command_count)
}
/// Spawn hook commands in the background (used for post-start hooks).
- #[allow(clippy::too_many_arguments)]
- pub fn spawn_detached(
+ pub fn spawn_background(
&self,
command_config: &CommandConfig,
- phase: CommandPhase,
- auto_trust: bool,
+ hook_type: HookType,
+ source: HookSource,
extra_vars: &[(&str, &str)],
- label_prefix: &str,
name_filter: Option<&str>,
) -> anyhow::Result<()> {
let commands =
- self.prepare_commands(command_config, phase, auto_trust, extra_vars, name_filter)?;
+ self.prepare_commands(command_config, hook_type, &source, extra_vars, name_filter)?;
if commands.is_empty() {
return Ok(());
}
+ // Derive operation name from hook type (e.g., "post-start")
+ let operation_prefix = hook_type.to_string();
+ let label_prefix = source.format_label(hook_type);
+
for prepared in commands {
let label =
- crate::commands::format_command_label(label_prefix, prepared.name.as_deref());
+ crate::commands::format_command_label(&label_prefix, prepared.name.as_deref());
crate::output::print(progress_message(format!("{label}:")))?;
crate::output::gutter(format_bash_with_gutter(&prepared.expanded, ""))?;
let name = prepared.name.as_deref().unwrap_or("cmd");
- let operation = format!("post-start-{}", name);
+ // Include source in operation name to prevent log file collisions between
+ // user and project hooks with the same name
+ let operation = format!("{}-{}-{}", source.label_prefix(), operation_prefix, name);
if let Err(err) = spawn_detached(
self.ctx.repo,
self.ctx.worktree_path,
@@ -206,7 +249,6 @@ impl<'a> HookPipeline<'a> {
&self,
project_config: &ProjectConfig,
target_branch: Option<&str>,
- auto_trust: bool,
name_filter: Option<&str>,
) -> anyhow::Result<()> {
let Some(pre_commit_config) = &project_config.pre_commit else {
@@ -220,13 +262,12 @@ impl<'a> HookPipeline<'a> {
self.run_sequential(
pre_commit_config,
- CommandPhase::PreCommit,
- auto_trust,
- &extra_vars,
- "pre-commit",
HookType::PreCommit,
+ HookSource::Project,
+ &extra_vars,
HookFailureStrategy::FailFast,
name_filter,
- )
+ )?;
+ Ok(())
}
}
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index dd7ad2936..353b677f6 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -1,13 +1,13 @@
use worktrunk::HookType;
-use worktrunk::config::{Command, CommandPhase, ProjectConfig};
+use worktrunk::config::{Command, ProjectConfig};
use worktrunk::git::Repository;
use worktrunk::styling::info_message;
use super::command_approval::approve_command_batch;
-use super::command_executor::CommandContext;
+use super::command_executor::{CommandContext, expand_commands_for_approval};
use super::commit::CommitOptions;
use super::context::CommandEnv;
-use super::hooks::{HookFailureStrategy, HookPipeline};
+use super::hooks::{HookFailureStrategy, HookPipeline, HookSource};
use super::project_config::collect_commands_for_hooks;
use super::repository_ext::RepositoryCliExt;
use super::worktree::{MergeOperations, RemoveResult, handle_push};
@@ -27,6 +27,7 @@ struct MergeCommandCollector<'a> {
repo: &'a Repository,
no_commit: bool,
no_verify: bool,
+ will_remove: bool,
}
/// Commands collected for batch approval with their project identifier
@@ -59,6 +60,9 @@ impl<'a> MergeCommandCollector<'a> {
if !self.no_verify {
hooks.push(HookType::PreMerge);
hooks.push(HookType::PostMerge);
+ if self.will_remove {
+ hooks.push(HookType::PreRemove);
+ }
}
all_commands.extend(collect_commands_for_hooks(&project_config, &hooks));
@@ -110,17 +114,26 @@ pub fn handle_merge(
repo,
no_commit: !commit,
no_verify: !verify,
+ will_remove: remove_effective,
}
.collect()?;
- // Approve all commands in a single batch
- // Commands collected here are not yet expanded - expansion happens later in prepare_project_commands
- let approved = approve_command_batch(&all_commands, &project_id, config, force, false)?;
+ // Expand commands for approval display (shows actual values instead of templates)
+ let ctx = env.context(force);
+ let expanded =
+ expand_commands_for_approval(&all_commands, &ctx, &[("target", &target_branch)])?;
- // If commands were declined, show message explaining that merge continues anyway
- if !approved {
+ // Approve all expanded commands in a single batch
+ let approved = approve_command_batch(&expanded, &project_id, config, force, false)?;
+
+ // If commands were declined, skip hooks but continue with merge
+ // Shadow verify to gate all subsequent hook execution on approval
+ let verify = if !approved {
crate::output::print(info_message("Commands declined, continuing merge"))?;
- }
+ false
+ } else {
+ verify
+ };
// Handle uncommitted changes (skip if --no-commit) - track whether commit occurred
let committed = if commit && repo.is_dirty()? {
@@ -132,7 +145,6 @@ pub fn handle_merge(
options.target_branch = Some(&target_branch);
options.no_verify = !verify;
options.stage_mode = stage_mode;
- options.auto_trust = true;
options.warn_about_untracked = stage_mode == super::commit::StageMode::All;
options.show_no_squash_note = true;
@@ -149,8 +161,7 @@ pub fn handle_merge(
super::standalone::handle_squash(
Some(&target_branch),
force,
- !verify,
- true,
+ !verify, // skip_pre_commit when !verify
stage_mode
)?,
super::standalone::SquashResult::Squashed
@@ -171,9 +182,10 @@ pub fn handle_merge(
// Run pre-merge checks unless --no-verify was specified
// Do this after commit/squash/rebase to validate the final state that will be pushed
- if verify && let Some(project_config) = repo.load_project_config()? {
+ if verify {
let ctx = env.context(force);
- run_pre_merge_commands(&project_config, &ctx, &target_branch, true, None)?;
+ let project_config = repo.load_project_config()?.unwrap_or_default();
+ run_pre_merge_commands(&project_config, &ctx, &target_branch, None)?;
}
// Fast-forward push to target branch with commit/squash/rebase info for consolidated message
@@ -210,8 +222,9 @@ pub fn handle_merge(
force_delete: false,
target_branch: Some(target_branch.clone()),
};
- // Run hooks during merge removal (verify=true)
- crate::output::handle_remove_output(&remove_result, Some(&current_branch), true, true)?;
+ // Run hooks during merge removal (pass through verify flag)
+ // Approval was handled at the gate (MergeCommandCollector)
+ crate::output::handle_remove_output(&remove_result, Some(&current_branch), true, verify)?;
} else {
// Print comprehensive summary (worktree preserved)
// Priority: main worktree > on target > --no-remove flag
@@ -239,7 +252,7 @@ pub fn handle_merge(
&destination_repo_root,
force,
);
- execute_post_merge_commands(&ctx, &target_branch, true, None)?;
+ execute_post_merge_commands(&ctx, &target_branch, None)?;
}
Ok(())
@@ -259,100 +272,209 @@ fn handle_merge_summary_output(reason: PreserveReason) -> anyhow::Result<()> {
}
/// Run pre-merge commands sequentially (blocking, fail-fast)
///
-/// # Security Note
-/// `auto_trust`: When true, skip approval prompts (commands already approved in `wt merge`'s batch).
-/// When false, require approval (standalone `wt step hook` execution).
+/// Runs user hooks first, then project hooks.
+/// Approval is handled at the gate (command entry point).
pub fn run_pre_merge_commands(
project_config: &ProjectConfig,
ctx: &CommandContext,
target_branch: &str,
- auto_trust: bool,
name_filter: Option<&str>,
) -> anyhow::Result<()> {
- let Some(pre_merge_config) = &project_config.pre_merge else {
- return Ok(());
- };
-
let pipeline = HookPipeline::new(*ctx);
+ let extra_vars = [("target", target_branch)];
+ let mut total_commands_run = 0;
+
+ // Run user hooks first (no approval required)
+ if let Some(user_config) = &ctx.config.pre_merge {
+ total_commands_run += pipeline.run_sequential(
+ user_config,
+ HookType::PreMerge,
+ HookSource::User,
+ &extra_vars,
+ HookFailureStrategy::FailFast,
+ name_filter,
+ )?;
+ }
- pipeline.run_sequential(
- pre_merge_config,
- CommandPhase::PreMerge,
- auto_trust,
- &[("target", target_branch)],
- "pre-merge",
- HookType::PreMerge,
- HookFailureStrategy::FailFast,
- name_filter,
- )
+ // Then run project hooks (require approval)
+ if let Some(pre_merge_config) = &project_config.pre_merge {
+ total_commands_run += pipeline.run_sequential(
+ pre_merge_config,
+ HookType::PreMerge,
+ HookSource::Project,
+ &extra_vars,
+ HookFailureStrategy::FailFast,
+ name_filter,
+ )?;
+ }
+
+ // If name filter was provided but no commands matched, error with available names
+ if let Some(name) = name_filter
+ && total_commands_run == 0
+ {
+ let mut available = Vec::new();
+ if let Some(config) = &ctx.config.pre_merge {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("user:{n}"))),
+ );
+ }
+ if let Some(config) = &project_config.pre_merge {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("project:{n}"))),
+ );
+ }
+ return Err(worktrunk::git::GitError::HookCommandNotFound {
+ name: name.to_string(),
+ available,
+ }
+ .into());
+ }
+
+ Ok(())
}
/// Execute post-merge commands sequentially in the main worktree (blocking)
///
-/// # Security Note
-/// `auto_trust`: When true, skip approval prompts (commands already approved in `wt merge`'s batch).
-/// When false, require approval (standalone `wt step hook` execution).
+/// Runs user hooks first, then project hooks.
+/// Approval is handled at the gate (command entry point).
pub fn execute_post_merge_commands(
ctx: &CommandContext,
target_branch: &str,
- auto_trust: bool,
name_filter: Option<&str>,
) -> anyhow::Result<()> {
- // Load project config from the main worktree path directly
- let project_config = match ctx.repo.load_project_config()? {
- Some(cfg) => cfg,
- None => return Ok(()),
- };
+ let pipeline = HookPipeline::new(*ctx);
+ let extra_vars = [("target", target_branch)];
+ let mut total_commands_run = 0;
+
+ // Run user hooks first (no approval required)
+ if let Some(user_config) = &ctx.config.post_merge {
+ total_commands_run += pipeline.run_sequential(
+ user_config,
+ HookType::PostMerge,
+ HookSource::User,
+ &extra_vars,
+ HookFailureStrategy::Warn,
+ name_filter,
+ )?;
+ }
- let Some(post_merge_config) = &project_config.post_merge else {
- return Ok(());
- };
+ // Then run project hooks (require approval)
+ // Load project config from the main worktree path directly
+ let project_config = ctx.repo.load_project_config()?;
+
+ if let Some(post_merge_config) = project_config.as_ref().and_then(|c| c.post_merge.as_ref()) {
+ total_commands_run += pipeline.run_sequential(
+ post_merge_config,
+ HookType::PostMerge,
+ HookSource::Project,
+ &extra_vars,
+ HookFailureStrategy::Warn,
+ name_filter,
+ )?;
+ }
- let pipeline = HookPipeline::new(*ctx);
+ // If name filter was provided but no commands matched, error with available names
+ if let Some(name) = name_filter
+ && total_commands_run == 0
+ {
+ let mut available = Vec::new();
+ if let Some(config) = &ctx.config.post_merge {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("user:{n}"))),
+ );
+ }
+ if let Some(config) = project_config.as_ref().and_then(|c| c.post_merge.as_ref()) {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("project:{n}"))),
+ );
+ }
+ return Err(worktrunk::git::GitError::HookCommandNotFound {
+ name: name.to_string(),
+ available,
+ }
+ .into());
+ }
- pipeline.run_sequential(
- post_merge_config,
- CommandPhase::PostMerge,
- auto_trust,
- &[("target", target_branch)],
- "post-merge",
- HookType::PostMerge,
- HookFailureStrategy::Warn,
- name_filter,
- )
+ Ok(())
}
/// Execute pre-remove commands sequentially in the worktree (blocking)
///
+/// Runs user hooks first, then project hooks.
/// Runs before a worktree is removed. Non-zero exit aborts the removal.
-///
-/// # Arguments
-/// * `ctx` - Command context pointing to the worktree being removed
-/// * `auto_trust` - When true, skip approval prompts
+/// Approval is handled at the gate (command entry point).
pub fn execute_pre_remove_commands(
ctx: &CommandContext,
- auto_trust: bool,
name_filter: Option<&str>,
) -> anyhow::Result<()> {
- let project_config = match ctx.repo.load_project_config()? {
- Some(cfg) => cfg,
- None => return Ok(()),
- };
+ let pipeline = HookPipeline::new(*ctx);
+ let mut total_commands_run = 0;
+
+ // Run user hooks first (no approval required)
+ if let Some(user_config) = &ctx.config.pre_remove {
+ total_commands_run += pipeline.run_sequential(
+ user_config,
+ HookType::PreRemove,
+ HookSource::User,
+ &[],
+ HookFailureStrategy::FailFast,
+ name_filter,
+ )?;
+ }
- let Some(pre_remove_config) = &project_config.pre_remove else {
- return Ok(());
- };
+ // Then run project hooks (require approval)
+ let project_config = ctx.repo.load_project_config()?;
+
+ if let Some(pre_remove_config) = project_config.as_ref().and_then(|c| c.pre_remove.as_ref()) {
+ total_commands_run += pipeline.run_sequential(
+ pre_remove_config,
+ HookType::PreRemove,
+ HookSource::Project,
+ &[],
+ HookFailureStrategy::FailFast,
+ name_filter,
+ )?;
+ }
- let pipeline = HookPipeline::new(*ctx);
+ // If name filter was provided but no commands matched, error with available names
+ if let Some(name) = name_filter
+ && total_commands_run == 0
+ {
+ let mut available = Vec::new();
+ if let Some(config) = &ctx.config.pre_remove {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("user:{n}"))),
+ );
+ }
+ if let Some(config) = project_config.as_ref().and_then(|c| c.pre_remove.as_ref()) {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("project:{n}"))),
+ );
+ }
+ return Err(worktrunk::git::GitError::HookCommandNotFound {
+ name: name.to_string(),
+ available,
+ }
+ .into());
+ }
- pipeline.run_sequential(
- pre_remove_config,
- CommandPhase::PreRemove,
- auto_trust,
- &[],
- "pre-remove",
- HookType::PreRemove,
- HookFailureStrategy::FailFast,
- name_filter,
- )
+ Ok(())
}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 393eb67ec..6e4aacc8d 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -17,6 +17,7 @@ pub mod standalone;
pub mod statusline;
pub mod worktree;
+pub use command_approval::approve_hooks;
pub use config::{
handle_cache_clear, handle_cache_refresh, handle_cache_show, handle_config_create,
handle_config_show, handle_var_clear, handle_var_get, handle_var_set,
@@ -30,12 +31,12 @@ pub use merge::{execute_pre_remove_commands, handle_merge};
#[cfg(unix)]
pub use select::handle_select;
pub use standalone::{
- RebaseResult, SquashResult, handle_rebase, handle_squash, handle_standalone_add_approvals,
- handle_standalone_clear_approvals, handle_standalone_commit, handle_standalone_run_hook,
+ RebaseResult, SquashResult, add_approvals, clear_approvals, handle_hook_show, handle_rebase,
+ handle_squash, run_hook, step_commit,
};
pub use worktree::{
- handle_remove, handle_remove_by_path, handle_remove_current, handle_switch,
- resolve_worktree_path_first,
+ compute_worktree_path, handle_remove, handle_remove_by_path, handle_remove_current,
+ handle_switch, resolve_worktree_path_first,
};
// Re-export Shell from the canonical location
diff --git a/src/commands/standalone.rs b/src/commands/standalone.rs
index bc3510b0c..bcb10d851 100644
--- a/src/commands/standalone.rs
+++ b/src/commands/standalone.rs
@@ -1,11 +1,16 @@
use anyhow::Context;
use color_print::cformat;
+use std::fmt::Write as _;
use worktrunk::HookType;
+use worktrunk::config::{CommandConfig, ProjectConfig, WorktrunkConfig};
use worktrunk::git::Repository;
+use worktrunk::path::format_path_for_display;
use worktrunk::styling::{
- format_with_gutter, hint_message, info_message, progress_message, success_message,
+ HINT_EMOJI, INFO_EMOJI, PROMPT_EMOJI, format_bash_with_gutter, format_with_gutter,
+ hint_message, info_message, progress_message, success_message,
};
+use super::command_executor::CommandContext;
use super::commit::{CommitGenerator, CommitOptions};
use super::context::CommandEnv;
use super::hooks::HookPipeline;
@@ -16,46 +21,87 @@ use super::project_config::collect_commands_for_hooks;
use super::repository_ext::RepositoryCliExt;
/// Handle `wt hook` command
-pub fn handle_standalone_run_hook(
- hook_type: HookType,
- force: bool,
- name_filter: Option<&str>,
-) -> anyhow::Result<()> {
+///
+/// When explicitly invoking hooks, ALL hooks run (both user and project).
+/// There's no skip flag - if you explicitly run hooks, all configured hooks run.
+pub fn run_hook(hook_type: HookType, force: bool, name_filter: Option<&str>) -> anyhow::Result<()> {
+ use super::command_approval::approve_hooks_filtered;
+
// Derive context from current environment
let env = CommandEnv::for_action(&format!("run {hook_type} hook"))?;
let repo = &env.repo;
let ctx = env.context(force);
- // Load project config (show helpful error if missing)
- let project_config = repo.require_project_config()?;
+ // Load project config (optional - user hooks can run without project config)
+ let project_config = repo.load_project_config()?;
+
+ // "Approve at the Gate": approve project hooks upfront
+ // Get extra vars for template expansion based on hook type
+ // For wt hook pre-merge/post-merge, use current branch as target (not default branch)
+ // because we're testing hooks in the context of the current worktree
+ let default_branch = repo.default_branch().ok();
+ let extra_vars: Vec<(&str, &str)> = match hook_type {
+ HookType::PreCommit => {
+ // Pre-commit uses default branch as target (for comparison context)
+ default_branch
+ .as_deref()
+ .into_iter()
+ .map(|t| ("target", t))
+ .collect()
+ }
+ HookType::PreMerge | HookType::PostMerge => {
+ // Pre-merge and post-merge use current branch as target for testing
+ vec![("target", env.branch.as_str())]
+ }
+ _ => Vec::new(),
+ };
+ // Pass name_filter to only approve the targeted hook, not all hooks of this type
+ let approved = approve_hooks_filtered(&ctx, &[hook_type], &extra_vars, name_filter)?;
+ // If declined, return early - the whole point of `wt hook` is to run hooks
+ if !approved {
+ crate::output::print(worktrunk::styling::info_message("Commands declined"))?;
+ return Ok(());
+ }
// TODO: Add support for custom variable overrides (e.g., --var key=value)
// This would allow testing hooks with different contexts without being in that context
+ // Helper to get user hook config
+ macro_rules! user_hook {
+ ($field:ident) => {
+ ctx.config.$field.as_ref()
+ };
+ }
+
// Execute the hook based on type
match hook_type {
HookType::PostCreate => {
- check_hook_configured(&project_config.post_create, hook_type)?;
+ let user_config = user_hook!(post_create);
+ let project_config = project_config.as_ref().and_then(|c| c.post_create.as_ref());
run_hook_with_filter(
&ctx,
- &project_config.post_create,
+ user_config,
+ project_config,
hook_type,
&[],
name_filter,
)
}
HookType::PostStart => {
- check_hook_configured(&project_config.post_start, hook_type)?;
+ let user_config = user_hook!(post_start);
+ let project_config = project_config.as_ref().and_then(|c| c.post_start.as_ref());
run_hook_with_filter(
&ctx,
- &project_config.post_start,
+ user_config,
+ project_config,
hook_type,
&[],
name_filter,
)
}
HookType::PreCommit => {
- check_hook_configured(&project_config.pre_commit, hook_type)?;
+ let user_config = user_hook!(pre_commit);
+ let project_config = project_config.as_ref().and_then(|c| c.pre_commit.as_ref());
// Pre-commit hook can optionally use target branch context
let target_branch = repo.default_branch().ok();
let extra_vars: Vec<(&str, &str)> = target_branch
@@ -65,93 +111,144 @@ pub fn handle_standalone_run_hook(
.collect();
run_hook_with_filter(
&ctx,
- &project_config.pre_commit,
+ user_config,
+ project_config,
hook_type,
&extra_vars,
name_filter,
)
}
HookType::PreMerge => {
- check_hook_configured(&project_config.pre_merge, hook_type)?;
- // Use current branch as target - when running standalone, the "target"
- // represents what branch we're on (vs. in `wt merge` where it's the
- // branch being merged into)
- run_pre_merge_commands(&project_config, &ctx, &env.branch, false, name_filter)
+ // pre-merge, post-merge, pre-remove use functions from merge.rs
+ // which already handle user hooks (approval already happened at gate)
+ // Use current branch as target (matches approval prompt for wt hook)
+ let project_cfg = project_config.unwrap_or_default();
+ run_pre_merge_commands(&project_cfg, &ctx, &env.branch, name_filter)
}
HookType::PostMerge => {
- check_hook_configured(&project_config.post_merge, hook_type)?;
- // Use current branch as target - when running standalone, the "target"
- // represents what branch we're on (vs. in `wt merge` where it's the
- // branch being merged into)
- execute_post_merge_commands(&ctx, &env.branch, false, name_filter)
- }
- HookType::PreRemove => {
- check_hook_configured(&project_config.pre_remove, hook_type)?;
- execute_pre_remove_commands(&ctx, false, name_filter)
+ // Use current branch as target (matches approval prompt for wt hook)
+ execute_post_merge_commands(&ctx, &env.branch, name_filter)
}
+ HookType::PreRemove => execute_pre_remove_commands(&ctx, name_filter),
}
}
-/// Run a hook with optional name filter (used by standalone hook commands)
+/// Run user and project hooks with optional name filter (used by standalone hook commands)
+///
+/// Runs user hooks first, then project hooks.
+/// Returns an error if no hooks are configured for this hook type.
fn run_hook_with_filter(
ctx: &super::command_executor::CommandContext,
- config: &Option<worktrunk::config::CommandConfig>,
+ user_config: Option<&worktrunk::config::CommandConfig>,
+ project_config: Option<&worktrunk::config::CommandConfig>,
hook_type: HookType,
extra_vars: &[(&str, &str)],
name_filter: Option<&str>,
) -> anyhow::Result<()> {
- use super::hooks::{HookFailureStrategy, HookPipeline};
- use worktrunk::config::CommandPhase;
+ use super::hooks::{HookFailureStrategy, HookPipeline, HookSource};
- let Some(command_config) = config else {
- return Ok(());
- };
+ // Check at least one hook is configured
+ if user_config.is_none() && project_config.is_none() {
+ return Err(worktrunk::git::GitError::Other {
+ message: format!("No {hook_type} hook configured (neither user nor project)"),
+ }
+ .into());
+ }
let pipeline = HookPipeline::new(*ctx);
- let phase = match hook_type {
- HookType::PostCreate => CommandPhase::PostCreate,
- HookType::PostStart => CommandPhase::PostStart,
- HookType::PreCommit => CommandPhase::PreCommit,
- HookType::PreMerge => CommandPhase::PreMerge,
- HookType::PostMerge => CommandPhase::PostMerge,
- HookType::PreRemove => CommandPhase::PreRemove,
- };
- let label = hook_type.to_string().to_lowercase().replace(' ', "-");
-
- pipeline.run_sequential(
- command_config,
- phase,
- false, // auto_trust=false, require approval for standalone
- extra_vars,
- &label,
- hook_type,
- HookFailureStrategy::FailFast,
- name_filter,
- )
-}
+ let mut total_commands_run = 0;
+
+ // Run user hooks first (no approval required)
+ if let Some(config) = user_config {
+ total_commands_run += pipeline.run_sequential(
+ config,
+ hook_type,
+ HookSource::User,
+ extra_vars,
+ HookFailureStrategy::FailFast,
+ name_filter,
+ )?;
+ }
-fn check_hook_configured<T>(hook: &Option<T>, hook_type: HookType) -> anyhow::Result<()> {
- if hook.is_none() {
- return Err(worktrunk::git::GitError::Other {
- message: format!("No {hook_type} hook configured"),
+ // Then run project hooks (approval already happened at gate)
+ if let Some(config) = project_config {
+ total_commands_run += pipeline.run_sequential(
+ config,
+ hook_type,
+ HookSource::Project,
+ extra_vars,
+ HookFailureStrategy::FailFast,
+ name_filter,
+ )?;
+ }
+
+ // If name filter was provided but no commands matched, error with available names
+ if let Some(name) = name_filter
+ && total_commands_run == 0
+ {
+ let mut available = Vec::new();
+ if let Some(config) = user_config {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("user:{n}"))),
+ );
+ }
+ if let Some(config) = project_config {
+ available.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|c| c.name.as_ref().map(|n| format!("project:{n}"))),
+ );
+ }
+ return Err(worktrunk::git::GitError::HookCommandNotFound {
+ name: name.to_string(),
+ available,
}
.into());
}
+
Ok(())
}
/// Handle `wt step commit` command
-pub fn handle_standalone_commit(
+pub fn step_commit(
force: bool,
no_verify: bool,
stage_mode: super::commit::StageMode,
) -> anyhow::Result<()> {
+ use super::command_approval::approve_hooks;
+
let env = CommandEnv::for_action("commit")?;
let ctx = env.context(force);
+
+ // "Approve at the Gate": approve pre-commit hooks upfront (unless --no-verify)
+ // Shadow no_verify: if user declines approval, skip hooks but continue commit
+ let no_verify = if !no_verify {
+ let target_branch = env.repo.default_branch().ok();
+ let extra_vars: Vec<(&str, &str)> = target_branch
+ .as_deref()
+ .into_iter()
+ .map(|t| ("target", t))
+ .collect();
+ let approved = approve_hooks(&ctx, &[HookType::PreCommit], &extra_vars)?;
+ if !approved {
+ crate::output::print(worktrunk::styling::info_message(
+ "Commands declined, committing without hooks",
+ ))?;
+ true // Skip hooks
+ } else {
+ false // Run hooks
+ }
+ } else {
+ true // --no-verify was passed
+ };
+
let mut options = CommitOptions::new(&ctx);
options.no_verify = no_verify;
options.stage_mode = stage_mode;
- options.auto_trust = false;
options.show_no_squash_note = false;
// Only warn about untracked if we're staging all
options.warn_about_untracked = stage_mode == super::commit::StageMode::All;
@@ -175,13 +272,12 @@ pub enum SquashResult {
/// Handle shared squash workflow (used by `wt step squash` and `wt merge`)
///
/// # Arguments
-/// * `auto_trust` - If true, skip approval prompts for pre-commit commands (already approved in batch)
+/// * `skip_pre_commit` - If true, skip all pre-commit hooks (both user and project)
/// * `stage_mode` - What to stage before committing (All or Tracked; None not supported for squash)
pub fn handle_squash(
target: Option<&str>,
force: bool,
skip_pre_commit: bool,
- auto_trust: bool,
stage_mode: super::commit::StageMode,
) -> anyhow::Result<SquashResult> {
use super::commit::StageMode;
@@ -211,19 +307,40 @@ pub fn handle_squash(
}
}
- // Run pre-commit hook unless explicitly skipped
+ // Run pre-commit hooks unless explicitly skipped
let project_config = repo.load_project_config()?;
- let has_pre_commit = project_config
+ let has_project_pre_commit = project_config
.as_ref()
.map(|c| c.pre_commit.is_some())
.unwrap_or(false);
+ let has_user_pre_commit = ctx.config.pre_commit.is_some();
+ let has_any_pre_commit = has_project_pre_commit || has_user_pre_commit;
- if skip_pre_commit && has_pre_commit {
+ if skip_pre_commit && has_any_pre_commit {
crate::output::print(hint_message(cformat!(
- "Skipping pre-commit hook (<bright-black>--no-verify</>)"
+ "Skipping pre-commit hooks (<bright-black>--no-verify</>)"
)))?;
- } else if let Some(ref config) = project_config {
- HookPipeline::new(ctx).run_pre_commit(config, Some(&target_branch), auto_trust, None)?;
+ }
+
+ let pipeline = HookPipeline::new(ctx);
+ let extra_vars = [("target", target_branch.as_str())];
+
+ // Run user pre-commit hooks first (unless skipped)
+ if !skip_pre_commit && let Some(user_config) = &ctx.config.pre_commit {
+ use super::hooks::{HookFailureStrategy, HookSource};
+ pipeline.run_sequential(
+ user_config,
+ HookType::PreCommit,
+ HookSource::User,
+ &extra_vars,
+ HookFailureStrategy::FailFast,
+ None,
+ )?;
+ }
+
+ // Then run project pre-commit hooks (unless skipped)
+ if !skip_pre_commit && let Some(ref config) = project_config {
+ pipeline.run_pre_commit(config, Some(&target_branch), None)?;
}
// Get merge base with target branch
@@ -443,7 +560,7 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
}
/// Handle `wt config approvals add` command - approve all commands in the project
-pub fn handle_standalone_add_approvals(force: bool, show_all: bool) -> anyhow::Result<()> {
+pub fn add_approvals(force: bool, show_all: bool) -> anyhow::Result<()> {
use super::command_approval::approve_command_batch;
use worktrunk::config::WorktrunkConfig;
@@ -509,7 +626,7 @@ pub fn handle_standalone_add_approvals(force: bool, show_all: bool) -> anyhow::R
}
/// Handle `wt config approvals clear` command - clear approved commands
-pub fn handle_standalone_clear_approvals(global: bool) -> anyhow::Result<()> {
+pub fn clear_approvals(global: bool) -> anyhow::Result<()> {
use worktrunk::config::WorktrunkConfig;
let mut config = WorktrunkConfig::load().context("Failed to load config")?;
@@ -562,3 +679,267 @@ pub fn handle_standalone_clear_approvals(global: bool) -> anyhow::Result<()> {
Ok(())
}
+
+/// Handle `wt hook show` command - display configured hooks
+pub fn handle_hook_show(hook_type_filter: Option<&str>, expanded: bool) -> anyhow::Result<()> {
+ use crate::help_pager::show_help_in_pager;
+
+ let repo = Repository::current();
+ let config = WorktrunkConfig::load().context("Failed to load user config")?;
+ let project_config = repo.load_project_config()?;
+ let project_id = repo.project_identifier().ok();
+
+ // Parse hook type filter if provided
+ let filter: Option<HookType> = hook_type_filter.map(|s| match s {
+ "post-create" => HookType::PostCreate,
+ "post-start" => HookType::PostStart,
+ "pre-commit" => HookType::PreCommit,
+ "pre-merge" => HookType::PreMerge,
+ "post-merge" => HookType::PostMerge,
+ "pre-remove" => HookType::PreRemove,
+ _ => unreachable!("clap validates hook type"),
+ });
+
+ // Build context for template expansion (only used if --expanded)
+ // Need to keep CommandEnv alive for the lifetime of ctx
+ let env = if expanded {
+ Some(CommandEnv::for_action("show hooks")?)
+ } else {
+ None
+ };
+ let ctx = env.as_ref().map(|e| e.context(false));
+
+ let mut output = String::new();
+
+ // Render user hooks
+ render_user_hooks(&mut output, &config, filter, ctx.as_ref())?;
+ output.push('\n');
+
+ // Render project hooks
+ render_project_hooks(
+ &mut output,
+ &repo,
+ project_config.as_ref(),
+ &config,
+ project_id.as_deref(),
+ filter,
+ ctx.as_ref(),
+ )?;
+
+ // Display through pager (fall back to stderr if pager unavailable)
+ if show_help_in_pager(&output).is_err() {
+ worktrunk::styling::eprintln!("{}", output);
+ }
+
+ Ok(())
+}
+
+/// Render user hooks section
+fn render_user_hooks(
+ out: &mut String,
+ config: &WorktrunkConfig,
+ filter: Option<HookType>,
+ ctx: Option<&CommandContext>,
+) -> anyhow::Result<()> {
+ let config_path = worktrunk::config::get_config_path();
+
+ writeln!(
+ out,
+ "{}",
+ cformat!(
+ "{INFO_EMOJI} User Hooks: <bold>{}</>",
+ config_path
+ .as_ref()
+ .map(|p| format_path_for_display(p))
+ .unwrap_or_else(|| "(not found)".to_string())
+ )
+ )?;
+
+ // Collect all user hooks
+ let hooks = [
+ (HookType::PostCreate, &config.post_create),
+ (HookType::PostStart, &config.post_start),
+ (HookType::PreCommit, &config.pre_commit),
+ (HookType::PreMerge, &config.pre_merge),
+ (HookType::PostMerge, &config.post_merge),
+ (HookType::PreRemove, &config.pre_remove),
+ ];
+
+ let mut has_any = false;
+ for (hook_type, hook_config) in hooks {
+ // Apply filter if specified
+ if let Some(f) = filter
+ && f != hook_type
+ {
+ continue;
+ }
+
+ if let Some(cfg) = hook_config {
+ has_any = true;
+ render_hook_commands(out, hook_type, cfg, None, ctx)?;
+ }
+ }
+
+ if !has_any {
+ writeln!(
+ out,
+ "{}",
+ cformat!("{HINT_EMOJI} <dim>(none configured)</>")
+ )?;
+ }
+
+ Ok(())
+}
+
+/// Render project hooks section
+fn render_project_hooks(
+ out: &mut String,
+ repo: &Repository,
+ project_config: Option<&ProjectConfig>,
+ user_config: &WorktrunkConfig,
+ project_id: Option<&str>,
+ filter: Option<HookType>,
+ ctx: Option<&CommandContext>,
+) -> anyhow::Result<()> {
+ let repo_root = repo.worktree_root()?;
+ let config_path = repo_root.join(".config").join("wt.toml");
+
+ writeln!(
+ out,
+ "{}",
+ cformat!(
+ "{INFO_EMOJI} Project Hooks: <bold>{}</>",
+ format_path_for_display(&config_path)
+ )
+ )?;
+
+ let Some(config) = project_config else {
+ writeln!(out, "{}", cformat!("{HINT_EMOJI} <dim>(not found)</>"))?;
+ return Ok(());
+ };
+
+ // Collect all project hooks
+ let hooks = [
+ (HookType::PostCreate, &config.post_create),
+ (HookType::PostStart, &config.post_start),
+ (HookType::PreCommit, &config.pre_commit),
+ (HookType::PreMerge, &config.pre_merge),
+ (HookType::PostMerge, &config.post_merge),
+ (HookType::PreRemove, &config.pre_remove),
+ ];
+
+ let mut has_any = false;
+ for (hook_type, hook_config) in hooks {
+ // Apply filter if specified
+ if let Some(f) = filter
+ && f != hook_type
+ {
+ continue;
+ }
+
+ if let Some(cfg) = hook_config {
+ has_any = true;
+ render_hook_commands(out, hook_type, cfg, Some((user_config, project_id)), ctx)?;
+ }
+ }
+
+ if !has_any {
+ writeln!(
+ out,
+ "{}",
+ cformat!("{HINT_EMOJI} <dim>(none configured)</>")
+ )?;
+ }
+
+ Ok(())
+}
+
+/// Render commands for a single hook type
+fn render_hook_commands(
+ out: &mut String,
+ hook_type: HookType,
+ config: &CommandConfig,
+ // For project hooks: (user_config, project_id) to check approval status
+ approval_context: Option<(&WorktrunkConfig, Option<&str>)>,
+ ctx: Option<&CommandContext>,
+) -> anyhow::Result<()> {
+ let commands = config.commands();
+ if commands.is_empty() {
+ return Ok(());
+ }
+
+ for cmd in commands {
+ // Build label: "hook-type name:" or "hook-type:"
+ let label = match &cmd.name {
+ Some(name) => cformat!("{hook_type} <bold>{name}</>:"),
+ None => format!("{hook_type}:"),
+ };
+
+ // Check approval status for project hooks
+ let needs_approval = if let Some((user_config, Some(project_id))) = approval_context {
+ !user_config.is_command_approved(project_id, &cmd.template)
+ } else {
+ false
+ };
+
+ // Use ❓ for needs approval, ⚪ for approved/user hooks
+ let (emoji, suffix) = if needs_approval {
+ (PROMPT_EMOJI, cformat!(" <dim>(requires approval)</>"))
+ } else {
+ (INFO_EMOJI, String::new())
+ };
+
+ writeln!(out, "{emoji} {label}{suffix}")?;
+
+ // Show template or expanded command
+ let command_text = if let Some(command_ctx) = ctx {
+ // Expand template with current context
+ expand_command_template(&cmd.template, command_ctx, hook_type)
+ } else {
+ cmd.template.clone()
+ };
+
+ write!(out, "{}", format_bash_with_gutter(&command_text, ""))?;
+ }
+
+ Ok(())
+}
+
+/// Expand a command template with context variables
+fn expand_command_template(template: &str, ctx: &CommandContext, hook_type: HookType) -> String {
+ use super::command_executor::build_hook_context;
+
+ // Build extra vars based on hook type (same logic as run_hook approval)
+ let default_branch = ctx.repo.default_branch().ok();
+ let extra_vars: Vec<(&str, &str)> = match hook_type {
+ HookType::PreCommit => {
+ // Pre-commit uses default branch as target (for comparison context)
+ default_branch
+ .as_deref()
+ .into_iter()
+ .map(|t| ("target", t))
+ .collect()
+ }
+ HookType::PreMerge | HookType::PostMerge => {
+ // Pre-merge and post-merge use current branch as target
+ vec![("target", ctx.branch)]
+ }
+ _ => Vec::new(),
+ };
+ let template_ctx = build_hook_context(ctx, &extra_vars);
+
+ // Use the standard template expansion
+ worktrunk::config::expand_template(
+ template,
+ ctx.repo_root
+ .file_name()
+ .and_then(|n| n.to_str())
+ .unwrap_or("unknown"),
+ ctx.branch,
+ &template_ctx
+ .iter()
+ .map(|(k, v)| (k.as_str(), v.as_str()))
+ .collect(),
+ )
+ .unwrap_or_else(|_| template.to_string())
+}
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 8a99dbbf6..4f39e5aa5 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -114,15 +114,15 @@ use color_print::cformat;
use normalize_path::NormalizePath;
use std::path::PathBuf;
use worktrunk::HookType;
-use worktrunk::config::{CommandPhase, WorktrunkConfig};
-use worktrunk::git::{GitError, Repository, ResolvedWorktree, is_command_not_approved};
+use worktrunk::config::WorktrunkConfig;
+use worktrunk::git::{GitError, Repository, ResolvedWorktree};
use worktrunk::styling::{
format_with_gutter, hint_message, info_message, progress_message, success_message,
warning_message,
};
use super::command_executor::CommandContext;
-use super::hooks::{HookFailureStrategy, HookPipeline};
+use super::hooks::{HookFailureStrategy, HookPipeline, HookSource};
use super::repository_ext::RepositoryCliExt;
/// Resolve a worktree argument using path-first lookup.
@@ -206,7 +206,7 @@ pub fn resolve_worktree_path_first(
}
/// Compute the expected worktree path for a branch name.
-fn compute_worktree_path(
+pub fn compute_worktree_path(
repo: &Repository,
branch: &str,
config: &WorktrunkConfig,
@@ -493,17 +493,8 @@ pub fn handle_switch(
&repo_root,
force,
);
- if let Err(e) = ctx.execute_post_create_commands() {
- // Only treat CommandNotApproved as non-fatal (user declined)
- // Other errors should still fail
- if is_command_not_approved(&e) {
- crate::output::print(info_message(
- "Commands declined, continuing worktree creation",
- ))?;
- } else {
- return Err(e);
- }
- }
+ // Approval was handled at the gate
+ ctx.execute_post_create_commands(true)?;
}
// Note: post-start commands are spawned AFTER success message is shown
@@ -600,7 +591,28 @@ pub fn handle_remove_by_path(
impl<'a> CommandContext<'a> {
/// Execute post-create commands sequentially (blocking)
- pub fn execute_post_create_commands(&self) -> anyhow::Result<()> {
+ ///
+ /// Runs user hooks first, then project hooks. Skips all hooks if verify is false.
+ pub fn execute_post_create_commands(&self, verify: bool) -> anyhow::Result<()> {
+ if !verify {
+ return Ok(());
+ }
+
+ let pipeline = HookPipeline::new(*self);
+
+ // Run user hooks first (no approval required)
+ if let Some(user_config) = &self.config.post_create {
+ pipeline.run_sequential(
+ user_config,
+ HookType::PostCreate,
+ HookSource::User,
+ &[],
+ HookFailureStrategy::Warn,
+ None,
+ )?;
+ }
+
+ // Then run project hooks (approval checked at gate, not here)
let project_config = match self.repo.load_project_config()? {
Some(cfg) => cfg,
None => return Ok(()),
@@ -610,21 +622,39 @@ impl<'a> CommandContext<'a> {
return Ok(());
};
- let pipeline = HookPipeline::new(*self);
pipeline.run_sequential(
post_create_config,
- CommandPhase::PostCreate,
- false,
- &[],
- "post-create",
HookType::PostCreate,
+ HookSource::Project,
+ &[],
HookFailureStrategy::Warn,
None,
- )
+ )?;
+ Ok(())
}
/// Spawn post-start commands in parallel as background processes (non-blocking)
- pub fn spawn_post_start_commands(&self) -> anyhow::Result<()> {
+ ///
+ /// Spawns user hooks first, then project hooks. Skips all hooks if verify is false.
+ pub fn spawn_post_start_commands(&self, verify: bool) -> anyhow::Result<()> {
+ if !verify {
+ return Ok(());
+ }
+
+ let pipeline = HookPipeline::new(*self);
+
+ // Spawn user hooks first (no approval required)
+ if let Some(user_config) = &self.config.post_start {
+ pipeline.spawn_background(
+ user_config,
+ HookType::PostStart,
+ HookSource::User,
+ &[],
+ None,
+ )?;
+ }
+
+ // Then spawn project hooks (approval checked at gate, not here)
let project_config = match self.repo.load_project_config()? {
Some(cfg) => cfg,
None => return Ok(()),
@@ -634,13 +664,11 @@ impl<'a> CommandContext<'a> {
return Ok(());
};
- let pipeline = HookPipeline::new(*self);
- pipeline.spawn_detached(
+ pipeline.spawn_background(
post_start_config,
- CommandPhase::PostStart,
- false,
+ HookType::PostStart,
+ HookSource::Project,
&[],
- "post-start",
None,
)
}
diff --git a/src/completion.rs b/src/completion.rs
index fb5b64f59..30da906de 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -8,7 +8,7 @@ use clap_complete::env::CompleteEnv;
use crate::cli;
use crate::display::format_relative_time_short;
-use worktrunk::config::ProjectConfig;
+use worktrunk::config::{ProjectConfig, WorktrunkConfig};
use worktrunk::git::{BranchCategory, Repository};
/// Args that should never appear in completions, even when all options are shown.
@@ -227,39 +227,58 @@ fn complete_hook_commands() -> Vec<CompletionCandidate> {
return Vec::new();
};
- // Load project config
- let repo = Repository::current();
- let repo_root = match repo.worktree_root() {
- Ok(root) => root,
- Err(_) => return Vec::new(),
- };
+ let mut candidates = Vec::new();
+
+ // Load user config and add user hook names
+ if let Ok(user_config) = WorktrunkConfig::load() {
+ let user_command_config = match hook_type {
+ "post-create" => &user_config.post_create,
+ "post-start" => &user_config.post_start,
+ "pre-commit" => &user_config.pre_commit,
+ "pre-merge" => &user_config.pre_merge,
+ "post-merge" => &user_config.post_merge,
+ "pre-remove" => &user_config.pre_remove,
+ _ => &None,
+ };
- let project_config = match ProjectConfig::load(&repo_root) {
- Ok(Some(config)) => config,
- _ => return Vec::new(),
- };
+ if let Some(config) = user_command_config {
+ candidates.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|cmd| cmd.name.as_ref())
+ .map(|name| CompletionCandidate::new(name.clone())),
+ );
+ }
+ }
- // Get command names for the hook type
- let command_config = match hook_type {
- "post-create" => &project_config.post_create,
- "post-start" => &project_config.post_start,
- "pre-commit" => &project_config.pre_commit,
- "pre-merge" => &project_config.pre_merge,
- "post-merge" => &project_config.post_merge,
- "pre-remove" => &project_config.pre_remove,
- _ => return Vec::new(),
- };
+ // Load project config and add project hook names
+ let repo = Repository::current();
+ if let Ok(repo_root) = repo.worktree_root()
+ && let Ok(Some(project_config)) = ProjectConfig::load(&repo_root)
+ {
+ let project_command_config = match hook_type {
+ "post-create" => &project_config.post_create,
+ "post-start" => &project_config.post_start,
+ "pre-commit" => &project_config.pre_commit,
+ "pre-merge" => &project_config.pre_merge,
+ "post-merge" => &project_config.post_merge,
+ "pre-remove" => &project_config.pre_remove,
+ _ => &None,
+ };
- let Some(config) = command_config else {
- return Vec::new();
- };
+ if let Some(config) = project_command_config {
+ candidates.extend(
+ config
+ .commands()
+ .iter()
+ .filter_map(|cmd| cmd.name.as_ref())
+ .map(|name| CompletionCandidate::new(name.clone())),
+ );
+ }
+ }
- config
- .commands()
- .iter()
- .filter_map(|cmd| cmd.name.as_ref())
- .map(|name| CompletionCandidate::new(name.clone()))
- .collect()
+ candidates
}
#[derive(Clone, Copy)]
diff --git a/src/config/mod.rs b/src/config/mod.rs
index e4a02d424..554a50c47 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -723,4 +723,64 @@ squash-template-file = "~/file.txt"
assert!(unknown_project.is_empty());
assert!(unknown_user.is_empty());
}
+
+ #[test]
+ fn test_user_hooks_config_parsing() {
+ let toml_str = r#"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-create]
+log = "echo '{{ repo }}' >> ~/.log"
+
+[pre-merge]
+test = "cargo test"
+lint = "cargo clippy"
+"#;
+ let config: WorktrunkConfig = toml::from_str(toml_str).unwrap();
+
+ // Check post-create
+ let post_create = config.post_create.expect("post-create should be present");
+ let commands = post_create.commands();
+ assert_eq!(commands.len(), 1);
+ assert_eq!(commands[0].name.as_deref(), Some("log"));
+
+ // Check pre-merge (multiple commands preserve order)
+ let pre_merge = config.pre_merge.expect("pre-merge should be present");
+ let commands = pre_merge.commands();
+ assert_eq!(commands.len(), 2);
+ assert_eq!(commands[0].name.as_deref(), Some("test"));
+ assert_eq!(commands[1].name.as_deref(), Some("lint"));
+ }
+
+ #[test]
+ fn test_user_hooks_config_single_command() {
+ let toml_str = r#"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
+post-create = "npm install"
+"#;
+ let config: WorktrunkConfig = toml::from_str(toml_str).unwrap();
+
+ let post_create = config.post_create.expect("post-create should be present");
+ let commands = post_create.commands();
+ assert_eq!(commands.len(), 1);
+ assert!(commands[0].name.is_none()); // single command has no name
+ assert_eq!(commands[0].template, "npm install");
+ }
+
+ #[test]
+ fn test_user_hooks_not_reported_as_unknown() {
+ let toml_str = r#"
+worktree-path = "../test"
+post-create = "npm install"
+
+[pre-merge]
+test = "cargo test"
+"#;
+ let unknown = find_unknown_user_keys(toml_str);
+ assert!(
+ unknown.is_empty(),
+ "hook fields should not be reported as unknown: {:?}",
+ unknown
+ );
+ }
}
diff --git a/src/config/user.rs b/src/config/user.rs
index ba9f27fcf..cc2b628ea 100644
--- a/src/config/user.rs
+++ b/src/config/user.rs
@@ -7,6 +7,8 @@ use serde::{Deserialize, Deserializer, Serialize};
use std::path::PathBuf;
use std::sync::OnceLock;
+use super::commands::CommandConfig;
+
/// Deserialize a Vec<String> that can also accept a single String
/// This enables setting array config fields via environment variables
fn deserialize_string_or_vec<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
@@ -146,6 +148,53 @@ pub struct WorktrunkConfig {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub merge: Option<MergeConfig>,
+ // =========================================================================
+ // User-level hooks (same syntax as project hooks, run before project hooks)
+ // =========================================================================
+ /// Commands to execute after worktree creation (blocking)
+ #[serde(
+ default,
+ rename = "post-create",
+ skip_serializing_if = "Option::is_none"
+ )]
+ pub post_create: Option<CommandConfig>,
+
+ /// Commands to execute after worktree creation (background)
+ #[serde(
+ default,
+ rename = "post-start",
+ skip_serializing_if = "Option::is_none"
+ )]
+ pub post_start: Option<CommandConfig>,
+
+ /// Commands to execute before committing during merge (blocking, fail-fast)
+ #[serde(
+ default,
+ rename = "pre-commit",
+ skip_serializing_if = "Option::is_none"
+ )]
+ pub pre_commit: Option<CommandConfig>,
+
+ /// Commands to execute before merging (blocking, fail-fast)
+ #[serde(default, rename = "pre-merge", skip_serializing_if = "Option::is_none")]
+ pub pre_merge: Option<CommandConfig>,
+
+ /// Commands to execute after successful merge (blocking, best-effort)
+ #[serde(
+ default,
+ rename = "post-merge",
+ skip_serializing_if = "Option::is_none"
+ )]
+ pub post_merge: Option<CommandConfig>,
+
+ /// Commands to execute before worktree removal (blocking, fail-fast)
+ #[serde(
+ default,
+ rename = "pre-remove",
+ skip_serializing_if = "Option::is_none"
+ )]
+ pub pre_remove: Option<CommandConfig>,
+
/// Captures unknown fields for validation warnings
#[serde(flatten, default, skip_serializing)]
pub(crate) unknown: std::collections::HashMap<String, toml::Value>,
@@ -284,6 +333,12 @@ impl Default for WorktrunkConfig {
list: None,
commit: None,
merge: None,
+ post_create: None,
+ post_start: None,
+ pre_commit: None,
+ pre_merge: None,
+ post_merge: None,
+ pre_remove: None,
unknown: std::collections::HashMap::new(),
}
}
diff --git a/src/main.rs b/src/main.rs
index 1bc293990..98ceb697c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,7 @@ use color_print::cformat;
use std::path::PathBuf;
use std::process;
use worktrunk::config::{WorktrunkConfig, set_config_path};
-use worktrunk::git::{Repository, exit_code, is_command_not_approved, set_base_path};
+use worktrunk::git::{Repository, exit_code, set_base_path};
use worktrunk::path::format_path_for_display;
use worktrunk::styling::{
format_with_gutter, hint_message, info_message, println, success_message, warning_message,
@@ -26,13 +26,13 @@ use commands::command_executor::CommandContext;
use commands::handle_select;
use commands::worktree::{SwitchResult, handle_push};
use commands::{
- ConfigAction, RebaseResult, SquashResult, handle_cache_clear, handle_cache_refresh,
- handle_cache_show, handle_config_create, handle_config_show, handle_configure_shell,
+ ConfigAction, RebaseResult, SquashResult, add_approvals, approve_hooks, clear_approvals,
+ compute_worktree_path, handle_cache_clear, handle_cache_refresh, handle_cache_show,
+ handle_config_create, handle_config_show, handle_configure_shell, handle_hook_show,
handle_init, handle_list, handle_merge, handle_rebase, handle_remove, handle_remove_by_path,
- handle_remove_current, handle_show_theme, handle_squash, handle_standalone_add_approvals,
- handle_standalone_clear_approvals, handle_standalone_commit, handle_standalone_run_hook,
- handle_switch, handle_unconfigure_shell, handle_var_clear, handle_var_get, handle_var_set,
- resolve_worktree_path_first,
+ handle_remove_current, handle_show_theme, handle_squash, handle_switch,
+ handle_unconfigure_shell, handle_var_clear, handle_var_get, handle_var_set,
+ resolve_worktree_path_first, run_hook, step_commit,
};
use output::{execute_user_command, handle_remove_output, handle_switch_output};
@@ -892,8 +892,8 @@ fn main() {
VarCommand::Clear { key, branch, all } => handle_var_clear(&key, branch, all),
},
ConfigCommand::Approvals { action } => match action {
- ApprovalsCommand::Add { force, all } => handle_standalone_add_approvals(force, all),
- ApprovalsCommand::Clear { global } => handle_standalone_clear_approvals(global),
+ ApprovalsCommand::Add { force, all } => add_approvals(force, all),
+ ApprovalsCommand::Clear { global } => clear_approvals(global),
},
},
Commands::Step { action } => match action {
@@ -907,7 +907,7 @@ fn main() {
let stage_final = stage
.or_else(|| config.commit.and_then(|c| c.stage))
.unwrap_or_default();
- handle_standalone_commit(force, !verify, stage_final)
+ step_commit(force, !verify, stage_final)
}),
StepCommand::Squash {
target,
@@ -920,7 +920,32 @@ fn main() {
let stage_final = stage
.or_else(|| config.commit.and_then(|c| c.stage))
.unwrap_or_default();
- match handle_squash(target.as_deref(), force, !verify, false, stage_final)? {
+
+ // "Approve at the Gate": approve pre-commit hooks upfront (unless --no-verify)
+ // Shadow verify: if user declines approval, skip hooks but continue squash
+ let verify = if verify {
+ use commands::command_approval::approve_hooks;
+ use commands::context::CommandEnv;
+ let env = CommandEnv::for_action("squash")?;
+ let ctx = env.context(force);
+ let target_branch = env.repo.default_branch().ok();
+ let extra_vars: Vec<(&str, &str)> = target_branch
+ .as_deref()
+ .into_iter()
+ .map(|t| ("target", t))
+ .collect();
+ let approved = approve_hooks(&ctx, &[HookType::PreCommit], &extra_vars)?;
+ if !approved {
+ crate::output::print(info_message(
+ "Commands declined, squashing without hooks",
+ ))?;
+ }
+ approved
+ } else {
+ false
+ };
+
+ match handle_squash(target.as_deref(), force, !verify, stage_final)? {
SquashResult::Squashed | SquashResult::NoNetChanges => {}
SquashResult::NoCommitsAhead(branch) => {
crate::output::print(info_message(format!(
@@ -952,23 +977,27 @@ fn main() {
}
},
Commands::Hook { action } => match action {
+ HookCommand::Show {
+ hook_type,
+ expanded,
+ } => handle_hook_show(hook_type.as_deref(), expanded),
HookCommand::PostCreate { name, force } => {
- handle_standalone_run_hook(HookType::PostCreate, force, name.as_deref())
+ run_hook(HookType::PostCreate, force, name.as_deref())
}
HookCommand::PostStart { name, force } => {
- handle_standalone_run_hook(HookType::PostStart, force, name.as_deref())
+ run_hook(HookType::PostStart, force, name.as_deref())
}
HookCommand::PreCommit { name, force } => {
- handle_standalone_run_hook(HookType::PreCommit, force, name.as_deref())
+ run_hook(HookType::PreCommit, force, name.as_deref())
}
HookCommand::PreMerge { name, force } => {
- handle_standalone_run_hook(HookType::PreMerge, force, name.as_deref())
+ run_hook(HookType::PreMerge, force, name.as_deref())
}
HookCommand::PostMerge { name, force } => {
- handle_standalone_run_hook(HookType::PostMerge, force, name.as_deref())
+ run_hook(HookType::PostMerge, force, name.as_deref())
}
HookCommand::PreRemove { name, force } => {
- handle_standalone_run_hook(HookType::PreRemove, force, name.as_deref())
+ run_hook(HookType::PreRemove, force, name.as_deref())
}
},
#[cfg(unix)]
@@ -1038,9 +1067,40 @@ fn main() {
} => WorktrunkConfig::load()
.context("Failed to load config")
.and_then(|config| {
- // Execute switch operation (creates worktree, runs post-create hooks)
+ // "Approve at the Gate": collect and approve hooks upfront when creating
+ // This ensures approval happens once at the command entry point
+ // If user declines, skip hooks but continue with worktree creation
+ let approved = if create && verify {
+ let repo = Repository::current();
+ let repo_root = repo.worktree_base()?;
+ // Compute worktree path for template expansion in approval prompt
+ let worktree_path = compute_worktree_path(&repo, &branch, &config)?;
+ let ctx = CommandContext::new(
+ &repo,
+ &config,
+ &branch,
+ &worktree_path,
+ &repo_root,
+ force,
+ );
+ approve_hooks(&ctx, &[HookType::PostCreate, HookType::PostStart], &[])?
+ } else {
+ true // No hooks to approve = considered approved
+ };
+
+ // Skip hooks if --no-hooks or user declined approval
+ let skip_hooks = !verify || !approved;
+
+ // Show message if user declined approval
+ if !approved {
+ crate::output::print(info_message(
+ "Commands declined, continuing worktree creation",
+ ))?;
+ }
+
+ // Execute switch operation (creates worktree, runs post-create hooks if approved)
let (result, resolved_branch) =
- handle_switch(&branch, create, base.as_deref(), force, !verify, &config)?;
+ handle_switch(&branch, create, base.as_deref(), force, skip_hooks, &config)?;
// Show success message (temporal locality: immediately after worktree creation)
// Pass cli.internal to indicate whether shell integration is active
@@ -1048,8 +1108,8 @@ fn main() {
// Now spawn post-start hooks (background processes, after success message)
// Only run post-start commands when creating a NEW worktree, not when switching to existing
- // Note: If user declines post-start commands, continue anyway - they're optional
- if verify && let SwitchResult::Created { path, .. } = &result {
+ // Hooks only run if --no-hooks wasn't passed and approval was granted (or --force used)
+ if !skip_hooks && let SwitchResult::Created { path, .. } = &result {
let repo = Repository::current();
let repo_root = repo.worktree_base()?;
let ctx = CommandContext::new(
@@ -1060,13 +1120,7 @@ fn main() {
&repo_root,
force,
);
- if let Err(e) = ctx.spawn_post_start_commands() {
- // Only treat CommandNotApproved as non-fatal (user declined)
- // Other errors should still fail
- if !is_command_not_approved(&e) {
- return Err(e);
- }
- }
+ ctx.spawn_post_start_commands(true)?;
}
// Execute user command after post-start hooks have been spawned
@@ -1082,6 +1136,7 @@ fn main() {
force_delete,
background,
verify,
+ force,
} => WorktrunkConfig::load()
.context("Failed to load config")
.and_then(|config| {
@@ -1093,15 +1148,47 @@ fn main() {
.into());
}
+ // "Approve at the Gate": collect and approve pre-remove hooks upfront
+ // This ensures approval happens once at the command entry point
+ //
+ // TODO(pre-remove-context): The approval context uses current worktree (cwd + current_branch),
+ // but hooks execute in each target worktree. When removing another worktree, the approval
+ // preview shows the wrong branch/path. Consider building approval context per target worktree.
+ let repo = Repository::current();
+ let verify = if verify {
+ // Create context for template expansion in approval prompt
+ let worktree_path =
+ std::env::current_dir().context("Failed to get current directory")?;
+ let repo_root = repo.worktree_base()?;
+ let current_branch = repo.current_branch()?.unwrap_or_default();
+ let ctx = CommandContext::new(
+ &repo,
+ &config,
+ &current_branch,
+ &worktree_path,
+ &repo_root,
+ force,
+ );
+ let approved = approve_hooks(&ctx, &[HookType::PreRemove], &[])?;
+ // If declined, skip hooks but continue with removal
+ if !approved {
+ crate::output::print(info_message(
+ "Commands declined, continuing removal",
+ ))?;
+ }
+ approved
+ } else {
+ false
+ };
+
if worktrees.is_empty() {
// No worktrees specified, remove current worktree
// Uses path-based removal to handle detached HEAD state
let result = handle_remove_current(!delete_branch, force_delete, background)?;
+ // Approval was handled at the gate
handle_remove_output(&result, None, background, verify)
} else {
use worktrunk::git::ResolvedWorktree;
-
- let repo = Repository::current();
// When removing multiple worktrees, we need to handle the current worktree last
// to avoid deleting the directory we're currently in
let current_worktree = repo.worktree_root().ok();
@@ -1127,7 +1214,7 @@ fn main() {
}
}
- // Remove other worktrees first
+ // Remove other worktrees first (approval was handled at the gate)
for (path, branch) in &others {
if let Some(branch_name) = branch {
let result = handle_remove(
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 898a9c60a..ae34b43a8 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -371,6 +371,8 @@ fn build_remove_command(worktree_path: &std::path::Path, branch_to_delete: Optio
}
/// Handle output for a remove operation
+///
+/// Approval is handled at the gate (command entry point), not here.
pub fn handle_remove_output(
result: &RemoveResult,
branch: Option<&str>,
@@ -484,9 +486,9 @@ fn handle_removed_worktree_output(
hook_branch,
worktree_path,
main_path,
- false, // force=false, prompt for approval
+ false, // force=false for CommandContext (not approval-related)
);
- execute_pre_remove_commands(&ctx, false, None)?;
+ execute_pre_remove_commands(&ctx, None)?;
}
// Handle detached HEAD case (no branch known)
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 92ce8961c..a041a6db6 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -719,7 +719,8 @@ fn test_complete_hook_subcommands() {
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
let subcommands = value_suggestions(&stdout);
- // Hook types
+ // Hook types and commands
+ assert!(subcommands.contains(&"show"), "Missing show");
assert!(subcommands.contains(&"post-create"), "Missing post-create");
assert!(subcommands.contains(&"post-start"), "Missing post-start");
assert!(subcommands.contains(&"pre-commit"), "Missing pre-commit");
@@ -728,8 +729,8 @@ fn test_complete_hook_subcommands() {
assert!(subcommands.contains(&"pre-remove"), "Missing pre-remove");
assert_eq!(
subcommands.len(),
- 6,
- "Should have exactly 6 hook subcommands"
+ 7,
+ "Should have exactly 7 hook subcommands"
);
// Test 2: Partial input "po" - filters to post-* subcommands
diff --git a/tests/integration_tests/hook_show.rs b/tests/integration_tests/hook_show.rs
new file mode 100644
index 000000000..81d8c8eab
--- /dev/null
+++ b/tests/integration_tests/hook_show.rs
@@ -0,0 +1,197 @@
+//! Integration tests for `wt hook show` command
+
+use crate::common::{TestRepo, set_temp_home_env, setup_snapshot_settings_with_home, wt_command};
+use insta_cmd::assert_cmd_snapshot;
+use std::fs;
+use tempfile::TempDir;
+
+/// Test `wt hook show` with both user and project hooks
+#[test]
+fn test_hook_show_with_both_configs() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ let temp_home = TempDir::new().unwrap();
+
+ // Create user config with hooks
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ fs::write(
+ global_config_dir.join("config.toml"),
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-commit]
+user-lint = "pre-commit run --all-files"
+"#,
+ )
+ .unwrap();
+
+ // Create project config with hooks
+ repo.write_project_config(
+ r#"[post-start]
+deps = "npm install"
+
+[pre-merge]
+build = "cargo build"
+test = "cargo test"
+"#,
+ );
+ repo.commit("Add project config");
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
+ cmd.arg("hook").arg("show").current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+/// Test `wt hook show` with no hooks configured
+#[test]
+fn test_hook_show_no_hooks() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ let temp_home = TempDir::new().unwrap();
+
+ // Create user config without hooks
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ fs::write(
+ global_config_dir.join("config.toml"),
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+"#,
+ )
+ .unwrap();
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
+ cmd.arg("hook").arg("show").current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+/// Test `wt hook show` filtering by hook type
+#[test]
+fn test_hook_show_filter_by_type() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ let temp_home = TempDir::new().unwrap();
+
+ // Create user config without hooks
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ fs::write(
+ global_config_dir.join("config.toml"),
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+"#,
+ )
+ .unwrap();
+
+ // Create project config with multiple hook types
+ repo.write_project_config(
+ r#"[post-start]
+deps = "npm install"
+
+[pre-merge]
+build = "cargo build"
+test = "cargo test"
+
+[post-merge]
+deploy = "scripts/deploy.sh"
+"#,
+ );
+ repo.commit("Add project config");
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
+ cmd.arg("hook")
+ .arg("show")
+ .arg("pre-merge")
+ .current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+/// Test `wt hook show` shows approval status for project hooks
+#[test]
+fn test_hook_show_approval_status() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ let temp_home = TempDir::new().unwrap();
+
+ // Create user config at XDG path with one approved command
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ let config_path = global_config_dir.join("config.toml");
+ fs::write(
+ &config_path,
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[projects."repo"]
+approved-commands = ["cargo build"]
+"#,
+ )
+ .unwrap();
+
+ // Create project config with approved and unapproved hooks
+ repo.write_project_config(
+ r#"[pre-merge]
+build = "cargo build"
+test = "cargo test"
+"#,
+ );
+ repo.commit("Add project config");
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
+ // Override config path to point to our test config with approval
+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
+ cmd.arg("hook").arg("show").current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+/// Test `wt hook show` outside git repo
+#[test]
+fn test_hook_show_outside_git_repo() {
+ let temp_dir = tempfile::tempdir().unwrap();
+ let temp_home = TempDir::new().unwrap();
+
+ // Create user config
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ fs::write(
+ global_config_dir.join("config.toml"),
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-commit]
+lint = "pre-commit run"
+"#,
+ )
+ .unwrap();
+
+ let mut settings = insta::Settings::clone_current();
+ // Replace temp home path with ~ for stable snapshots
+ settings.add_filter(temp_home.path().to_string_lossy().as_ref(), "~");
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ cmd.arg("hook").arg("show").current_dir(temp_dir.path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index d56d3cc32..07cc0cca9 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -1165,11 +1165,11 @@ fn test_merge_pre_merge_command_no_hooks() {
.output()
.unwrap();
- // Merge with --no-hooks - should skip pre-merge commands and succeed
+ // Merge with --no-verify - should skip pre-merge commands and succeed
snapshot_merge(
"merge_pre_merge_command_no_hooks",
&repo,
- &["main", "--no-hooks"],
+ &["main", "--no-verify"],
Some(&feature_wt),
);
}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 862724890..a8910aaf6 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -22,6 +22,7 @@ pub mod directives;
pub mod e2e_shell;
pub mod e2e_shell_post_start;
pub mod help;
+pub mod hook_show;
pub mod init;
pub mod internal_flag;
pub mod list;
@@ -39,3 +40,4 @@ pub mod shell_wrapper;
pub mod spacing_edge_cases;
pub mod statusline;
pub mod switch;
+pub mod user_hooks;
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index 2d5fb51ae..63ed53262 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -1402,8 +1402,8 @@ approved-commands = ["echo 'background task'"]
// Critical assertion: progress messages should appear to users
// This is the test that catches the bug where progress() is suppressed in directive mode
assert!(
- output.combined.contains("Running post-start"),
- "Progress message 'Running post-start' missing from output. \
+ output.combined.contains("Running project post-start"),
+ "Progress message 'Running project post-start' missing from output. \
Output:\n{}",
output.combined
);
@@ -1469,8 +1469,8 @@ approved-commands = ["echo 'fish background task'"]
// Critical: progress messages should appear to users through Fish wrapper
assert!(
- output.combined.contains("Running post-start"),
- "Progress message 'Running post-start' missing from Fish wrapper output. \
+ output.combined.contains("Running project post-start"),
+ "Progress message 'Running project post-start' missing from Fish wrapper output. \
Output:\n{}",
output.combined
);
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
index 7cdfc107b..6405ec92b 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
@@ -10,7 +10,7 @@ y
  echo 'test command'
❓ Allow and remember? [y/N]
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'test command'
test command
✅ Created new worktree for test-approve from main at [REPO]/repo.test-approve
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
index 915e36e51..2ce98cd4d 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
@@ -13,13 +13,13 @@ y
  echo 'Third command'
❓ Allow and remember? [y/N]
-🔄 Running post-create first:
+🔄 Running project post-create first:
  echo 'First command'
First command
-🔄 Running post-create second:
+🔄 Running project post-create second:
  echo 'Second command'
Second command
-🔄 Running post-create third:
+🔄 Running project post-create third:
  echo 'Third command'
Third command
✅ Created new worktree for test-mixed-accept from main at [REPO]/repo.test-mixed-accept
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
index d148b0063..079c27971 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
@@ -16,13 +16,13 @@ y
  echo 'Third command'
❓ Allow and remember? [y/N]
-🔄 Running post-create first:
+🔄 Running project post-create first:
  echo 'First command'
First command
-🔄 Running post-create second:
+🔄 Running project post-create second:
  echo 'Second command'
Second command
-🔄 Running post-create third:
+🔄 Running project post-create third:
  echo 'Third command'
Third command
✅ Created new worktree for test-multi from main at [REPO]/repo.test-multi
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
index 2b58cb226..703aa1899 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
@@ -16,13 +16,13 @@ y
  echo 'Running tests...'
❓ Allow and remember? [y/N]
-🔄 Running post-create install:
+🔄 Running project post-create install:
  echo 'Installing dependencies...'
Installing dependencies...
-🔄 Running post-create build:
+🔄 Running project post-create build:
  echo 'Building project...'
Building project...
-🔄 Running post-create test:
+🔄 Running project post-create test:
  echo 'Running tests...'
Running tests...
✅ Created new worktree for test-named from main at [REPO]/repo.test-named
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
index 5939dfc2b..c1c28be53 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
@@ -12,7 +12,7 @@ y
❓ Allow and remember? [y/N]
🟡 Failed to save command approval: Failed to write config file: Permission denied (os error 13)
💡 Approval will be requested again next time.
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'test command'
test command
✅ Created new worktree for test-permission from main at [REPO]/repo.test-permission
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__hook_show__hook_show_outside_git_repo.snap b/tests/integration_tests/snapshots/integration__integration_tests__hook_show__hook_show_outside_git_repo.snap
new file mode 100644
index 000000000..2c0934d21
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__hook_show__hook_show_outside_git_repo.snap
@@ -0,0 +1,22 @@
+---
+source: tests/integration_tests/hook_show.rs
+info:
+ program: wt
+ args:
+ - hook
+ - show
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_EDITOR: ""
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpwjXPMy
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
+ XDG_CONFIG_HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpwjXPMy/.config
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+❌ fatal: not a git repository (or any of the parent directories): .git
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_preserves_progress_messages.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_preserves_progress_messages.snap
index cf52dbcc3..aaedd2370 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_preserves_progress_messages.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_preserves_progress_messages.snap
@@ -3,5 +3,5 @@ source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
✅ Created new worktree for fish-bg from main at [TMPDIR]/repo.fish-bg
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'fish background task'
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap
index fb1e7b3f7..d21e56223 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap
@@ -2,7 +2,7 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running pre-merge check1:
+🔄 Running project pre-merge check1:
  [TMPDIR]/repo/mixed-output.sh check1 3
[check1] stdout line 1
[check1] stderr line 1
@@ -12,7 +12,7 @@ expression: output.normalized()
[check1] stderr line 3
[check1] stdout complete
[check1] stderr complete
-🔄 Running pre-merge check2:
+🔄 Running project pre-merge check2:
  [TMPDIR]/repo/mixed-output.sh check2 3
[check2] stdout line 1
[check2] stderr line 1
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap
index fb1e7b3f7..d21e56223 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap
@@ -2,7 +2,7 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running pre-merge check1:
+🔄 Running project pre-merge check1:
  [TMPDIR]/repo/mixed-output.sh check1 3
[check1] stdout line 1
[check1] stderr line 1
@@ -12,7 +12,7 @@ expression: output.normalized()
[check1] stderr line 3
[check1] stdout complete
[check1] stderr complete
-🔄 Running pre-merge check2:
+🔄 Running project pre-merge check2:
  [TMPDIR]/repo/mixed-output.sh check2 3
[check2] stdout line 1
[check2] stderr line 1
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snap
index 9fdb6499f..9e6480cee 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snap
@@ -2,10 +2,10 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running pre-merge format:
+🔄 Running project pre-merge format:
  echo '✓ Code formatting check passed'
✓ Code formatting check passed
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  echo '✗ Test suite failed: 3 tests failing' && exit 1
✗ Test suite failed: 3 tests failing
❌ pre-merge command failed: test: exit status: 1
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap
index 9fdb6499f..9e6480cee 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap
@@ -2,10 +2,10 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running pre-merge format:
+🔄 Running project pre-merge format:
  echo '✓ Code formatting check passed'
✓ Code formatting check passed
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  echo '✗ Test suite failed: 3 tests failing' && exit 1
✗ Test suite failed: 3 tests failing
❌ pre-merge command failed: test: exit status: 1
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap
index baf781fb8..c3aaf3781 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap
@@ -2,13 +2,13 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running pre-merge format:
+🔄 Running project pre-merge format:
  echo '✓ Code formatting check passed'
✓ Code formatting check passed
-🔄 Running pre-merge lint:
+🔄 Running project pre-merge lint:
  echo '✓ Linting passed - no warnings'
✓ Linting passed - no warnings
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  echo '✓ All 47 tests passed in 2.3s'
✓ All 47 tests passed in 2.3s
🔄 Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap
index baf781fb8..c3aaf3781 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap
@@ -2,13 +2,13 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running pre-merge format:
+🔄 Running project pre-merge format:
  echo '✓ Code formatting check passed'
✓ Code formatting check passed
-🔄 Running pre-merge lint:
+🔄 Running project pre-merge lint:
  echo '✓ Linting passed - no warnings'
✓ Linting passed - no warnings
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  echo '✓ All 47 tests passed in 2.3s'
✓ All 47 tests passed in 2.3s
🔄 Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_post_create.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_post_create.snap
index 783df959c..598c5cecf 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_post_create.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_post_create.snap
@@ -2,11 +2,11 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running post-create install:
+🔄 Running project post-create install:
  uv sync
Resolved 24 packages in 145ms
Installed 24 packages in 1.2s
✅ Created new worktree for feature-x from main at [TMPDIR]/repo.feature-x
-🔄 Running post-start dev:
+🔄 Running project post-start dev:
  uv run dev
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_pre_merge.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_pre_merge.snap
index 60067d250..f1de064e5 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_pre_merge.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__readme_example_hooks_pre_merge.snap
@@ -9,7 +9,7 @@ expression: output.normalized()
  Implement login and token refresh endpoints with JWT validation.
  Includes comprehensive test coverage and input validation.
✅ Squashed @ [HASH]
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  uv run pytest
============================= test session starts ==============================
@@ -21,7 +21,7 @@ tests/test_auth.py::test_token_validation PASSED [100%]
============================== 3 passed in 0.8s ===============================
-🔄 Running pre-merge lint:
+🔄 Running project pre-merge lint:
  uv run ruff check
All checks passed!
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap
index 875fd37c6..1ba35ba38 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap
@@ -2,14 +2,14 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-🔄 Running post-create install:
+🔄 Running project post-create install:
  echo 'Installing dependencies...'
Installing dependencies...
-🔄 Running post-create build:
+🔄 Running project post-create build:
  echo 'Building project...'
Building project...
✅ Created new worktree for feature-hooks from main at [TMPDIR]/repo.feature-hooks
-🔄 Running post-start server:
+🔄 Running project post-start server:
  echo 'Starting dev server on port 3000'
-🔄 Running post-start watch:
+🔄 Running project post-start watch:
  echo 'Watching for file changes'
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_post_start_command_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_post_start_command_no_directive_leak.snap
index 4ff0b1934..c259856b2 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_post_start_command_no_directive_leak.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_post_start_command_no_directive_leak.snap
@@ -3,5 +3,5 @@ source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
✅ Created new worktree for feature-with-hooks from main at [TMPDIR]/repo.feature-with-hooks
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'test command executed'
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__wrapper_preserves_progress_messages.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__wrapper_preserves_progress_messages.snap
index e7d498053..f11476a3a 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__wrapper_preserves_progress_messages.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__wrapper_preserves_progress_messages.snap
@@ -3,5 +3,5 @@ source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
✅ Created new worktree for feature-bg from main at [TMPDIR]/repo.feature-bg
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'background task'
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 21cdebc85..305c4538c 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -310,7 +310,7 @@ fn test_switch_no_config_commands_execute_still_runs() {
"no-hooks-test",
"--execute",
"echo 'execute command runs'",
- "--no-hooks",
+ "--no-verify",
],
);
}
@@ -353,11 +353,11 @@ approved-commands = ["{}"]
)
.unwrap();
- // With --no-hooks, the post-start command should be skipped
+ // With --no-verify, the post-start command should be skipped
snapshot_switch_with_home(
"switch_no_hooks_skips_post_start",
&repo,
- &["--create", "no-post-start", "--no-hooks"],
+ &["--create", "no-post-start", "--no-verify"],
Some(temp_home.path()),
&[],
);
@@ -370,7 +370,7 @@ fn test_switch_no_config_commands_with_existing_worktree() {
// Create a worktree first
repo.add_worktree("existing-no-hooks");
- // With --no-hooks, the --execute command should still run
+ // With --no-verify, the --execute command should still run
snapshot_switch(
"switch_no_hooks_existing",
&repo,
@@ -378,7 +378,7 @@ fn test_switch_no_config_commands_with_existing_worktree() {
"existing-no-hooks",
"--execute",
"echo 'execute still runs'",
- "--no-hooks",
+ "--no-verify",
],
);
}
@@ -402,11 +402,11 @@ fn test_switch_no_config_commands_with_force() {
repo.commit("Add config");
- // With --no-hooks, even --force shouldn't execute config commands
+ // With --no-verify, even --force shouldn't execute config commands
snapshot_switch_with_home(
"switch_no_hooks_with_force",
&repo,
- &["--create", "force-no-hooks", "--force", "--no-hooks"],
+ &["--create", "force-no-hooks", "--force", "--no-verify"],
Some(temp_home.path()),
&[],
);
diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rs
new file mode 100644
index 000000000..b4371260f
--- /dev/null
+++ b/tests/integration_tests/user_hooks.rs
@@ -0,0 +1,727 @@
+//! Integration tests for user-level hooks (~/.config/worktrunk/config.toml)
+//!
+//! User hooks differ from project hooks:
+//! - Run for all repositories
+//! - Execute before project hooks
+//! - Don't require approval
+//! - Skipped together with project hooks via --no-verify
+
+use crate::common::{TestRepo, make_snapshot_cmd, setup_snapshot_settings, wait_for_file};
+use insta_cmd::assert_cmd_snapshot;
+use std::fs;
+use std::process::Command;
+use std::thread;
+use std::time::Duration;
+
+/// Wait duration when checking file absence (testing command did NOT run).
+const SLEEP_FOR_ABSENCE_CHECK: Duration = Duration::from_millis(500);
+
+// ============================================================================
+// User Post-Create Hook Tests
+// ============================================================================
+
+/// Helper to create snapshot for switch commands
+fn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str]) {
+ let settings = setup_snapshot_settings(repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(repo, "switch", args, None);
+ assert_cmd_snapshot!(test_name, cmd);
+ });
+}
+
+#[test]
+fn test_user_post_create_hook_executes() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Write user config with post-create hook (no project config)
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-create]
+log = "echo 'USER_POST_CREATE_RAN' > user_hook_marker.txt"
+"#,
+ );
+
+ snapshot_switch("user_post_create_executes", &repo, &["--create", "feature"]);
+
+ // Verify user hook actually ran
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+ let marker_file = worktree_path.join("user_hook_marker.txt");
+ assert!(
+ marker_file.exists(),
+ "User post-create hook should have created marker file"
+ );
+
+ let contents = fs::read_to_string(&marker_file).unwrap();
+ assert!(
+ contents.contains("USER_POST_CREATE_RAN"),
+ "Marker file should contain expected content"
+ );
+}
+
+#[test]
+fn test_user_hooks_run_before_project_hooks() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create project config with post-create hook
+ repo.write_project_config(r#"post-create = "echo 'PROJECT_HOOK' >> hook_order.txt""#);
+ repo.commit("Add project config");
+
+ // Write user config with user hook AND pre-approve project command
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-create]
+log = "echo 'USER_HOOK' >> hook_order.txt"
+
+[projects."repo"]
+approved-commands = ["echo 'PROJECT_HOOK' >> hook_order.txt"]
+"#,
+ );
+
+ snapshot_switch("user_hooks_before_project", &repo, &["--create", "feature"]);
+
+ // Verify execution order
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+ let order_file = worktree_path.join("hook_order.txt");
+ assert!(order_file.exists(), "Hook order file should exist");
+
+ let contents = fs::read_to_string(&order_file).unwrap();
+ let lines: Vec<&str> = contents.lines().collect();
+
+ assert_eq!(lines.len(), 2, "Should have two hooks executed");
+ assert_eq!(lines[0], "USER_HOOK", "User hook should run first");
+ assert_eq!(lines[1], "PROJECT_HOOK", "Project hook should run second");
+}
+
+#[test]
+fn test_user_hooks_no_approval_required() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Write user config with hook but NO pre-approved commands
+ // (unlike project hooks, user hooks don't require approval)
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-create]
+setup = "echo 'NO_APPROVAL_NEEDED' > no_approval.txt"
+"#,
+ );
+
+ snapshot_switch("user_hooks_no_approval", &repo, &["--create", "feature"]);
+
+ // Verify hook ran without approval
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+ let marker_file = worktree_path.join("no_approval.txt");
+ assert!(
+ marker_file.exists(),
+ "User hook should run without pre-approval"
+ );
+}
+
+#[test]
+fn test_no_verify_flag_skips_all_hooks() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create project config with post-create hook
+ repo.write_project_config(r#"post-create = "echo 'PROJECT_HOOK' > project_marker.txt""#);
+ repo.commit("Add project config");
+
+ // Write user config with both user hook and pre-approved project command
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-create]
+log = "echo 'USER_HOOK' > user_marker.txt"
+
+[projects."repo"]
+approved-commands = ["echo 'PROJECT_HOOK' > project_marker.txt"]
+"#,
+ );
+
+ // Create worktree with --no-verify (skips ALL hooks)
+ snapshot_switch(
+ "no_verify_skips_all_hooks",
+ &repo,
+ &["--create", "feature", "--no-verify"],
+ );
+
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+
+ // User hook should NOT have run
+ let user_marker = worktree_path.join("user_marker.txt");
+ assert!(
+ !user_marker.exists(),
+ "User hook should be skipped with --no-verify"
+ );
+
+ // Project hook should also NOT have run (--no-verify skips ALL hooks)
+ let project_marker = worktree_path.join("project_marker.txt");
+ assert!(
+ !project_marker.exists(),
+ "Project hook should also be skipped with --no-verify"
+ );
+}
+
+#[test]
+fn test_user_post_create_hook_failure() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Write user config with failing hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-create]
+failing = "exit 1"
+"#,
+ );
+
+ // Failing user hook should produce warning but not block creation
+ snapshot_switch("user_post_create_failure", &repo, &["--create", "feature"]);
+
+ // Worktree should still be created despite hook failure
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+ assert!(
+ worktree_path.exists(),
+ "Worktree should be created even if post-create hook fails"
+ );
+}
+
+// ============================================================================
+// User Post-Start Hook Tests (Background)
+// ============================================================================
+
+#[test]
+fn test_user_post_start_hook_executes() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Write user config with post-start hook (background)
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-start]
+bg = "echo 'USER_POST_START_RAN' > user_bg_marker.txt"
+"#,
+ );
+
+ snapshot_switch("user_post_start_executes", &repo, &["--create", "feature"]);
+
+ // Wait for background hook to complete
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+ let marker_file = worktree_path.join("user_bg_marker.txt");
+ wait_for_file(&marker_file, Duration::from_secs(5));
+
+ let contents = fs::read_to_string(&marker_file).unwrap();
+ assert!(
+ contents.contains("USER_POST_START_RAN"),
+ "User post-start hook should have run in background"
+ );
+}
+
+#[test]
+fn test_user_post_start_skipped_with_no_verify() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Write user config with post-start hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-start]
+bg = "echo 'USER_BG' > user_bg_marker.txt"
+"#,
+ );
+
+ snapshot_switch(
+ "user_post_start_skipped_no_verify",
+ &repo,
+ &["--create", "feature", "--no-verify"],
+ );
+
+ // Wait to ensure background hook would have had time to run
+ thread::sleep(SLEEP_FOR_ABSENCE_CHECK);
+
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+ let marker_file = worktree_path.join("user_bg_marker.txt");
+ assert!(
+ !marker_file.exists(),
+ "User post-start hook should be skipped with --no-verify"
+ );
+}
+
+// ============================================================================
+// User Pre-Merge Hook Tests
+// ============================================================================
+
+/// Helper for merge snapshots
+fn snapshot_merge(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&std::path::Path>) {
+ let settings = setup_snapshot_settings(repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(repo, "merge", args, cwd);
+ assert_cmd_snapshot!(test_name, cmd);
+ });
+}
+
+#[test]
+fn test_user_pre_merge_hook_executes() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create feature worktree with a commit
+ let feature_wt = repo.add_worktree("feature");
+ fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["add", "."])
+ .output()
+ .unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["commit", "-m", "Add feature"])
+ .output()
+ .unwrap();
+
+ // Write user config with pre-merge hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-merge]
+check = "echo 'USER_PRE_MERGE_RAN' > user_premerge.txt"
+"#,
+ );
+
+ snapshot_merge(
+ "user_pre_merge_executes",
+ &repo,
+ &["main", "--force", "--no-remove"],
+ Some(&feature_wt),
+ );
+
+ // Verify user hook ran
+ let marker_file = feature_wt.join("user_premerge.txt");
+ assert!(marker_file.exists(), "User pre-merge hook should have run");
+}
+
+#[test]
+fn test_user_pre_merge_hook_failure_blocks_merge() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create feature worktree with a commit
+ let feature_wt = repo.add_worktree("feature");
+ fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["add", "."])
+ .output()
+ .unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["commit", "-m", "Add feature"])
+ .output()
+ .unwrap();
+
+ // Write user config with failing pre-merge hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-merge]
+check = "exit 1"
+"#,
+ );
+
+ // Failing pre-merge hook should block the merge
+ snapshot_merge(
+ "user_pre_merge_failure",
+ &repo,
+ &["main", "--force", "--no-remove"],
+ Some(&feature_wt),
+ );
+}
+
+#[test]
+fn test_user_pre_merge_skipped_with_no_verify() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create feature worktree with a commit
+ let feature_wt = repo.add_worktree("feature");
+ fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["add", "."])
+ .output()
+ .unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["commit", "-m", "Add feature"])
+ .output()
+ .unwrap();
+
+ // Write user config with pre-merge hook that creates a marker
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-merge]
+check = "echo 'USER_PRE_MERGE' > user_premerge_marker.txt"
+"#,
+ );
+
+ snapshot_merge(
+ "user_pre_merge_skipped_no_verify",
+ &repo,
+ &["main", "--force", "--no-remove", "--no-verify"],
+ Some(&feature_wt),
+ );
+
+ // User hook should NOT have run (--no-verify skips all hooks)
+ let marker_file = feature_wt.join("user_premerge_marker.txt");
+ assert!(
+ !marker_file.exists(),
+ "User pre-merge hook should be skipped with --no-verify"
+ );
+}
+
+// ============================================================================
+// User Post-Merge Hook Tests
+// ============================================================================
+
+#[test]
+fn test_user_post_merge_hook_executes() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create feature worktree with a commit
+ let feature_wt = repo.add_worktree("feature");
+ fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["add", "."])
+ .output()
+ .unwrap();
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.current_dir(&feature_wt)
+ .args(["commit", "-m", "Add feature"])
+ .output()
+ .unwrap();
+
+ // Write user config with post-merge hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-merge]
+notify = "echo 'USER_POST_MERGE_RAN' > user_postmerge.txt"
+"#,
+ );
+
+ snapshot_merge(
+ "user_post_merge_executes",
+ &repo,
+ &["main", "--force", "--no-remove"],
+ Some(&feature_wt),
+ );
+
+ // Post-merge runs in the destination (main) worktree
+ let main_worktree = repo.root_path();
+ let marker_file = main_worktree.join("user_postmerge.txt");
+ assert!(
+ marker_file.exists(),
+ "User post-merge hook should have run in main worktree"
+ );
+}
+
+// ============================================================================
+// User Pre-Remove Hook Tests
+// ============================================================================
+
+/// Helper for remove snapshots
+fn snapshot_remove(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&std::path::Path>) {
+ let settings = setup_snapshot_settings(repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(repo, "remove", args, cwd);
+ assert_cmd_snapshot!(test_name, cmd);
+ });
+}
+
+#[test]
+fn test_user_pre_remove_hook_executes() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create a worktree to remove
+ let _feature_wt = repo.add_worktree("feature");
+
+ // Write user config with pre-remove hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-remove]
+cleanup = "echo 'USER_PRE_REMOVE_RAN' > /tmp/user_preremove_marker.txt"
+"#,
+ );
+
+ snapshot_remove(
+ "user_pre_remove_executes",
+ &repo,
+ &["feature", "--force-delete"],
+ Some(repo.root_path()),
+ );
+
+ // Verify user hook ran (writes to /tmp since worktree is being removed)
+ let marker_file = std::path::Path::new("/tmp/user_preremove_marker.txt");
+ assert!(marker_file.exists(), "User pre-remove hook should have run");
+ // Clean up
+ let _ = fs::remove_file(marker_file);
+}
+
+#[test]
+fn test_user_pre_remove_failure_blocks_removal() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create a worktree to remove
+ let feature_wt = repo.add_worktree("feature");
+
+ // Write user config with failing pre-remove hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-remove]
+block = "exit 1"
+"#,
+ );
+
+ snapshot_remove(
+ "user_pre_remove_failure",
+ &repo,
+ &["feature", "--force-delete"],
+ Some(repo.root_path()),
+ );
+
+ // Worktree should still exist (removal blocked by failing hook)
+ assert!(
+ feature_wt.exists(),
+ "Worktree should not be removed when pre-remove hook fails"
+ );
+}
+
+#[test]
+fn test_user_pre_remove_skipped_with_no_verify() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create a worktree to remove
+ let feature_wt = repo.add_worktree("feature");
+
+ // Write user config with pre-remove hook that would block
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-remove]
+block = "exit 1"
+"#,
+ );
+
+ // With --no-verify, all hooks (including the failing one) should be skipped
+ snapshot_remove(
+ "user_pre_remove_skipped_no_verify",
+ &repo,
+ &["feature", "--force-delete", "--no-verify"],
+ Some(repo.root_path()),
+ );
+
+ // Worktree should be removed (hooks skipped)
+ // Background removal needs time to complete
+ let timeout = Duration::from_secs(5);
+ let poll_interval = Duration::from_millis(50);
+ let start = std::time::Instant::now();
+ while feature_wt.exists() && start.elapsed() < timeout {
+ thread::sleep(poll_interval);
+ }
+ assert!(
+ !feature_wt.exists(),
+ "Worktree should be removed when --no-verify skips failing hook"
+ );
+}
+
+// ============================================================================
+// User Pre-Commit Hook Tests
+// ============================================================================
+
+#[test]
+fn test_user_pre_commit_hook_executes() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create feature worktree
+ let feature_wt = repo.add_worktree("feature");
+
+ // Add uncommitted changes (triggers pre-commit during merge)
+ fs::write(feature_wt.join("uncommitted.txt"), "uncommitted content").unwrap();
+
+ // Write user config with pre-commit hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-commit]
+lint = "echo 'USER_PRE_COMMIT_RAN' > user_precommit.txt"
+"#,
+ );
+
+ snapshot_merge(
+ "user_pre_commit_executes",
+ &repo,
+ &["main", "--force", "--no-remove"],
+ Some(&feature_wt),
+ );
+
+ // Verify user hook ran
+ let marker_file = feature_wt.join("user_precommit.txt");
+ assert!(marker_file.exists(), "User pre-commit hook should have run");
+}
+
+#[test]
+fn test_user_pre_commit_failure_blocks_commit() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create feature worktree
+ let feature_wt = repo.add_worktree("feature");
+
+ // Add uncommitted changes
+ fs::write(feature_wt.join("uncommitted.txt"), "uncommitted content").unwrap();
+
+ // Write user config with failing pre-commit hook
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[pre-commit]
+lint = "exit 1"
+"#,
+ );
+
+ // Failing pre-commit hook should block the merge
+ snapshot_merge(
+ "user_pre_commit_failure",
+ &repo,
+ &["main", "--force", "--no-remove"],
+ Some(&feature_wt),
+ );
+}
+
+// ============================================================================
+// Template Variable Tests
+// ============================================================================
+
+#[test]
+fn test_user_hook_template_variables() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Write user config with hook using template variables
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-create]
+vars = "echo 'repo={{ repo }} branch={{ branch }}' > template_vars.txt"
+"#,
+ );
+
+ snapshot_switch("user_hook_template_vars", &repo, &["--create", "feature"]);
+
+ // Verify template variables were expanded
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+ let vars_file = worktree_path.join("template_vars.txt");
+ assert!(vars_file.exists(), "Template vars file should exist");
+
+ let contents = fs::read_to_string(&vars_file).unwrap();
+ assert!(
+ contents.contains("repo=repo"),
+ "Should have expanded repo variable: {}",
+ contents
+ );
+ assert!(
+ contents.contains("branch=feature"),
+ "Should have expanded branch variable: {}",
+ contents
+ );
+}
+
+// ============================================================================
+// Combined User and Project Hooks Tests
+// ============================================================================
+
+#[test]
+fn test_user_and_project_post_start_both_run() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create project config with post-start hook
+ repo.write_project_config(r#"post-start = "echo 'PROJECT_POST_START' > project_bg.txt""#);
+ repo.commit("Add project config");
+
+ // Write user config with user hook AND pre-approve project command
+ repo.write_test_config(
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
+
+[post-start]
+bg = "echo 'USER_POST_START' > user_bg.txt"
+
+[projects."repo"]
+approved-commands = ["echo 'PROJECT_POST_START' > project_bg.txt"]
+"#,
+ );
+
+ snapshot_switch(
+ "user_and_project_post_start",
+ &repo,
+ &["--create", "feature"],
+ );
+
+ let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
+
+ // Wait for both background commands
+ wait_for_file(&worktree_path.join("user_bg.txt"), Duration::from_secs(5));
+ wait_for_file(
+ &worktree_path.join("project_bg.txt"),
+ Duration::from_secs(5),
+ );
+
+ // Both should have run
+ assert!(
+ worktree_path.join("user_bg.txt").exists(),
+ "User post-start should have run"
+ );
+ assert!(
+ worktree_path.join("project_bg.txt").exists(),
+ "Project post-start should have run"
+ );
+}
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__already_approved_skip_prompt.snap b/tests/snapshots/integration__integration_tests__approval_ui__already_approved_skip_prompt.snap
index 012bc53b8..22760621f 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__already_approved_skip_prompt.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__already_approved_skip_prompt.snap
@@ -24,7 +24,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'approved' > output.txt
✅ Created new worktree for test-approved from main at [REPO].test-approved
💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap b/tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap
index 9549bcfec..73894efbe 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap
@@ -25,7 +25,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'test command'
test command
✅ Created new worktree for test-force-tty from main at [REPO].test-force-tty
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_first_run.snap b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_first_run.snap
index fb75202da..b517ac0f9 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_first_run.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_first_run.snap
@@ -25,7 +25,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'test command' > output.txt
✅ Created new worktree for test-force from main at [REPO].test-force
💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__step_hook_unknown_name_error.snap b/tests/snapshots/integration__integration_tests__approval_ui__step_hook_unknown_name_error.snap
index 87d89ee74..0a5d5a6b0 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__step_hook_unknown_name_error.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__step_hook_unknown_name_error.snap
@@ -3,7 +3,7 @@ source: tests/integration_tests/approval_ui.rs
info:
program: wt
args:
- - step
+ - hook
- pre-merge
- nonexistent
- "--force"
@@ -25,4 +25,4 @@ exit_code: 1
----- stdout -----
----- stderr -----
-❌ No command named nonexistent (available: test, lint)
+❌ No command named nonexistent (available: project:test, project:lint)
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
index 80366e781..76c05d1d1 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
@@ -273,7 +273,7 @@ With --project, creates .config/wt.toml in the current repositor
# Use for: uv sync, npm install, bundle install, build, dev servers, file watchers,
# downloading assets too large for git (images, ML models, binaries), long-running tasks
# The worktree switch completes immediately, these run in parallel
- # Output is logged to .git/wt-logs/{branch}-post-start-{name}.log
+ # Output is logged to .git/wt-logs/{branch}-{source}-post-start-{name}.log (source: user/project)
#
# Format options:
# 1. Single string:
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index 8f81545eb..c932ca09c 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -120,7 +120,7 @@ Set persistent flag values for commands. These apply unless explicitly overridde
squash = false # Preserve individual commits (--no-squash)
commit = false # Skip committing uncommitted changes (--no-commit)
remove = false # Keep worktree after merge (--no-remove)
- verify = false # Skip project hooks (--no-verify)
+ verify = false # Skip hooks (--no-verify)
LLM commit messages
@@ -145,6 +145,20 @@ When project hooks run for the first time, Worktrunk prompts for approval. Appro
Manage approvals with wt config approvals add to review and pre-approve commands, and wt config approvals clear to reset (add --global to clear
all projects).
+User hooks
+
+Personal hooks that run for all repositories. Use the same syntax as project hooks:
+
+ [post-create]
+ setup = "echo 'Setting up worktree...'"
+ 
+ [pre-merge]
+ notify = "notify-send 'Merging {{ branch }}'"
+
+User hooks run before project hooks and don't require approval. Skip with --no-verify.
+
+See wt hook for complete documentation.
+
Project config
The project config defines lifecycle hooks — commands that run at specific points during worktree operations. This file is checked into version
diff --git a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap b/tests/snapshots/integration__integration_tests__help__help_merge_long.snap
index 5eac2ce91..479c131e3 100644
--- a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_merge_long.snap
@@ -38,7 +38,7 @@ Usage: wt merge [OPTIONS] [TARGET]
Keep worktree after merge
--no-verify
- Skip all project hooks
+ Skip hooks
-f, --force
Skip approval prompts
diff --git a/tests/snapshots/integration__integration_tests__help__help_merge_short.snap b/tests/snapshots/integration__integration_tests__help__help_merge_short.snap
index 8154afcd3..be42e29d7 100644
--- a/tests/snapshots/integration__integration_tests__help__help_merge_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_merge_short.snap
@@ -28,7 +28,7 @@ Usage: wt merge [OPTIONS] [TARGET]
--no-squash Skip commit squashing
--no-commit Skip commit, squash, and rebase
--no-remove Keep worktree after merge
- --no-verify Skip all project hooks
+ --no-verify Skip hooks
-f, --force Skip approval prompts
--stage <STAGE> What to stage before committing [default: all] [possible values: all, tracked, none]
-h, --help Print help (see more with '--help')
diff --git a/tests/snapshots/integration__integration_tests__help__help_no_args.snap b/tests/snapshots/integration__integration_tests__help__help_no_args.snap
index 93c73819a..4cf8c3379 100644
--- a/tests/snapshots/integration__integration_tests__help__help_no_args.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_no_args.snap
@@ -22,7 +22,7 @@ Usage: wt [OPTIONS] [COMMAND]
Commands:
config Manage configuration and shell integration
step Run individual workflow operations
- hook Run project hooks
+ hook Run hooks independently
select Interactive worktree selector
list List worktrees and optionally branches
switch Switch to a worktree
diff --git a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap b/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
index 65e020305..aa5104f0c 100644
--- a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
@@ -36,7 +36,10 @@ Usage: wt remove [OPTIONS] [WORKTREES]...
Run removal in foreground
--no-verify
- Skip pre-remove hooks
+ Skip hooks
+
+ --force
+ Skip approval prompts
-h, --help
Print help (see a summary with '-h')
diff --git a/tests/snapshots/integration__integration_tests__help__help_remove_short.snap b/tests/snapshots/integration__integration_tests__help__help_remove_short.snap
index c98b432d7..b4412dbe7 100644
--- a/tests/snapshots/integration__integration_tests__help__help_remove_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_remove_short.snap
@@ -28,7 +28,8 @@ Usage: wt remove [OPTIONS] [WORKTREES]...
--no-delete-branch Keep branch after removal
-D, --force-delete Delete unmerged branches
--no-background Run removal in foreground
- --no-verify Skip pre-remove hooks
+ --no-verify Skip hooks
+ --force Skip approval prompts
-h, --help Print help (see more with '--help')
Global Options:
diff --git a/tests/snapshots/integration__integration_tests__help__help_root_long.snap b/tests/snapshots/integration__integration_tests__help__help_root_long.snap
index f97fdaf31..35e1fe314 100644
--- a/tests/snapshots/integration__integration_tests__help__help_root_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_root_long.snap
@@ -23,7 +23,7 @@ Usage: wt [OPTIONS] [COMMAND]
Commands:
config Manage configuration and shell integration
step Run individual workflow operations
- hook Run project hooks
+ hook Run hooks independently
select Interactive worktree selector
list List worktrees and optionally branches
switch Switch to a worktree
diff --git a/tests/snapshots/integration__integration_tests__help__help_root_short.snap b/tests/snapshots/integration__integration_tests__help__help_root_short.snap
index e78df219d..889f4774b 100644
--- a/tests/snapshots/integration__integration_tests__help__help_root_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_root_short.snap
@@ -23,7 +23,7 @@ Usage: wt [OPTIONS] [COMMAND]
Commands:
config Manage configuration and shell integration
step Run individual workflow operations
- hook Run project hooks
+ hook Run hooks independently
select Interactive worktree selector
list List worktrees and optionally branches
switch Switch to a worktree
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_long.snap b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
index a281cb637..516a617b5 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
@@ -67,4 +67,4 @@ Manual merge workflow with review between steps:
See also
- wt merge — Runs commit → squash → rebase → hooks → push → cleanup automatically
-- wt hook — Run project-defined lifecycle hooks
+- wt hook — Run hooks independently
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
index d67336917..1136c6284 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
@@ -52,7 +52,7 @@ Usage: wt switch [OPTIONS] <BRANCH>
Skip approval prompts
--no-verify
- Skip all project hooks
+ Skip hooks
-h, --help
Print help (see a summary with '-h')
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_short.snap b/tests/snapshots/integration__integration_tests__help__help_switch_short.snap
index 139b065bf..429af0bc8 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_short.snap
@@ -29,7 +29,7 @@ Usage: wt switch [OPTIONS] <BRANCH>
-b, --base <BASE> Base branch
-x, --execute <EXECUTE> Command to run after switch
-f, --force Skip approval prompts
- --no-verify Skip all project hooks
+ --no-verify Skip hooks
-h, --help Print help (see more with '--help')
Global Options:
diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_show_approval_status.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_show_approval_status.snap
new file mode 100644
index 000000000..eb2119405
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_show_approval_status.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/hook_show.rs
+info:
+ program: wt
+ args:
+ - hook
+ - show
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+⚪ User Hooks: ~/.config/worktrunk/config.toml
+💡 (none configured)
+
+⚪ Project Hooks: [REPO]/.config/wt.toml
+⚪ pre-merge build:
+  cargo build
+❓ pre-merge test: (requires approval)
+  cargo test
diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_show_filter_by_type.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_show_filter_by_type.snap
new file mode 100644
index 000000000..11a005692
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_show_filter_by_type.snap
@@ -0,0 +1,36 @@
+---
+source: tests/integration_tests/hook_show.rs
+info:
+ program: wt
+ args:
+ - hook
+ - show
+ - pre-merge
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+[TEST_CONFIG]
+💡 (none configured)
+
+⚪ Project Hooks: [REPO]/.config/wt.toml
+❓ pre-merge build: (requires approval)
+  cargo build
+❓ pre-merge test: (requires approval)
+  cargo test
diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_show_no_hooks.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_show_no_hooks.snap
new file mode 100644
index 000000000..c2e8cb902
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_show_no_hooks.snap
@@ -0,0 +1,32 @@
+---
+source: tests/integration_tests/hook_show.rs
+info:
+ program: wt
+ args:
+ - hook
+ - show
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+[TEST_CONFIG]
+💡 (none configured)
+
+⚪ Project Hooks: [REPO]/.config/wt.toml
+💡 (not found)
diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_show_with_both_configs.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_show_with_both_configs.snap
new file mode 100644
index 000000000..0126e2122
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_show_with_both_configs.snap
@@ -0,0 +1,37 @@
+---
+source: tests/integration_tests/hook_show.rs
+info:
+ program: wt
+ args:
+ - hook
+ - show
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+[TEST_CONFIG]
+💡 (none configured)
+
+⚪ Project Hooks: [REPO]/.config/wt.toml
+❓ post-start deps: (requires approval)
+  npm install
+❓ pre-merge build: (requires approval)
+  cargo build
+❓ pre-merge test: (requires approval)
+  cargo test
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap
index e64a274b7..c6c999c09 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap
@@ -30,7 +30,7 @@ exit_code: 1
  1 file changed, 1 insertion(+)
✅ Merged to main (1 commit, 1 file, +1)
🔄 Removing feature worktree & branch in background (already in main)
-🔄 Running post-merge:
+🔄 Running project post-merge:
  exit 1
🟡 Command failed: exit status: 1
❌ post-merge command failed: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap
index 4a41235ba..2137ea73b 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap
@@ -30,8 +30,8 @@ exit_code: 0
  1 file changed, 1 insertion(+)
✅ Merged to main (1 commit, 1 file, +1)
🔄 Removing feature worktree & branch in background (already in main)
-🔄 Running post-merge notify:
+🔄 Running project post-merge notify:
  echo 'Merge to main complete' > notify.txt
-🔄 Running post-merge deploy:
+🔄 Running project post-merge deploy:
  echo 'Deploying branch feature' > deploy.txt

diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap
index fa5d181f5..c6e558e00 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap
@@ -30,6 +30,6 @@ exit_code: 0
  1 file changed, 1 insertion(+)
✅ Merged to main (1 commit, 1 file, +1)
🔄 Removing feature worktree & branch in background (already in main)
-🔄 Running post-merge:
+🔄 Running project post-merge:
  echo 'merged feature to main' > post-merge-ran.txt

diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_from_main_branch.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_from_main_branch.snap
index 67b9a787e..23f61ae6b 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_from_main_branch.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_from_main_branch.snap
@@ -25,6 +25,6 @@ exit_code: 0
----- stderr -----
⚪ Already up to date with main (no new commits, no rebase needed)
⚪ Worktree preserved (main worktree)
-🔄 Running post-merge:
+🔄 Running project post-merge:
  echo 'post-merge ran from main' > post-merge-ran.txt

diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_with_nothing_to_merge.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_with_nothing_to_merge.snap
index 90312e838..76bec14fb 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_with_nothing_to_merge.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_runs_with_nothing_to_merge.snap
@@ -26,6 +26,6 @@ exit_code: 0
----- stderr -----
⚪ Already up to date with main (no new commits, no rebase needed)
🔄 Removing feature worktree & branch in background (already in main)
-🔄 Running post-merge:
+🔄 Running project post-merge:
  echo 'post-merge ran' > post-merge-ran.txt

diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_failure.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_failure.snap
index 5dacb7013..1ee8acd64 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_failure.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_failure.snap
@@ -26,7 +26,7 @@ exit_code: 1
----- stderr -----
🟡 Auto-staging 1 untracked path:
  feature.txt
-🔄 Running pre-commit:
+🔄 Running project pre-commit:
  exit 1
❌ pre-commit command failed: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap
index e8ef4c594..bef897325 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_commit_command_success.snap
@@ -26,7 +26,7 @@ exit_code: 0
----- stderr -----
🟡 Auto-staging 1 untracked path:
  feature.txt
-🔄 Running pre-commit:
+🔄 Running project pre-commit:
  echo 'Pre-commit check passed'
Pre-commit check passed
🔄 Committing changes with default message... (1 file, +1, no squashing needed)
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_failure.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_failure.snap
index 52b3648ee..65893bb63 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_failure.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_failure.snap
@@ -24,7 +24,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-🔄 Running pre-merge:
+🔄 Running project pre-merge:
  exit 1
❌ pre-merge command failed: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_named.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_named.snap
index 741576fb9..79bda620c 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_named.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_named.snap
@@ -24,11 +24,11 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running pre-merge format:
+🔄 Running project pre-merge format:
  exit 0
-🔄 Running pre-merge lint:
+🔄 Running project pre-merge lint:
  exit 0
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  exit 0
🔄 Merging 1 commit to main @ 2cbe2a2 (no commit/squash/rebase needed)
  * 2cbe2a2 Add feature file
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap
index 60ba734e2..1aec4c46c 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_no_hooks.snap
@@ -5,7 +5,7 @@ info:
args:
- merge
- main
- - "--no-hooks"
+ - "--no-verify"
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
@@ -19,15 +19,14 @@ info:
SOURCE_DATE_EPOCH: "1735776000"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
-success: false
-exit_code: 2
+success: true
+exit_code: 0
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
-
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-
-Usage: wt merge <TARGET>
-
-For more information, try '--help'.
+🔄 Merging 1 commit to main @ f2d96c5 (no commit/squash/rebase needed)
+  * f2d96c5 Add feature file
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Merged to main (1 commit, 1 file, +1)
+🔄 Removing feature worktree & branch in background (already in main)
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_success.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_success.snap
index 76e8c58e1..f89154d82 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_success.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_command_success.snap
@@ -24,7 +24,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running pre-merge:
+🔄 Running project pre-merge:
  exit 0
🔄 Merging 1 commit to main @ 4b1199c (no commit/squash/rebase needed)
  * 4b1199c Add feature file
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_failure.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_failure.snap
index d65718cdc..4d40320b4 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_failure.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_failure.snap
@@ -24,7 +24,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-🔄 Running pre-commit:
+🔄 Running project pre-commit:
  exit 1
❌ pre-commit command failed: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_success.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_success.snap
index da97cfce2..08ab7db8e 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_success.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_squash_command_success.snap
@@ -24,7 +24,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running pre-commit:
+🔄 Running project pre-commit:
  echo 'Pre-commit check passed'
Pre-commit check passed
🔄 Merging 1 commit to main @ 726717f (no commit/squash/rebase needed)
diff --git a/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap b/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
index 3041bb5fe..41cb9db31 100644
--- a/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
+++ b/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
@@ -37,7 +37,7 @@ exit_code: 0
  - Add JWT encoding/decoding with signature verification
  - Create test suite covering all authentication flows
✅ Squashed @ 95c3316
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  cargo test
 Finished test [unoptimized + debuginfo] target(s) in 0.12s
Running unittests src/lib.rs (target/debug/deps/worktrunk-abc123)
@@ -49,7 +49,7 @@ test auth::tests::test_token_refresh ... ok
test auth::tests::test_token_validation ... ok
test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s
-🔄 Running pre-merge lint:
+🔄 Running project pre-merge lint:
  cargo clippy
 Checking worktrunk v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 1.23s
@@ -61,7 +61,7 @@ test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fin
  3 files changed, 33 insertions(+)
✅ Merged to main (1 commit, 3 files, +33)
🔄 Removing feature-auth worktree & branch in background (already in main)
-🔄 Running post-merge install:
+🔄 Running project post-merge install:
  cargo install --path .
 Installing worktrunk v0.1.0
Compiling worktrunk v0.1.0
diff --git a/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_post_create.snap b/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_post_create.snap
index 79f6db3c0..22a1ac25b 100644
--- a/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_post_create.snap
+++ b/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_post_create.snap
@@ -26,12 +26,12 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create install:
+🔄 Running project post-create install:
  uv sync

Resolved 24 packages in 145ms
Installed 24 packages in 1.2s
✅ Created new worktree for feature-x from main at [REPO].feature-x
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start dev:
+🔄 Running project post-start dev:
  uv run dev
diff --git a/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap b/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap
index aaafeb298..7014ec5d7 100644
--- a/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap
+++ b/tests/snapshots/integration__integration_tests__merge__readme_example_hooks_pre_merge.snap
@@ -32,7 +32,7 @@ exit_code: 0
  Implement login and token refresh endpoints with JWT validation.
  Includes comprehensive test coverage and input validation.
✅ Squashed @ 69200cc
-🔄 Running pre-merge test:
+🔄 Running project pre-merge test:
  uv run pytest

============================= test session starts ==============================
@@ -44,7 +44,7 @@ tests/test_auth.py::test_token_validation PASSED [100%]
============================== 3 passed in 0.8s ===============================
-🔄 Running pre-merge lint:
+🔄 Running project pre-merge lint:
  uv run ruff check

All checks passed!
diff --git a/tests/snapshots/integration__integration_tests__merge__step_commit_both_flags.snap b/tests/snapshots/integration__integration_tests__merge__step_commit_both_flags.snap
index 3a6973cae..98b3675d6 100644
--- a/tests/snapshots/integration__integration_tests__merge__step_commit_both_flags.snap
+++ b/tests/snapshots/integration__integration_tests__merge__step_commit_both_flags.snap
@@ -27,7 +27,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-💡 Skipping pre-commit hook (--no-verify)
+💡 Skipping pre-commit hooks (--no-verify)
🔄 Generating commit message and committing tracked changes... (1 file, +1, -1)
  fix: update file
✅ Committed changes @ 0b66aac
diff --git a/tests/snapshots/integration__integration_tests__merge__step_commit_no_verify.snap b/tests/snapshots/integration__integration_tests__merge__step_commit_no_verify.snap
index dcd77c242..abd2da770 100644
--- a/tests/snapshots/integration__integration_tests__merge__step_commit_no_verify.snap
+++ b/tests/snapshots/integration__integration_tests__merge__step_commit_no_verify.snap
@@ -26,7 +26,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-💡 Skipping pre-commit hook (--no-verify)
+💡 Skipping pre-commit hooks (--no-verify)
🟡 Auto-staging 2 untracked paths:
  .config/
  file1.txt
diff --git a/tests/snapshots/integration__integration_tests__merge__step_squash_both_flags.snap b/tests/snapshots/integration__integration_tests__merge__step_squash_both_flags.snap
index dead9b8a1..57824ede6 100644
--- a/tests/snapshots/integration__integration_tests__merge__step_squash_both_flags.snap
+++ b/tests/snapshots/integration__integration_tests__merge__step_squash_both_flags.snap
@@ -27,7 +27,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-💡 Skipping pre-commit hook (--no-verify)
+💡 Skipping pre-commit hooks (--no-verify)
🔄 Squashing 2 commits & tracked changes into a single commit (3 files, +3)...
💡 Backup created @ 31e06e8
🔄 Generating squash commit message...
diff --git a/tests/snapshots/integration__integration_tests__merge__step_squash_no_verify.snap b/tests/snapshots/integration__integration_tests__merge__step_squash_no_verify.snap
index 9f5dc5a6f..df2d7d2d9 100644
--- a/tests/snapshots/integration__integration_tests__merge__step_squash_no_verify.snap
+++ b/tests/snapshots/integration__integration_tests__merge__step_squash_no_verify.snap
@@ -26,7 +26,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-💡 Skipping pre-commit hook (--no-verify)
+💡 Skipping pre-commit hooks (--no-verify)
🔄 Squashing 2 commits into a single commit (3 files, +3)...
🔄 Generating squash commit message...
  squash: combined commits
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap b/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
index 0b93d0682..089a58b4a 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
@@ -25,9 +25,9 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'Setup done' > setup.txt
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start server:
+🔄 Running project post-start server:
  sleep 0.05 && echo 'Server running' > server.txt
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap b/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap
index 3e345601d..1d6881366 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap
@@ -28,7 +28,7 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'Background task' > background.txt
🔄 Executing (--execute):
  echo 'Execute flag' > execute.txt
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_default_branch_template.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_default_branch_template.snap
index f2bd79597..5d1e60415 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_default_branch_template.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_default_branch_template.snap
@@ -26,7 +26,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'Default: main' > default.txt
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
index 2a2ac6bd3..19314f969 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
@@ -25,7 +25,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  exit 1
🟡 Command failed: exit status: 1
✅ Created new worktree for feature from main at [REPO].feature
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_git_variables_template.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_git_variables_template.snap
index b5ed13760..70ab9cd99 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_git_variables_template.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_git_variables_template.snap
@@ -26,13 +26,13 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create commit:
+🔄 Running project post-create commit:
  echo 'Commit: d5f94f04f2d59bd7282f575b929b659aefa65f2e' > git_vars.txt
-🔄 Running post-create short:
+🔄 Running project post-create short:
  echo 'Short: d5f94f0' >> git_vars.txt
-🔄 Running post-create remote:
+🔄 Running project post-create remote:
  echo 'Remote: origin' >> git_vars.txt
-🔄 Running post-create worktree_name:
+🔄 Running project post-create worktree_name:
  echo 'Worktree Name: repo.feature' >> git_vars.txt
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiline_control_structure.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiline_control_structure.snap
index 4f3876fc8..11ad93f86 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiline_control_structure.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiline_control_structure.snap
@@ -25,7 +25,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  if [ ! -f test.txt ]; then
  echo 'File does not exist' > result.txt
  else
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap
index a35f36531..e590dd388 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_named_commands.snap
@@ -25,10 +25,10 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create install:
+🔄 Running project post-create install:
  echo 'Installing deps'
Installing deps
-🔄 Running post-create setup:
+🔄 Running project post-create setup:
  echo 'Running setup'
Running setup
✅ Created new worktree for feature from main at [REPO].feature
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap
index d81d0b8d3..fe6715d21 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_single_command.snap
@@ -25,7 +25,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'Setup complete'
Setup complete
✅ Created new worktree for feature from main at [REPO].feature
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
index 0481e53dd..e12ba2585 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
@@ -25,13 +25,13 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create repo:
+🔄 Running project post-create repo:
  echo 'Repo: repo' > info.txt
-🔄 Running post-create branch:
+🔄 Running project post-create branch:
  echo 'Branch: feature-test' >> info.txt
-🔄 Running post-create worktree:
+🔄 Running project post-create worktree:
  echo 'Worktree: [REPO].feature-test' >> info.txt
-🔄 Running post-create root:
+🔄 Running project post-create root:
  echo 'Root: [REPO]' >> info.txt
✅ Created new worktree for feature/test from main at [REPO].feature-test
💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap
index 877508c7b..07c2e64c5 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap
@@ -26,7 +26,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running post-create:
+🔄 Running project post-create:
  echo 'Upstream: ' > upstream.txt
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_complex_shell.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_complex_shell.snap
index 95c9ddd08..c227c8b39 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_complex_shell.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_complex_shell.snap
@@ -27,7 +27,7 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'line1
  line2
  line3' | grep line2 > filtered.txt
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_create_with_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_create_with_command.snap
index d7ef41efc..2605f479e 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_create_with_command.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_create_with_command.snap
@@ -27,5 +27,5 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'POST-START-RAN' > post_start_marker.txt
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_command.snap
index 2a84c14d8..0f9c062da 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_command.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_command.snap
@@ -27,5 +27,5 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'unclosed quote
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_log_captures_output.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_log_captures_output.snap
index 276b3bbbc..c9179b09f 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_log_captures_output.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_log_captures_output.snap
@@ -27,5 +27,5 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'stdout output' && echo 'stderr output' >&2
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiline_with_newlines.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiline_with_newlines.snap
index 7b79bba50..19f49b94c 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiline_with_newlines.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiline_with_newlines.snap
@@ -27,7 +27,7 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start:
+🔄 Running project post-start:
  echo 'first line' > multiline.txt
  echo 'second line' >> multiline.txt
  echo 'third line' >> multiline.txt
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiple_background.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiple_background.snap
index 3f025f4ce..b4621efef 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiple_background.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_multiple_background.snap
@@ -27,7 +27,7 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start task1:
+🔄 Running project post-start task1:
  echo 'Task 1 running' > task1.txt
-🔄 Running post-start task2:
+🔄 Running project post-start task2:
  echo 'Task 2 running' > task2.txt
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_separate_logs.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_separate_logs.snap
index 509e81f6e..6dd76b88e 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_separate_logs.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_separate_logs.snap
@@ -27,9 +27,9 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start task1:
+🔄 Running project post-start task1:
  echo 'TASK1_OUTPUT'
-🔄 Running post-start task2:
+🔄 Running project post-start task2:
  echo 'TASK2_OUTPUT'
-🔄 Running post-start task3:
+🔄 Running project post-start task3:
  echo 'TASK3_OUTPUT'
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap
index 4933fcebc..fccdcfbe6 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap
@@ -27,5 +27,5 @@ exit_code: 0
----- stderr -----
✅ Created new worktree for feature from main at [REPO].feature
💡 Run wt config shell install to enable automatic cd
-🔄 Running post-start:
+🔄 Running project post-start:
  sleep 0.1 && echo 'Background task done' > background.txt
diff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snap
index 1269aa611..c53f918db 100644
--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snap
+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snap
@@ -25,7 +25,7 @@ exit_code: 0
----- stderr -----
🔄 Removing worktree for feature-hook...
-🔄 Running pre-remove:
+🔄 Running project pre-remove:
  echo 'About to remove worktree'
About to remove worktree
✅ Removed feature-hook worktree & branch (already in main)
diff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snap
index fdebf022b..c7dd8d39d 100644
--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snap
+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snap
@@ -25,7 +25,7 @@ exit_code: 1
----- stderr -----
🔄 Removing worktree for feature-fail...
-🔄 Running pre-remove:
+🔄 Running project pre-remove:
  exit 1
❌ pre-remove command failed: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snap
index 11eead0cb..23cb4aaf5 100644
--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snap
+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snap
@@ -24,6 +24,6 @@ exit_code: 0
----- stderr -----
🔄 Removing current worktree...
-🔄 Running pre-remove:
+🔄 Running project pre-remove:
  touch [REPO]/m.txt
✅ Removed worktree (detached HEAD, no branch to delete)
diff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head_background.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head_background.snap
index 516d387c0..a13365124 100644
--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head_background.snap
+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head_background.snap
@@ -22,6 +22,6 @@ exit_code: 0
----- stdout -----
----- stderr -----
-🔄 Running pre-remove:
+🔄 Running project pre-remove:
  touch [REPO]/detached-bg-hook-marker.txt
🔄 Removing worktree in background (detached HEAD, no branch to delete)
diff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snap
index e6d78e2fd..aeff9472b 100644
--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snap
+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snap
@@ -25,13 +25,13 @@ exit_code: 0
----- stderr -----
🔄 Removing worktree for feature-templates...
-🔄 Running pre-remove branch:
+🔄 Running project pre-remove branch:
  echo 'Branch: feature-templates'
Branch: feature-templates
-🔄 Running pre-remove worktree:
+🔄 Running project pre-remove worktree:
  echo 'Worktree: [REPO].feature-templates'
Worktree: [REPO].feature-templates
-🔄 Running pre-remove worktree_name:
+🔄 Running project pre-remove worktree_name:
  echo 'Name: repo.feature-templates'
Name: repo.feature-templates
✅ Removed feature-templates worktree & branch (already in main)
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
index e352d82d9..44ce8ba36 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
@@ -8,7 +8,7 @@ info:
- no-hooks-test
- "--execute"
- "echo 'execute command runs'"
- - "--no-hooks"
+ - "--no-verify"
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
@@ -23,15 +23,12 @@ info:
SOURCE_DATE_EPOCH: "1735776000"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
-success: false
-exit_code: 2
+success: true
+exit_code: 0
----- stdout -----
+execute command runs
----- stderr -----
-error: unexpected argument '--no-hooks' found
-
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-
-Usage: wt switch --create --execute <EXECUTE> <BRANCH>
-
-For more information, try '--help'.
+✅ Created new worktree for no-hooks-test from main at [REPO].no-hooks-test
+🔄 Executing (--execute):
+  echo 'execute command runs'
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
index e60eabab6..aafa41bcf 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
@@ -7,7 +7,7 @@ info:
- existing-no-hooks
- "--execute"
- "echo 'execute still runs'"
- - "--no-hooks"
+ - "--no-verify"
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
@@ -22,15 +22,12 @@ info:
SOURCE_DATE_EPOCH: "1735776000"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
-success: false
-exit_code: 2
+success: true
+exit_code: 0
----- stdout -----
+execute still runs
----- stderr -----
-error: unexpected argument '--no-hooks' found
-
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-
-Usage: wt switch --execute <EXECUTE> <BRANCH>
-
-For more information, try '--help'.
+✅ Switched to worktree for existing-no-hooks at [REPO].existing-no-hooks
+🔄 Executing (--execute):
+  echo 'execute still runs'
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap
index b9068e95c..935fa1a11 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_skips_post_start.snap
@@ -6,7 +6,7 @@ info:
- switch
- "--create"
- no-post-start
- - "--no-hooks"
+ - "--no-verify"
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
@@ -21,15 +21,10 @@ info:
SOURCE_DATE_EPOCH: "1735776000"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
-success: false
-exit_code: 2
+success: true
+exit_code: 0
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
-
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-
-Usage: wt switch --create <BRANCH>
-
-For more information, try '--help'.
+✅ Created new worktree for no-post-start from main at [REPO].no-post-start
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap
index b04c592d2..9fbc9420c 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_with_force.snap
@@ -7,7 +7,7 @@ info:
- "--create"
- force-no-hooks
- "--force"
- - "--no-hooks"
+ - "--no-verify"
env:
CLICOLOR_FORCE: "1"
COLUMNS: "150"
@@ -22,15 +22,10 @@ info:
SOURCE_DATE_EPOCH: "1735776000"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
---
-success: false
-exit_code: 2
+success: true
+exit_code: 0
----- stdout -----
----- stderr -----
-error: unexpected argument '--no-hooks' found
-
- tip: to pass '--no-hooks' as a value, use '-- --no-hooks'
-
-Usage: wt switch --create --force <BRANCH>
-
-For more information, try '--help'.
+✅ Created new worktree for force-no-hooks from main at [REPO].force-no-hooks
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__no_user_hooks_flag.snap b/tests/snapshots/integration__integration_tests__user_hooks__no_user_hooks_flag.snap
new file mode 100644
index 000000000..eded8f916
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__no_user_hooks_flag.snap
@@ -0,0 +1,34 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ - "--no-user-hooks"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 2
+----- stdout -----
+
+----- stderr -----
+error: unexpected argument '--no-user-hooks' found
+
+ tip: to pass '--no-user-hooks' as a value, use '-- --no-user-hooks'
+
+Usage: wt switch --create <BRANCH>
+
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__no_verify_skips_all_hooks.snap b/tests/snapshots/integration__integration_tests__user_hooks__no_verify_skips_all_hooks.snap
new file mode 100644
index 000000000..7261d6686
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__no_verify_skips_all_hooks.snap
@@ -0,0 +1,29 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ - "--no-verify"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_and_project_post_start.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_and_project_post_start.snap
new file mode 100644
index 000000000..c4e2e8445
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_and_project_post_start.snap
@@ -0,0 +1,32 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
+🔄 Running user post-start bg:
+  echo 'USER_POST_START' > user_bg.txt
+🔄 Running project post-start:
+  echo 'PROJECT_POST_START' > project_bg.txt
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_hook_template_vars.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_hook_template_vars.snap
new file mode 100644
index 000000000..e946d6e05
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_hook_template_vars.snap
@@ -0,0 +1,30 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Running user post-create vars:
+  echo 'repo=repo branch=feature' > template_vars.txt
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_hooks_before_project.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_hooks_before_project.snap
new file mode 100644
index 000000000..cc549c2dc
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_hooks_before_project.snap
@@ -0,0 +1,32 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Running user post-create log:
+  echo 'USER_HOOK' >> hook_order.txt
+🔄 Running project post-create:
+  echo 'PROJECT_HOOK' >> hook_order.txt
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_hooks_no_approval.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_hooks_no_approval.snap
new file mode 100644
index 000000000..b89a93598
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_hooks_no_approval.snap
@@ -0,0 +1,30 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Running user post-create setup:
+  echo 'NO_APPROVAL_NEEDED' > no_approval.txt
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_executes.snap
new file mode 100644
index 000000000..3051bd14d
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_executes.snap
@@ -0,0 +1,30 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Running user post-create log:
+  echo 'USER_POST_CREATE_RAN' > user_hook_marker.txt
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap
new file mode 100644
index 000000000..f9f4bc3d3
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap
@@ -0,0 +1,31 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Running user post-create failing:
+  exit 1
+🟡 Command failing failed: exit status: 1
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_merge_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_merge_executes.snap
new file mode 100644
index 000000000..b4de68bd9
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_merge_executes.snap
@@ -0,0 +1,36 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--force"
+ - "--no-remove"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Merging 1 commit to main @ 66266ec (no commit/squash/rebase needed)
+  * 66266ec Add feature
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Merged to main (1 commit, 1 file, +1)
+⚪ Worktree preserved (--no-remove)
+🔄 Running user post-merge notify:
+  echo 'USER_POST_MERGE_RAN' > user_postmerge.txt
+
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_executes.snap
new file mode 100644
index 000000000..3609b3de5
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_executes.snap
@@ -0,0 +1,30 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
+🔄 Running user post-start bg:
+  echo 'USER_POST_START_RAN' > user_bg_marker.txt
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_skipped.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_skipped.snap
new file mode 100644
index 000000000..eded8f916
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_skipped.snap
@@ -0,0 +1,34 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ - "--no-user-hooks"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 2
+----- stdout -----
+
+----- stderr -----
+error: unexpected argument '--no-user-hooks' found
+
+ tip: to pass '--no-user-hooks' as a value, use '-- --no-user-hooks'
+
+Usage: wt switch --create <BRANCH>
+
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_skipped_no_verify.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_skipped_no_verify.snap
new file mode 100644
index 000000000..7261d6686
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_start_skipped_no_verify.snap
@@ -0,0 +1,29 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ - "--no-verify"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✅ Created new worktree for feature from main at [REPO].feature
+💡 Run wt config shell install to enable automatic cd
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_commit_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_commit_executes.snap
new file mode 100644
index 000000000..272ae1de2
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_commit_executes.snap
@@ -0,0 +1,41 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--force"
+ - "--no-remove"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🟡 Auto-staging 1 untracked path:
+  uncommitted.txt
+🔄 Running user pre-commit lint:
+  echo 'USER_PRE_COMMIT_RAN' > user_precommit.txt
+🔄 Committing changes with default message... (1 file, +1, no squashing needed)
+💡 Using fallback commit message. Run wt config --help for LLM setup guide
+  Changes to uncommitted.txt
+✅ Committed changes @ dd71589
+🔄 Merging 1 commit to main @ dd71589 (no rebase needed)
+  * dd71589 Changes to uncommitted.txt
+  uncommitted.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Merged to main (1 commit, 1 file, +1)
+⚪ Worktree preserved (--no-remove)
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_commit_failure.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_commit_failure.snap
new file mode 100644
index 000000000..343c33b46
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_commit_failure.snap
@@ -0,0 +1,34 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--force"
+ - "--no-remove"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+🟡 Auto-staging 1 untracked path:
+  uncommitted.txt
+🔄 Running user pre-commit lint:
+  exit 1
+❌ pre-commit command failed: lint: exit status: 1
+
+💡 Use --no-verify to skip pre-commit commands
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_executes.snap
new file mode 100644
index 000000000..9f8519151
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_executes.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--force"
+ - "--no-remove"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Running user pre-merge check:
+  echo 'USER_PRE_MERGE_RAN' > user_premerge.txt
+🔄 Merging 1 commit to main @ 66266ec (no commit/squash/rebase needed)
+  * 66266ec Add feature
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Merged to main (1 commit, 1 file, +1)
+⚪ Worktree preserved (--no-remove)
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_failure.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_failure.snap
new file mode 100644
index 000000000..f353f0c44
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_failure.snap
@@ -0,0 +1,32 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--force"
+ - "--no-remove"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+🔄 Running user pre-merge check:
+  exit 1
+❌ pre-merge command failed: check: exit status: 1
+
+💡 Use --no-verify to skip pre-merge commands
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped.snap
new file mode 100644
index 000000000..f1b3acfe3
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--force"
+ - "--no-remove"
+ - "--no-user-hooks"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 2
+----- stdout -----
+
+----- stderr -----
+error: unexpected argument '--no-user-hooks' found
+
+ tip: to pass '--no-user-hooks' as a value, use '-- --no-user-hooks'
+
+Usage: wt merge --force --no-remove <TARGET>
+
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped_no_verify.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped_no_verify.snap
new file mode 100644
index 000000000..5a56de979
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_merge_skipped_no_verify.snap
@@ -0,0 +1,34 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--force"
+ - "--no-remove"
+ - "--no-verify"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Merging 1 commit to main @ 66266ec (no commit/squash/rebase needed)
+  * 66266ec Add feature
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Merged to main (1 commit, 1 file, +1)
+⚪ Worktree preserved (--no-remove)
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_executes.snap
new file mode 100644
index 000000000..8fa80d106
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_executes.snap
@@ -0,0 +1,29 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - remove
+ - feature
+ - "--force-delete"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Running user pre-remove cleanup:
+  echo 'USER_PRE_REMOVE_RAN' > /tmp/user_preremove_marker.txt
+🔄 Removing feature worktree & branch in background (--force-delete)
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_failure.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_failure.snap
new file mode 100644
index 000000000..742156210
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_failure.snap
@@ -0,0 +1,31 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - remove
+ - feature
+ - "--force-delete"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+🔄 Running user pre-remove block:
+  exit 1
+❌ pre-remove command failed: block: exit status: 1
+
+💡 Use --no-verify to skip pre-remove commands
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_skipped.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_skipped.snap
new file mode 100644
index 000000000..68e54b5c5
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_skipped.snap
@@ -0,0 +1,34 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - remove
+ - feature
+ - "--force-delete"
+ - "--no-user-hooks"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: false
+exit_code: 2
+----- stdout -----
+
+----- stderr -----
+error: unexpected argument '--no-user-hooks' found
+
+ tip: to pass '--no-user-hooks' as a value, use '-- --no-user-hooks'
+
+Usage: wt remove --force-delete <WORKTREES>...
+
+For more information, try '--help'.
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_skipped_no_verify.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_skipped_no_verify.snap
new file mode 100644
index 000000000..1626940a9
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_skipped_no_verify.snap
@@ -0,0 +1,28 @@
+---
+source: tests/integration_tests/user_hooks.rs
+info:
+ program: wt
+ args:
+ - remove
+ - feature
+ - "--force-delete"
+ - "--no-verify"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+🔄 Removing feature worktree & branch in background (--force-delete)