Worktree switcherPro
The worktree and branch the agent works in, with uncommitted changes and drift from main. The list filters as you type, and the highlighted worktree previews what Apply to main would bring, conflicts included.
On this page
ProOpen on the retry worktree in an agent toolbar. Arrow keys move the apply preview; Apply to main merges and reports the commit, and the currency split shows its conflicts.
Installation
Usage
import { WorktreeSwitcher } from "@/components/ui/chatcn/pro/worktree-switcher"
<WorktreeSwitcher worktrees={worktrees} value={id} onValueChange={setId} onApply={applyToMain} />Each worktree has a branch, path, dirty (uncommitted files), ahead and behind against the base branch, stats for the apply preview, conflicts and the agent working in it. The preview under the list follows the highlighted row: commits and lines it would merge, a dot per commit ahead and behind, and the files that would conflict. Pass applying, applied and applyError to show the result in place.
Examples
States
ProThe trigger clean, with uncommitted changes and drift, a long branch, loading, and disabled while the agent runs.
Props
| Prop | Type | Notes |
|---|---|---|
worktrees | Worktree[] | name, branch, path, isMain, dirty, ahead, behind, stats, conflicts, agent |
value, defaultValue, onValueChange | string | Current worktree |
baseBranch | string | Default main |
onApply, applying, applied, applyError | Apply to main and its result | |
onCreate | () => void | New worktree at the end of the list |
open, defaultOpen, onOpenChange | boolean | |
loading, disabled | boolean |
Keyboard
| Key | Action |
|---|---|
| Type | Filter by worktree or branch |
ArrowUp ArrowDown | Move the highlight and the apply preview |
Enter | Switch to the highlighted worktree |
Tab | To Apply to main and New worktree |
Escape | Close |
Accessibility
- The filter is a combobox that drives a listbox with
aria-activedescendant, so focus stays in the field while the highlight moves. - The trigger reads the worktree and branch; uncommitted changes and drift are read as words (2 uncommitted, 4 ahead, 1 behind), never only as dots or color.
- Conflicts are listed by file and say how to resolve them before Apply is enabled.
Motion
The list opens from the trigger in 180 ms. The highlight moves instantly; nothing animates on arrow keys.