Skip to content

Feature request: reap processes started in a worktree on wt remove? #3365

Description

@max-sixty

Removing a worktree leaves behind any long-running processes that were started inside it — dev servers, watchers, language servers, tmux panes spawned by a post-start hook. wt remove deletes the directory (or trashes it) but the processes keep running, holding ports and file handles and, on the trash path, referencing files that no longer exist at their old path.

Would it be feasible for wt to reap those processes, perhaps as an option on wt remove?

The interesting part is identifying which processes "belong to" the worktree, since that's where I'd expect the feasibility to be decided:

  • By working directory — processes whose cwd is under the worktree path (lsof -a -d cwd +D <path> on macOS, /proc/*/cwd on Linux). Catches most dev servers, but misses a process that started in the worktree and then chdir'd away, and a daemon that forked and re-parented to init.
  • By process group / session — if wt recorded the pgid of hook-spawned processes at post-start, it could signal that group at remove. More reliable for things wt itself launched, but nothing for processes the user started by hand in the worktree.
  • By tmux/zellij session — for the common case where a post-start hook opens a multiplexer session named after the worktree, "reaping" might just mean killing that session.

Open questions:

  • Is cwd-based detection reliable enough to reap by default, or would it need to be opt-in given the risk of killing something unrelated?
  • Should this build on the existing pre-remove hook (letting the user supply the kill logic) rather than wt implementing process discovery itself? A pre-remove hook already has the worktree path and can run whatever the user wants — so this might be a docs/example question rather than a code one.
  • How should it interact with the trash-vs-delete path and the --force flag?

Mostly asking whether this is in scope for wt at all, versus something better left to a user-supplied pre-remove hook.

This was written by Claude Code on behalf of max

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions