Skip to main content

worktree_creation_obstacle

Function worktree_creation_obstacle 

Source
pub fn worktree_creation_obstacle(
    repo: &Path,
    label: &str,
    path: &Path,
) -> Option<String>
Expand description

What git refuses to create a worker’s worktree for at path, when there is something: the worktree-<label> branch already checked out in another worktree, a path taken by something that is not this worktree, or a registration git will not reuse.

The worktree is claude’s to create - it is handed --worktree <label> - and a creation that does nothing still leaves the session started, so a worker can read live with nowhere to work. Asking git the question that creation asks lets the caller refuse that spawn instead, and leaves who creates the worktree unchanged.

None when git cannot be asked: this exists to catch a silent failure, not to block a spawn on a probe that never answered.

The label is taken raw, the way forge’s worktree paths take it everywhere else. claude sanitises the name before deriving the path and the branch, so a label carrying / is a divergence that predates this check rather than one it widens.