Repository navigation
feat(worktrees): run actions before removal - #9337
bradymwilliams wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f029b24. Configure here.
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds an opt-in teardown workflow that executes configured shell commands and can block worktree deletion, alongside cross-cutting UI, contract, and server changes. The new process-execution and removal semantics warrant human review. Notes:
You can add or adjust custom eligibility rules. Learn more. |
|
+1 Are we going to see this land sometime soon? I'm in the process of switching over from superset and this is driving me crazy. On wt up I start a docker container so each agent can work on their isolated db. without the teardown, these containers keep piling up and at some point my macbook just freezes. Because of this, I am sticking with superset for those repos, but I really would like to make the move |
|
Thanks for the PR. We're not taking changes to the orchestration and provider layers right now: that part of the server is being rewritten for V2, and merging into the current code would either conflict with or be thrown away by that work. Closing for now. If this is still an issue once V2 lands, please reopen (or open a fresh PR against the new code) and we'll take a proper look. |



Projects can run an action when a worktree is created, but they have no matching hook before removal. Users must run cleanup commands by hand, and worktree deletion can leave generated resources behind.
This change adds one optional teardown action per project. T3 runs it in the worktree before removal and stops the removal when the command fails. The action editor, shared contracts, mobile labels, user documentation, and focused tests now include the new lifecycle step.
Safety model
Tests
Created with GPT-5.6 Sol using the Codex harness in T3 Code.
Note
Medium Risk
Worktree removal now executes configured shell commands and aborts removal on failure, which affects cleanup workflows and could leave worktrees in place if teardown errors.
Overview
Adds an optional teardown lifecycle for project actions, symmetric to existing setup-on-create behavior. Scripts can be marked run automatically before worktree removal in the web editor, settings, and
t3.json; only one setup and one teardown action are kept at a time viaclearProjectScriptLifecycleConflicts.Server:
ProjectSetupScriptRunnergainsrunBeforeWorktreeRemove, which finds the teardown script and runs its command in the worktree (host shell / PowerShell on Windows) withT3CODE_*env vars.GitWorkflowService.removeWorktreeruns teardown only when the worktree path still exists, then removes the worktree; a non-zero exit surfaces asGitCommandErrorwith commandproject teardown scriptand blocks deletion. Wiring addsProcessRunnerto the script runner layer.Clients & contracts: Optional
runOnWorktreeRemoveonProjectScript/ file schema; mobile and web menus show(teardown)/ badges. User docs describe setup/teardown and failure behavior. Tests cover runner, workflow ordering, and lifecycle helpers.Reviewed by Cursor Bugbot for commit c00a042. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add teardown scripts before worktree removal in
GitWorkflowServiceGitWorkflowService.removeWorktreenow runs the configured project teardown script before invoking VCS removal for existing worktree paths; missing paths skip teardown and proceed to removal as before.ProjectSetupScriptRunnergainsrunBeforeWorktreeRemove, which executes the selected teardown script in the worktree using PowerShell on win32 or the configured login shell elsewhere, and fails on process errors or nonzero exit codes.runOnWorktreeRemoveflag with badges, lifecycle-conflict clearing that keeps setup and teardown independent, and primary-script selection that excludes lifecycle scripts.runOnWorktreeRemovetoProjectScriptandT3ProjectFileScript; older snapshots and project files decode with the field absent.removeWorktreeaborts VCS removal and returns aGitCommandErrorwhen teardown fails; reviewers should check GitWorkflowService.ts and ProjectSetupScriptRunner.ts for error mapping of nonzero exit codes.Macroscope summarized c00a042.