Repository navigation
Conversation
Minimizing a task stops its agents but leaves running whatever its worktree started, such as a docker compose stack per worktree. With many tasks set aside, those stacks hold memory until each task is closed, and only closing runs the teardown script, which also removes the worktree. Two optional per-project scripts sit next to Setup and Teardown under Project settings → Tasks → Worktree setup: - Suspend script: runs in the worktree when a task is minimized, or snoozed with its agents stopped, after the agents stop. Snoozing with agents running does not run it. - Resume script: runs when that task is restored. A task is marked suspended when the script runs, and the mark is persisted, so a restore after a restart resumes only tasks that were suspended. Both run headless like teardown, with the same variables, project env and two-minute limit, and only in a folder git lists as a worktree of the repository. Neither holds up the minimize or restore; a failure is announced in a notification naming the task. Scripts on one worktree now run one at a time in the order asked, so a quick restore resumes after the suspend finished, and a close right after a minimize tears down after it. The headless runner is renamed from runTeardownScript to runWorktreeScript, and its failure notice takes the script's label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Minimizing a task ("Minimize (stop agents)", or a snooze that stops agents) stops its agents, but whatever the task's worktree started keeps running. With a docker compose stack per worktree (an app server, a frontend, a database, a cache), twenty-odd minimized tasks kept that many stacks up: tens of GB of RAM and swap for tasks nobody was working on. Only closing a task stops them, through the Teardown script, and closing also removes the worktree.
This adds two optional per-project scripts next to Setup and Teardown (#349), under Project settings → Tasks → Worktree setup:
docker compose stop). Snoozing a task that keeps its agents running does not run it: those agents may still need the services.docker compose start). The task is marked suspended when its suspend script runs, and the mark is persisted, so a restore after a restart resumes only tasks that were suspended. A task minimized before the scripts were set up is left as it was.They follow the Teardown script's design: headless on the host, in the worktree, with
PARALLEL_CODE_ROOT_PATH,PARALLEL_CODE_WORKTREE,PARALLEL_CODE_BRANCHand the project's env vars, two minutes at most, and only in a foldergit worktree listreports for the repository. Neither holds up the minimize or the restore: the layout changes at once, and a failure is announced in a notification naming the task, with the last lines of output. A project with neither set behaves exactly as before.Scripts on one worktree now run one at a time, in the order asked, so a quick minimize-and-restore resumes only after the suspend finished, and closing a task right after minimizing it tears down after the suspend.
Implementation:
electron/ipc/worktree-scripts.ts:runTeardownScriptbecomesrunWorktreeScript(with a per-worktree queue), anddescribeWorktreeScriptFailuretakes the script's label. Teardown behaviour is unchanged.RunWorktreeLifecycleScript(manifest and preload allowlist), validated likeDeleteTask's teardown fields.collapseTask/uncollapseTasksend the scripts;Task.worktreeSuspendedis persisted for minimized tasks.docs/features.md.They run for every task with a worktree, imported ones and archived sub-tasks included, but not for tasks on the current branch.
How I checked it
npm run check,npm run check:staticandnpm testpass.updateProject; the settings dialog saves both fieldsdocker compose -p <project> stopfor the worktree's stack) and resume script against real compose stacks: stopped on suspend, started on resume, volumes kept.Screenshots
Project settings → Tasks → Worktree setup, with a setup and a teardown script set.
Agent use
Claude Code wrote and tested this change.
🤖 Generated with Claude Code (Opus 5.5)