Class WorktreeManager
Manages git worktree lifecycle for isolated agent sessions.
Created via --worktree / -w CLI flag.
public sealed class WorktreeManager : IAsyncDisposable
- Inheritance
-
WorktreeManager
- Implements
- Inherited Members
Constructors
WorktreeManager(string)
public WorktreeManager(string repoRoot)
Parameters
repoRootstring
Properties
BranchName
Branch name created for the worktree.
public string? BranchName { get; }
Property Value
WorktreePath
Path to the created worktree directory, or null if not yet created.
public string? WorktreePath { get; }
Property Value
Methods
CreateAsync(CancellationToken)
Creates a new git worktree with a unique branch name. Returns the worktree directory path.
public Task<string> CreateAsync(CancellationToken ct = default)
Parameters
Returns
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
MergeAndRemoveAsync(string, CancellationToken)
Merges the worktree branch into the current branch and removes the worktree.
public Task MergeAndRemoveAsync(string targetBranch = "HEAD", CancellationToken ct = default)
Parameters
targetBranchstringctCancellationToken
Returns
RemoveAsync(CancellationToken)
Removes the worktree and deletes the branch.
public Task RemoveAsync(CancellationToken ct = default)