{"thread":{"id":"66370","subject":"Re: [RFC] worktree: add lifecycle hooks","startedAt":"2026-09-22T16:54:14Z","lastAt":"2026-09-22T16:54:14Z","messageCount":1,"participants":["Michał Papis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"553000","messageId":"CAJtm2pzYE5bNbPMATXczCYCVRf3q1T=tyJ1asfSYk9widQmBvQ@mail.gmail.com","threadId":"66370","inReplyTo":null,"subject":"Re: [RFC] worktree: add lifecycle hooks","fromName":"Michał Papis","fromEmail":"mpapis@gmail.com","sentAt":"2026-09-22T16:54:01Z","receivedAt":"2026-09-22T16:54:14Z","isPatch":false,"body":"The important piece for your use case is the pre-worktree-remove hook,\nnot just post-operation hooks.\n\nPost-hooks fire after the worktree is already gone. That's fine when a\ntool's state lives entirely inside the worktree. It breaks when the\nworktree points at state outside it — a docker container, a database,\nsockets, volumes. Then the worktree itself is the registry: its config\nis the only mapping from worktree to external resources, and\npre-remove is the only moment that mapping is still readable. After\nremoval you're guessing — hunting the disk for orphans, diffing\nagainst remaining worktrees, turning deterministic teardown into\nstale-data detection.\n\nReal example: with AI-generated worktrees (one per task, created and\ndiscarded faster than a human types), I was exhausting ~200GB of disk\nevery week and ended up writing cleanup scripts to reverse-engineer,\nfrom what was left on disk, which containers and databases belonged to\ndeleted worktrees. A pre-remove hook runs the same teardown with the\nconfig still present.\n\nThis is not about vetoing removal — pre-remove needs no power to\ncountermand anything. It's about doing cleanup with full information\ninstead of reconstructing it afterward.\n\nOne limit, which is why post hooks still matter: pre-remove only\napplies to git worktree remove. For manual deletion + git worktree\nprune, the tree is already gone, so pre-remove can't see it. The two\nare complementary.\n\nCheers / Pozdrawiam,\nMichal\n\n--\nMichal Papis\nphone. +48 603 751 266\n"}]}