Re: [PATCH v2 0/4] worktree: add lifecycle hooks
- From
- Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
- Date
- Sep 7, 2026, 18:18 UTC
- Message-ID
- <de83b791-92ae-41a1-8ecf-5abce7893998@app.fastmail.com>
- In-Reply-To
- <b10f2706-67bb-4657-8d7c-819a29dff890@mtasv.net>
On Mon, Sep 7, 2026, at 16:30, Domen Kožar wrote:
Show 8 quoted lines
> A gentle ping on the single "post-worktree" hook proposal below. > > As coding agents increasingly create and discard worktrees, reliable > lifecycle notifications matter more because tools managing environments > and cleanup cannot control every caller invoking Git. > > Would this interface address your concerns? I'm happy to prepare v3 if > we can agree on the direction.
The problem is multiple callers invoking Git with different intentions. What if `git worktree add` learned an option `--id=<string>` which is then stored in the worktree? This would communicate that whoever calls git-worktree(1) commands with this ID is the one who owns it.[1] git-worktree(1) commands which do not get an `--id` (and specifically that ID) does nothing to owned worktrees.
[1]: You know, among friendly and cooperating processes.
Then you don’t need hooks for adding, removing, pruning and whatever else.
I could imagine an agent tool that uses it’s own ID to manage a pool of worktrees.
I could imagine more metadata, like recording a timestamp for worktree expiry... but you don’t need anything more in git-worktree(1) itself if you have this ID concept. Then you can let tools implement it themselves. They won’t have their worktrees bothered/clobbered by other tools, so they can manage the whole lifecycle in peace.