Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: accept multiple NAME filters in hook subcommands (#2013)
Worktrunk Bot446e206ed680
diff --git a/docs/content/hook.md b/docs/content/hook.mdindex 12dc6cf27..eff045218 100644--- a/docs/content/hook.md+++ b/docs/content/hook.md@@ -207,7 +207,7 @@ if ctx['branch'].startswith('feature/') and 'backend' in ctx['repo']:`wt hook <type>` runs hooks on demand — useful for testing during development, running in CI pipelines, or re-running after a failure.-{{ terminal(cmd="wt hook pre-merge # Run all pre-merge hooks|||wt hook pre-merge test # Run hooks named __WT_QUOT__test__WT_QUOT__ from both sources|||wt hook pre-merge user: # Run all user hooks|||wt hook pre-merge project: # Run all project hooks|||wt hook pre-merge user:test # Run only user's __WT_QUOT__test__WT_QUOT__ hook|||wt hook pre-merge project:test # Run only project's __WT_QUOT__test__WT_QUOT__ hook|||wt hook pre-merge --yes # Skip approval prompts (for CI)|||wt hook pre-start --var branch=feature/test # Override template variable") }}+{{ terminal(cmd="wt hook pre-merge # Run all pre-merge hooks|||wt hook pre-merge test # Run hooks named __WT_QUOT__test__WT_QUOT__ from both sources|||wt hook pre-merge test build # Run hooks named __WT_QUOT__test__WT_QUOT__ and __WT_QUOT__build__WT_QUOT__|||wt hook pre-merge user: # Run all user hooks|||wt hook pre-merge project: # Run all project hooks|||wt hook pre-merge user:test # Run only user's __WT_QUOT__test__WT_QUOT__ hook|||wt hook pre-merge project:test # Run only project's __WT_QUOT__test__WT_QUOT__ hook|||wt hook pre-merge --yes # Skip approval prompts (for CI)|||wt hook pre-start --var branch=feature/test # Override template variable") }}The `user:` and `project:` prefixes filter by source. Use `user:` or `project:` alone to run all hooks from that source, or `user:name` / `project:name` to run a specific hook.diff --git a/skills/worktrunk/reference/hook.md b/skills/worktrunk/reference/hook.mdindex 7d25b8ec7..db75fba5b 100644--- a/skills/worktrunk/reference/hook.md+++ b/skills/worktrunk/reference/hook.md@@ -201,6 +201,7 @@ if ctx['branch'].startswith('feature/') and 'backend' in ctx['repo']:```bash$ wt hook pre-merge # Run all pre-merge hooks$ wt hook pre-merge test # Run hooks named "test" from both sources+$ wt hook pre-merge test build # Run hooks named "test" and "build"$ wt hook pre-merge user: # Run all user hooks$ wt hook pre-merge project: # Run all project hooks$ wt hook pre-merge user:test # Run only user's "test" hookdiff --git a/src/cli/hook.rs b/src/cli/hook.rsindex 169891d59..517804b59 100644--- a/src/cli/hook.rs+++ b/src/cli/hook.rs@@ -22,12 +22,12 @@ pub enum HookCommand {////// Blocking — waits for completion before continuing.PreSwitch {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -46,12 +46,12 @@ pub enum HookCommand {////// Background by default. Use `--foreground` to run in foreground for debugging.PostSwitch {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -75,12 +75,12 @@ pub enum HookCommand {/// Blocking — waits for completion before continuing.#[command(alias = "post-create")]PreStart {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -99,12 +99,12 @@ pub enum HookCommand {////// Background by default. Use `--foreground` to run in foreground for debugging.PostStart {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -125,12 +125,12 @@ pub enum HookCommand {/// Run pre-commit hooksPreCommit {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -149,12 +149,12 @@ pub enum HookCommand {////// Background by default. Use `--foreground` to run in foreground for debugging.PostCommit {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -175,12 +175,12 @@ pub enum HookCommand {/// Run pre-merge hooksPreMerge {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -199,12 +199,12 @@ pub enum HookCommand {////// Background by default. Use `--foreground` to run in foreground for debugging.PostMerge {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -225,12 +225,12 @@ pub enum HookCommand {/// Run pre-remove hooksPreRemove {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]@@ -249,12 +249,12 @@ pub enum HookCommand {////// Background by default. Use `--foreground` to run in foreground for debugging.PostRemove {- /// Filter by command name+ /// Filter by command name(s)////// Supports `user:name` or `project:name` to filter by source./// `user:` alone runs all user hooks; `project:` alone runs all project hooks.#[arg(add = crate::completion::hook_command_name_completer())]- name: Option<String>,+ name: Vec<String>,/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]diff --git a/src/cli/mod.rs b/src/cli/mod.rsindex 2ab37e6c6..6e21adb4f 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -1368,6 +1368,7 @@ if ctx['branch'].startswith('feature/') and 'backend' in ctx['repo']:```console$ wt hook pre-merge # Run all pre-merge hooks$ wt hook pre-merge test # Run hooks named "test" from both sources+$ wt hook pre-merge test build # Run hooks named "test" and "build"$ wt hook pre-merge user: # Run all user hooks$ wt hook pre-merge project: # Run all project hooks$ wt hook pre-merge user:test # Run only user's "test" hookdiff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rsindex 1404737fb..a36f3399b 100644--- a/src/commands/command_approval.rs+++ b/src/commands/command_approval.rs@@ -192,16 +192,16 @@ pub fn approve_hooks(ctx: &super::command_executor::CommandContext<'_>,hook_types: &[HookType],) -> anyhow::Result<bool> {- approve_hooks_filtered(ctx, hook_types, None)+ approve_hooks_filtered(ctx, hook_types, &[])}-/// Like `approve_hooks` but with optional name filter for targeted hook approval.+/// Like `approve_hooks` but with name filters 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.+/// When `name_filters` is non-empty, only commands matching those names are shown+/// in the approval prompt. This is used by `wt hook <type> <name...>` to+/// approve only the targeted hooks rather than all hooks of that type.///-/// Supports filter syntax:+/// Supports filter syntax per name:/// - `"foo"` — approves commands named "foo" from project config/// - `"project:foo"` — approves commands named "foo" from project config/// - `"project:"` — approves all commands from project config@@ -209,15 +209,20 @@ pub fn approve_hooks(pub fn approve_hooks_filtered(ctx: &super::command_executor::CommandContext<'_>,hook_types: &[HookType],- name_filter: Option<&str>,+ name_filters: &[String],) -> anyhow::Result<bool> {- // Parse filter to understand source and name separately+ // Parse filters to understand source and name separately// Uses the same ParsedFilter as hooks.rs for consistent behavior- let parsed = name_filter.map(ParsedFilter::parse);+ let parsed_filters: Vec<ParsedFilter<'_>> = name_filters+ .iter()+ .map(|f| ParsedFilter::parse(f))+ .collect();- // If filter explicitly targets user hooks only, skip project approval entirely- if let Some(ref f) = parsed- && f.source == Some(HookSource::User)+ // If all filters explicitly target user hooks only, skip project approval entirely+ if !parsed_filters.is_empty()+ && parsed_filters+ .iter()+ .all(|f| f.source == Some(HookSource::User)){return Ok(true);}@@ -229,13 +234,21 @@ pub fn approve_hooks_filtered(let mut commands = collect_commands_for_hooks(&project_config, hook_types);- // Apply name filter before approval to only prompt for targeted commands- // Use the parsed name (not raw filter) for matching- // Empty name (e.g., "project:") means match all project commands - no filtering- if let Some(ref f) = parsed- && !f.name.is_empty()- {- commands.retain(|cmd| cmd.command.name.as_deref() == Some(f.name));+ // Apply name filters before approval to only prompt for targeted commands+ // Collect non-empty name parts from filters+ // Empty names (e.g., "project:") mean match all project commands - no filtering+ let filter_names: Vec<&str> = parsed_filters+ .iter()+ .map(|f| f.name)+ .filter(|n| !n.is_empty())+ .collect();+ if !filter_names.is_empty() {+ commands.retain(|cmd| {+ cmd.command+ .name+ .as_deref()+ .is_some_and(|n| filter_names.contains(&n))+ });}if commands.is_empty() {diff --git a/src/commands/commit.rs b/src/commands/commit.rsindex a10d6f30f..b504840a1 100644--- a/src/commands/commit.rs+++ b/src/commands/commit.rs@@ -186,7 +186,7 @@ impl CommitOptions<'_> {project_config: proj_cfg,hook_type: HookType::PreCommit,extra_vars: &extra_vars,- name_filter: None,+ name_filters: &[],display_path: crate::output::pre_hook_display_path(self.ctx.worktree_path),},HookFailureStrategy::FailFast,diff --git a/src/commands/handle_switch.rs b/src/commands/handle_switch.rsindex 9aa30ae43..af0e08594 100644--- a/src/commands/handle_switch.rs+++ b/src/commands/handle_switch.rs@@ -148,7 +148,7 @@ pub(crate) fn run_pre_switch_hooks(HookType::PreSwitch,&extra_vars,HookFailureStrategy::FailFast,- None,+ &[],crate::output::pre_hook_display_path(pre_ctx.worktree_path),)?;}diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rsindex 0148f7ff4..012eed7b6 100644--- a/src/commands/hook_commands.rs+++ b/src/commands/hook_commands.rs@@ -38,7 +38,7 @@ fn run_filtered_hook(project_config: Option<&CommandConfig>,hook_type: HookType,extra_vars: &[(&str, &str)],- name_filter: Option<&str>,+ name_filters: &[String],failure_strategy: HookFailureStrategy,) -> anyhow::Result<()> {run_hook_with_filter(@@ -48,7 +48,7 @@ fn run_filtered_hook(project_config,hook_type,extra_vars,- name_filter,+ name_filters,display_path: crate::output::pre_hook_display_path(ctx.worktree_path),},failure_strategy,@@ -62,11 +62,11 @@ fn run_post_hook(project_config: Option<&CommandConfig>,hook_type: HookType,extra_vars: &[(&str, &str)],- name_filter: Option<&str>,+ name_filters: &[String],) -> anyhow::Result<()> {// Default to background execution; --foreground is for debugging.if !foreground.unwrap_or(false) {- if name_filter.is_some() {+ if !name_filters.is_empty() {// Name filtering operates on individual commands — extract matching// commands, convert to pipeline steps, and spawn via pipeline runner.let commands = prepare_hook_commands(@@ -76,11 +76,11 @@ fn run_post_hook(project_config,hook_type,extra_vars,- name_filter,+ name_filters,display_path: None,},)?;- check_name_filter_matched(name_filter, commands.len(), user_config, project_config)?;+ check_name_filter_matched(name_filters, commands.len(), user_config, project_config)?;let steps: Vec<SourcedStep> = commands.into_iter().map(|cmd| SourcedStep {@@ -106,7 +106,7 @@ fn run_post_hook(project_config,hook_type,extra_vars,- name_filter,+ name_filters,HookFailureStrategy::Warn,)}@@ -182,7 +182,7 @@ pub fn run_hook(yes: bool,foreground: Option<bool>,dry_run: bool,- name_filter: Option<&str>,+ name_filters: &[String],custom_vars: &[(String, String)],) -> anyhow::Result<()> {// Derive context from current environment (branch-optional for CI compatibility)@@ -195,8 +195,8 @@ pub fn run_hook(if !dry_run {// "Approve at the Gate": approve project hooks upfront- // Pass name_filter to only approve the targeted hook, not all hooks of this type- let approved = approve_hooks_filtered(&ctx, &[hook_type], name_filter)?;+ // Pass name_filters to only approve the targeted hooks, not all hooks of this type+ let approved = approve_hooks_filtered(&ctx, &[hook_type], name_filters)?;// If declined, return early - the whole point of `wt hook` is to run hooksif !approved {eprintln!("{}", worktrunk::styling::info_message("Commands declined"));@@ -252,11 +252,11 @@ pub fn run_hook(project_config: proj_config,hook_type,extra_vars: &extra_vars,- name_filter,+ name_filters,display_path: None,},)?;- check_name_filter_matched(name_filter, commands.len(), user_config, proj_config)?;+ check_name_filter_matched(name_filters, commands.len(), user_config, proj_config)?;for cmd in &commands {let label = match &cmd.prepared.name {@@ -290,7 +290,7 @@ pub fn run_hook(proj_config,hook_type,&extra_vars,- name_filter,+ name_filters,HookFailureStrategy::FailFast,),HookType::PostStart@@ -304,7 +304,7 @@ pub fn run_hook(proj_config,hook_type,&extra_vars,- name_filter,+ name_filters,),}}diff --git a/src/commands/hooks.rs b/src/commands/hooks.rsindex 00ffacd84..fa7178176 100644--- a/src/commands/hooks.rs+++ b/src/commands/hooks.rs@@ -84,7 +84,7 @@ pub struct HookCommandSpec<'cfg, 'vars, 'name, 'path> {pub project_config: Option<&'cfg CommandConfig>,pub hook_type: HookType,pub extra_vars: &'vars [(&'vars str, &'vars str)],- pub name_filter: Option<&'name str>,+ pub name_filters: &'name [String],pub display_path: Option<&'path Path>,}@@ -105,11 +105,14 @@ pub fn prepare_hook_commands(project_config,hook_type,extra_vars,- name_filter,+ name_filters,display_path,} = spec;- let parsed_filter = name_filter.map(ParsedFilter::parse);+ let parsed_filters: Vec<ParsedFilter<'_>> = name_filters+ .iter()+ .map(|f| ParsedFilter::parse(f))+ .collect();let mut commands = Vec::new();let display_path = display_path.map(|p| p.to_path_buf());@@ -123,16 +126,13 @@ pub fn prepare_hook_commands(for (source, config) in sources {let Some(config) = config else { continue };- // Skip if filter specifies a different source- if !parsed_filter- .as_ref()- .is_none_or(|f| f.matches_source(source))- {+ // Skip if all filters specify a different source+ if !parsed_filters.is_empty() && !parsed_filters.iter().any(|f| f.matches_source(source)) {continue;}let prepared = prepare_commands(config, ctx, extra_vars, hook_type, source)?;- let filtered = filter_by_name(prepared, parsed_filter.as_ref().map(|f| f.name));+ let filtered = filter_by_name(prepared, &parsed_filters);commands.extend(filtered.into_iter().map(|p| SourcedCommand {prepared: p,source,@@ -144,19 +144,39 @@ pub fn prepare_hook_commands(Ok(commands)}-/// Filter commands by name (returns empty vec if name not found).-/// Empty name matches all commands (supports `user:` to mean "all user hooks").+/// Filter commands by name (returns empty vec if no names match).+/// Empty slice matches all commands. Each filter's name component is checked+/// independently — empty names (from `user:` or `project:`) match all commands+/// from that source (source filtering is handled by the caller).fn filter_by_name(commands: Vec<PreparedCommand>,- name_filter: Option<&str>,+ parsed_filters: &[ParsedFilter<'_>],) -> Vec<PreparedCommand> {- match name_filter {- Some(name) if !name.is_empty() => commands- .into_iter()- .filter(|cmd| cmd.name.as_deref() == Some(name))- .collect(),- _ => commands, // None or empty = match all+ if parsed_filters.is_empty() {+ return commands; // No filters = match all+ }++ // Collect the non-empty name parts from filters+ let filter_names: Vec<&str> = parsed_filters+ .iter()+ .map(|f| f.name)+ .filter(|n| !n.is_empty())+ .collect();++ // If all filters have empty names (e.g., just "user:" or "project:"),+ // match all commands (source filtering already handled by caller)+ if filter_names.is_empty() {+ return commands;}++ commands+ .into_iter()+ .filter(|cmd| {+ cmd.name+ .as_deref()+ .is_some_and(|n| filter_names.contains(&n))+ })+ .collect()}/// A pipeline step with source information, for pipeline-aware execution.@@ -392,28 +412,34 @@ fn spawn_hook_pipeline_quiet(ctx: &CommandContext, steps: Vec<SourcedStep>) -> aOk(())}-/// Check if a name filter was provided but no commands matched.+/// Check if name filters were provided but no commands matched./// Returns an error listing available command names if so.pub(crate) fn check_name_filter_matched(- name_filter: Option<&str>,+ name_filters: &[String],total_commands_run: usize,user_config: Option<&CommandConfig>,project_config: Option<&CommandConfig>,) -> anyhow::Result<()> {- if let Some(filter_str) = name_filter- && total_commands_run == 0- {- let parsed = ParsedFilter::parse(filter_str);+ if !name_filters.is_empty() && total_commands_run == 0 {+ // Show the combined filter string in the error+ let filter_display = name_filters.join(", ");++ // Use the first filter to determine source scope for available commands,+ // but collect across all filters' source scopes+ let parsed_filters: Vec<ParsedFilter<'_>> = name_filters+ .iter()+ .map(|f| ParsedFilter::parse(f))+ .collect();let mut available = Vec::new();- // Collect available commands from sources that match the filterlet sources = [(HookSource::User, user_config),(HookSource::Project, project_config),];for (source, config) in sources {let Some(config) = config else { continue };- if !parsed.matches_source(source) {+ // Include this source if any filter matches it+ if !parsed_filters.iter().any(|f| f.matches_source(source)) {continue;}available.extend(@@ -424,7 +450,7 @@ pub(crate) fn check_name_filter_matched(}return Err(worktrunk::git::GitError::HookCommandNotFound {- name: filter_str.to_string(),+ name: filter_display,available,}.into());@@ -450,11 +476,11 @@ pub fn run_hook_with_filter(user_config,project_config,hook_type,- name_filter,+ name_filters,..} = spec;- check_name_filter_matched(name_filter, commands.len(), user_config, project_config)?;+ check_name_filter_matched(name_filters, commands.len(), user_config, project_config)?;if commands.is_empty() {return Ok(());@@ -542,7 +568,7 @@ pub fn execute_hook(hook_type: HookType,extra_vars: &[(&str, &str)],failure_strategy: HookFailureStrategy,- name_filter: Option<&str>,+ name_filters: &[String],display_path: Option<&Path>,) -> anyhow::Result<()> {let project_config = ctx.repo.load_project_config()?;@@ -557,7 +583,7 @@ pub fn execute_hook(project_config: proj_config,hook_type,extra_vars,- name_filter,+ name_filters,display_path,},failure_strategy,diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 16e0c7c51..fe8f34efe 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -240,7 +240,7 @@ pub fn handle_merge(opts: MergeOptions<'_>) -> anyhow::Result<()> {HookType::PreMerge,&extra,HookFailureStrategy::FailFast,- None,+ &[],crate::output::pre_hook_display_path(ctx.worktree_path),)?;}diff --git a/src/commands/picker/mod.rs b/src/commands/picker/mod.rsindex ab3506c65..cb2494236 100644--- a/src/commands/picker/mod.rs+++ b/src/commands/picker/mod.rs@@ -117,7 +117,7 @@ impl PickerCollector {worktrunk::HookType::PreRemove,&extra_vars,HookFailureStrategy::FailFast,- None,+ &[],None, // no display path in TUI context)?;diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rsindex 2236a6897..fd20e5c49 100644--- a/src/commands/step_commands.rs+++ b/src/commands/step_commands.rs@@ -206,7 +206,7 @@ pub fn handle_squash(project_config: proj_cfg,hook_type: HookType::PreCommit,extra_vars: &extra_vars,- name_filter: None,+ name_filters: &[],display_path: crate::output::pre_hook_display_path(ctx.worktree_path),},HookFailureStrategy::FailFast,diff --git a/src/commands/worktree/hooks.rs b/src/commands/worktree/hooks.rsindex bc501d526..1e9766f39 100644--- a/src/commands/worktree/hooks.rs+++ b/src/commands/worktree/hooks.rs@@ -26,7 +26,7 @@ impl<'a> CommandContext<'a> {HookType::PreStart,extra_vars,HookFailureStrategy::FailFast,- None,+ &[],crate::output::post_hook_display_path(self.worktree_path),)}diff --git a/src/main.rs b/src/main.rsindex 30faf6006..ddd80c3e7 100644--- a/src/main.rs+++ b/src/main.rs@@ -119,10 +119,10 @@ fn run_non_toggle_hook(hook_type: HookType,yes: bool,dry_run: bool,- name: Option<&str>,+ names: &[String],vars: &[(String, String)],) -> anyhow::Result<()> {- run_hook(hook_type, yes, None, dry_run, name, vars)+ run_hook(hook_type, yes, None, dry_run, names, vars)}fn run_toggleable_hook(@@ -130,10 +130,10 @@ fn run_toggleable_hook(yes: bool,dry_run: bool,foreground: bool,- name: Option<&str>,+ names: &[String],vars: &[(String, String)],) -> anyhow::Result<()> {- run_hook(hook_type, yes, Some(foreground), dry_run, name, vars)+ run_hook(hook_type, yes, Some(foreground), dry_run, names, vars)}fn warn_select_deprecated() {@@ -168,87 +168,59 @@ fn handle_hook_command(action: HookCommand) -> anyhow::Result<()> {yes,dry_run,vars,- } => run_non_toggle_hook(HookType::PreSwitch, yes, dry_run, name.as_deref(), &vars),+ } => run_non_toggle_hook(HookType::PreSwitch, yes, dry_run, &name, &vars),HookCommand::PostSwitch {name,yes,dry_run,foreground,vars,- } => run_toggleable_hook(- HookType::PostSwitch,- yes,- dry_run,- foreground,- name.as_deref(),- &vars,- ),+ } => run_toggleable_hook(HookType::PostSwitch, yes, dry_run, foreground, &name, &vars),HookCommand::PreStart {name,yes,dry_run,vars,- } => run_non_toggle_hook(HookType::PreStart, yes, dry_run, name.as_deref(), &vars),+ } => run_non_toggle_hook(HookType::PreStart, yes, dry_run, &name, &vars),HookCommand::PostStart {name,yes,dry_run,foreground,vars,- } => run_toggleable_hook(- HookType::PostStart,- yes,- dry_run,- foreground,- name.as_deref(),- &vars,- ),+ } => run_toggleable_hook(HookType::PostStart, yes, dry_run, foreground, &name, &vars),HookCommand::PreCommit {name,yes,dry_run,vars,- } => run_non_toggle_hook(HookType::PreCommit, yes, dry_run, name.as_deref(), &vars),+ } => run_non_toggle_hook(HookType::PreCommit, yes, dry_run, &name, &vars),HookCommand::PostCommit {name,yes,dry_run,foreground,vars,- } => run_toggleable_hook(- HookType::PostCommit,- yes,- dry_run,- foreground,- name.as_deref(),- &vars,- ),+ } => run_toggleable_hook(HookType::PostCommit, yes, dry_run, foreground, &name, &vars),HookCommand::PreMerge {name,yes,dry_run,vars,- } => run_non_toggle_hook(HookType::PreMerge, yes, dry_run, name.as_deref(), &vars),+ } => run_non_toggle_hook(HookType::PreMerge, yes, dry_run, &name, &vars),HookCommand::PostMerge {name,yes,dry_run,foreground,vars,- } => run_toggleable_hook(- HookType::PostMerge,- yes,- dry_run,- foreground,- name.as_deref(),- &vars,- ),+ } => run_toggleable_hook(HookType::PostMerge, yes, dry_run, foreground, &name, &vars),HookCommand::PreRemove {name,yes,dry_run,vars,- } => run_non_toggle_hook(HookType::PreRemove, yes, dry_run, name.as_deref(), &vars),+ } => run_non_toggle_hook(HookType::PreRemove, yes, dry_run, &name, &vars),HookCommand::PostRemove {name,yes,@@ -260,7 +232,7 @@ fn handle_hook_command(action: HookCommand) -> anyhow::Result<()> {yes,Some(foreground),dry_run,- name.as_deref(),+ &name,&vars,),HookCommand::RunPipeline => commands::run_pipeline(),diff --git a/src/output/handlers.rs b/src/output/handlers.rsindex 7f310aa96..5aef851ad 100644--- a/src/output/handlers.rs+++ b/src/output/handlers.rs@@ -1169,7 +1169,7 @@ fn execute_pre_remove_hooks_if_needed(worktrunk::HookType::PreRemove,&extra_vars,HookFailureStrategy::FailFast,- None,+ &[],display_path,)}diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rsindex ae8a4a926..262973100 100644--- a/tests/integration_tests/user_hooks.rs+++ b/tests/integration_tests/user_hooks.rs@@ -1740,6 +1740,45 @@ first = "echo 'FIRST'");}+#[rstest]+fn test_hook_multiple_name_filters(repo: TestRepo) {+ // Write project config with three named hooks+ repo.write_project_config(+ r#"[pre-merge]+first = "echo FIRST"+second = "echo SECOND"+third = "echo THIRD"+"#,+ );++ // Run only "first" and "second" by passing multiple names — "third" should not run+ assert_cmd_snapshot!(+ "hook_multiple_name_filters",+ make_snapshot_cmd(+ &repo,+ "hook",+ &["pre-merge", "first", "second", "--yes"],+ None+ )+ );+}++#[rstest]+fn test_hook_multiple_name_filters_none_match(repo: TestRepo) {+ // Write project config with named hooks+ repo.write_project_config(+ r#"[pre-merge]+first = "echo FIRST"+"#,+ );++ // Run with multiple names that don't match any configured hook+ assert_cmd_snapshot!(+ "hook_multiple_name_filters_none_match",+ make_snapshot_cmd(&repo, "hook", &["pre-merge", "foo", "bar", "--yes"], None)+ );+}+// ============================================================================// Custom Variable (--var) Tests// ============================================================================diff --git a/tests/snapshots/integration__integration_tests__user_hooks__hook_multiple_name_filters.snap b/tests/snapshots/integration__integration_tests__user_hooks__hook_multiple_name_filters.snapnew file mode 100644index 000000000..310270724--- /dev/null+++ b/tests/snapshots/integration__integration_tests__user_hooks__hook_multiple_name_filters.snap@@ -0,0 +1,55 @@+---+source: tests/integration_tests/user_hooks.rs+info:+ program: wt+ args:+ - hook+ - pre-merge+ - first+ - second+ - "--yes"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ 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: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mRunning pre-merge [1mproject:first[22m[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m FIRST+[0mFIRST+[36m◎[39m [36mRunning pre-merge [1mproject:second[22m[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m SECOND+[0mSECONDdiff --git a/tests/snapshots/integration__integration_tests__user_hooks__hook_multiple_name_filters_none_match.snap b/tests/snapshots/integration__integration_tests__user_hooks__hook_multiple_name_filters_none_match.snapnew file mode 100644index 000000000..0b76db2f5--- /dev/null+++ b/tests/snapshots/integration__integration_tests__user_hooks__hook_multiple_name_filters_none_match.snap@@ -0,0 +1,50 @@+---+source: tests/integration_tests/user_hooks.rs+info:+ program: wt+ args:+ - hook+ - pre-merge+ - foo+ - bar+ - "--yes"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ 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: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[31m✗[39m [31mNo command named [1mfoo, bar[22m (available: [1mproject:first[22m)[39m