Skip to content
Sign in
CodeWorktree switcherMenu

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.

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

$ pnpm dlx shadcn@latest add @chatcn-pro/worktree-switcher

Usage

tsx
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

PropTypeNotes
worktreesWorktree[]name, branch, path, isMain, dirty, ahead, behind, stats, conflicts, agent
value, defaultValue, onValueChangestringCurrent worktree
baseBranchstringDefault main
onApply, applying, applied, applyErrorApply to main and its result
onCreate() => voidNew worktree at the end of the list
open, defaultOpen, onOpenChangeboolean
loading, disabledboolean

Keyboard

KeyAction
TypeFilter by worktree or branch
ArrowUp ArrowDownMove the highlight and the apply preview
EnterSwitch to the highlighted worktree
TabTo Apply to main and New worktree
EscapeClose

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.