worktree-switching

Featured

Git worktree support in sidecar: worktree detection, switching between worktrees, worktree state management, and plugin reinitialization. Covers the full lifecycle of worktree context switching including registry reinit, per-worktree state persistence, deleted worktree detection and fallback. Use when working on git worktree features or worktree-related functionality.

AI & Automation 1,041 stars 80 forks Updated today MIT

Install

View on GitHub

Quality Score: 92/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Worktree Switching Sidecar supports seamless switching between git worktrees. When switching: 1. All plugins are stopped, reinitialized with the new WorkDir, and restarted 2. Per-worktree state (active plugin, sidebar selections) is saved/restored 3. Project-specific themes are applied 4. If a worktree is deleted externally, sidecar gracefully falls back to main ## Core Mechanism ### Project Switching Worktree switching uses `Model.switchProject()` in `internal/app/model.go`: ```go m.switchProject(worktreePath) ``` This triggers in order: 1. Save active plugin for old WorkDir 2. Update `m.ui.WorkDir` to new path 3. Apply resolved theme for new path 4. Call `registry.Reinit(newWorkDir)` -- stops all plugins, updates context, reinits all 5. Send `WindowSizeMsg` to all plugins for layout recalculation 6. Restore saved active plugin for new WorkDir 7. Show toast notification ### Registry Reinitialization `Registry.Reinit()` in `internal/plugin/registry.go`: ```go func (r *Registry) Reinit(newWorkDir string) []tea.Cmd { // Stop all plugins (reverse order) for i := len(r.plugins) - 1; i >= 0; i-- { r.safeStop(r.plugins[i]) } // Update context r.ctx.WorkDir = newWorkDir // Reinit all plugins for _, p := range r.plugins { r.safeInit(p) } // Collect and return start commands return startCmds } ``` ## Plugin Responsibilities on Worktree Switch ### Handle Reinitialization Cleanly Your plugin will be stopped and reinit...

Details

Author
marcus
Repository
marcus/sidecar
Created
7 months ago
Last Updated
today
Language
Go
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category