Skip to main content

run_event

Function run_event 

Source
pub fn run_event(event: &str, cwd: &Path) -> Result<()>
Expand description

Run the configured hook for event (one of "post_new", "pre_rm"), resolving the hook command from the layered config rooted at the main repo (resolved from cwd via git::get_main_repo_root, falling back to cwd if that fails). The hook runs with cwd as its working directory.

No-op (returns Ok(())) when the event name is unknown or the hook is unset. Hook is run as sh -c <cmd>. A non-zero exit propagates as CwError::Other.

Caller policy — this function always returns Err on non-zero exit; callers decide what that means:

  • pre_rm callers treat the error as advisory: log a warning, then continue with removal (aligned with Claude Code’s WorktreeRemove hook, which cannot block cleanup).
  • post_new callers treat the error as blocking: propagate it as a non-zero gw new exit code and skip the AI tool launch.