Skip to main content

Module worktree

Module worktree 

Source
Expand description

A git worktree per supervisor task (#570).

A task with a git_ref runs in its own worktree on its own branch, so parallel tasks over one repo never edit the same checkout. The worktree lives under ~/.claudectl/worktrees/<task-id>, outside the repo, so it never shows up in that repo’s git status.

  • Reused, not recreated. A retry or a resume of the same task finds its worktree and keeps working in it.
  • Removed after DONE only if clean. An agent that left uncommitted changes left its work there, and removing the worktree would destroy it. The branch is always kept.
  • No git means no worktree: a git_ref on a non-repo is an error, not a silent fallback to the plain cwd.

Structs§

Worktree
A worktree a task runs in.

Enums§

Cleanup
What cleanup did.

Functions§

cleanup
Remove a finished task’s worktree if nothing would be lost; keep the branch either way.
default_branch
The branch a task gets when it doesn’t name one: claudectl/<name>-<id>, with the name reduced to lowercase letters, digits and -.
ensure
Make sure the task’s worktree exists at path on branch, starting from git_ref, in the repo containing cwd. Reuses one already there.
path_for
Where task task_id’s worktree goes.
repo_root
The repo cwd is in.
validate_ref
Check a ref or branch name before it goes on a git command line. It comes from a tasks file; a leading - would read as an option.