Agent skill · Audited from source
Worktree Switching
skill · marcus/sidecarMIT licenceAudited 10 Oct 2026 · source a69114b893d1
Is it safe? Yes — SAFE, grade B (89/100). We read this skill's source at commit a69114b893d1 and found no filesystem, network or shell access and no hard-coded secrets. What it does: 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…
Cite
Cite this page
ModelsAtlas. “Worktree Switching (marcus/sidecar)”. Retrieved 10 Oct 2026. https://modelsatlas.com/skills/marcus/worktree-switching
Trust audit
Audit 0.4.1 · source read 10 Oct 2026
SAFE means nothing in the source contradicts what the skill says it does. Grade B is shared by 17,406 of 18,389 audited skills.
What the source does
- FilesystemNone observedNo reads or writes in the source
- NetworkNone observedNo outbound calls in the source
- ShellNone observedNo commands run in the source
- DependenciesPinnedNothing floats
- SecretsNone foundNo keys in source
Five audit layers
| Layer | What we check | Result | Findings |
|---|---|---|---|
L0 Provenance | Repo owner, licence, archive status, activity | WARN | 2 |
L1 Static source | Secrets, path traversal, supply chain, hidden code | NA | 0 |
L2 Instructions | Prompt injection, authority framing, hidden directives | PASS | 0 |
L3 Inventory | The files and declarations match the source | PASS | 0 |
L4 Sandbox | Run in isolation and watch behaviour | SKIPPED why | 0 |
Gates applied: no behavioural pass.
Findings (2)
MEDIUMInventory / provenanceinv.symlink · .codex/skills
.codex/skills
- Why
- link not followed
- Fix
- —
LOWInventory / provenanceinv.symlink · GEMINI.md
GEMINI.md
- Why
- link not followed
- Fix
- —
Audit 0.4.1 · source sha a69114b893d1 · 10 Oct 2026Report an issue or request a re-scan
Provenance
Who published it, and what the verdict is pinned to
- Publishermarcus GitHub userOwner of the repository this skill is read from
- Source foldermarcus/sidecar/.claude/skills/worktree-switchingThe exact folder we audited
- LicenceMITAs the repository states it
- Commit pinned for this verdicta69114b893d1A new audit runs when the source changes
- Repository statusNot archivedLast push 2 days ago
- Sandboxed runNot runSkills are read, not executed; layer L4 is skipped
What it tells the agent
Full source on GitHub ↗Its description: 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…
---
name: worktree-switching
description: >
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.
---
# 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 reinitialized on worktree switch. Ensure:
1. **`Stop()`** releases all resources (watchers, goroutines, channels)
2. **`Init(ctx)`** resets state and reads from new `ctx.WorkDir`
3. **`Start()`** kicks off fresh async work for the new context
```go
func (p *Plugin) Stop() {
p.stopOnce.Do(func() {
if p.watcher != nil {
p.watcher.Close()
}
close(p.done)
})
}
func (p *Plugin) Init(ctx *plugin.Context) error {
p.ctx = ctx
p.items = nil // Reset state
p.stopOnce = sync.Once{} // Reset stop guard
p.done = make(chan struct{})
return nil
}
```
### Handle WindowSizeMsg After Switch
After reinitialization, the app sends `tea.WindowSizeMsg`. Handle it in `Update`:
```go
case tea.WindowSizeMsg:
p.width = msg.Width
p.height = msg.Height
return p, nil
```
### Persist Per-Worktree State
Use `internal/state` to save/restore preferences keyed by WorkDir:
```go
// Restore state in Init or Start
saved := state.GetMyPluginState(p.ctx.WorkDir)
if saved.Selection != "" {
p.selection = saved.Selection
}
// Save state on user action
state.SetMyPluginState(p.ctx.WorkDir, MyPluginState{
Selection: p.selection,
})
```
Add state struct and accessors following `internal/state/state.go`:
```go
type MyPluginState struct {
Selection string `json:"selection,omitempty"`
}
func GetMyPluginState(workdir string) MyPluginState {
mu.RLock()
defer mu.RUnlock()
if current == nil || current.MyPlugin == nil {
return MyPluginState{}
}
return current.MyPlugin[workdir]
}
```
State is saved to `~/.config/sidecar/state.json` keyed by absolute WorkDir path. State is automatically per-worktree when you pass `p.ctx.WorkDir`.
## Deleted Worktree Detection
When a worktree is deleted externally, plugins should detect this and request fallback to main.
### App-Level Commands
Defined in `internal/app/commands.go`:
- `SwitchWorktreeMsg{WorktreePath}` -- requests switching to a specific worktree
- `SwitchWorktree(path) tea.Cmd` -- helper to create the above
- `SwitchToMainWorktreeMsg{MainWorktreePath}` -- requests fallback to main worktree
- `SwitchToMainWorktree(mainPath) tea.Cmd` -- helper to create the above
### Detection Pattern (from workspace plugin)
**1. Define plugin-local message** (`internal/plugins/workspace/worktree.go`):
```go
type WorkDirDeletedMsg struct {
MainWorktreePath string
}
```
**2. Detect deletion in refresh command:**
```go
func (p *Plugin) refreshWorktrees() tea.Cmd {
workDir := p.ctx.WorkDir
return func() tea.Msg {
if _, err := os.Stat(workDir); os.IsNotExist(err) {
mainPath := findMainWorktreeFromDeleted(workDir)
if mainPath != "" {
return WorkDirDeletedMsg{MainWorktreePath: mainPath}
}
}
return RefreshDoneMsg{Worktrees: worktrees, Err: err}
}
}
```
**3. Handle message, return app command:**
```go
case WorkDirDeletedMsg:
p.refreshing = false
if msg.MainWorktreePath != "" {
return p, app.SwitchToMainWorktree(msg.MainWorktreePath)
}
return p, nil
```
## Git Helpers
`internal/app/git.go` provides:
| Function | Purpose |
|----------|---------|
| `GetWorktrees(workDir)` | List all worktrees for the repo |
| `GetMainWorktreePath(workDir)` | Get path to main worktree |
| `WorktreeNameForPath(workDir, path)` | Derive display name for a worktree |
| `GetAllRelatedPaths(workDir)` | Get all paths sharing the same repo |
## Per-WorkDir State Keys
| Key | Purpose |
|-----|---------|
| `ActivePlugin` | Which plugin tab was focused |
| `FileBrowser` | File browser selections and view state |
| `Workspace` | Workspace/shell selections |
## Best Practices
1. **Reset all state in `Init()`** -- do not carry over stale data from previous worktree
2. **Use `sync.Once` for `Stop()`** -- prevents double-close panics during rapid switching
3. **Validate WorkDir exists** before expensive operations
4. **Store WorkDir at command creation time** -- closures may execute after switch
5. **KeExcerpt, first 6,000 characters of SKILL.md, verbatim from the audited commit. It is text from someone else’s repository, quoted so you can judge it before your agent reads it.
Install
Pinned to the audited commit a69114b
git clone https://github.com/marcus/sidecar git -C sidecar checkout a69114b893d1
The author documents no install command, so this uses the repository directly. Our verdict covers commit a69114b893d1 only.
Works in
The author has not said which agents this skill supports, and we have not tested it in any.
Audit history
Every audit, every source change
- ✓SAFE B 89 / 100
first audit · source
a69114b893d1
README badge
For maintainers · shows the latest audit
[](https://modelsatlas.com/skills/marcus/worktree-switching/)
The badge shows our verdict and grade for this skill, and links back to this page. It changes when the audit does.
Similar skills
All automation skills →marcus/sidecar
Create conversation adapters for importing AI chat history from different tools (Claude Code, Cursor, Warp, Codex, etc.). Covers the adapter.Adapter interface, caching strategies, incremental parsing, watch/FD…
marcus/sidecar
Create declarative modals using the modal library API. Covers modal types (confirm, input, select, form), sections (Text, Buttons, Input, Textarea, Checkbox, Select, List, Combo, When, Custom), rendering with…
marcus/sidecar
Create new sidecar plugins implementing the plugin.Plugin interface, rendering views with Bubble Tea, handling keyboard input via keymap contexts, and integrating with the app shell (footer hints, event bus, adapters).…
marcus/sidecar
Create prompts for sidecar workspaces. Covers prompt structure (name, ticketMode, body), template variables (ticket with fallbacks), config file locations (global vs project), and scope overrides. Use when creating or…
marcus/sidecar
Create custom color themes for Sidecar, including base theme selection, color overrides, gradient borders, tab styles, per-project themes, community themes, and programmatic theme registration. Use when creating or…
marcus/sidecar
Drag-and-drop pane resizing implementation for two-pane plugin layouts. Covers mouse event handling via the internal/mouse package, hit region registration, drag delta calculation, width clamping, state persistence, and…
Add this badge to your README
[](https://modelsatlas.com/skills/marcus/worktree-switching/)
<a href="https://modelsatlas.com/skills/marcus/worktree-switching/"><img src="https://modelsatlas.com/skills/marcus/worktree-switching/badge.svg" alt="ModelsAtlas: SAFE B"></a>
Questions about Worktree Switching
What does the Worktree Switching skill do?
Is Worktree Switching safe to install?
What can Worktree Switching access on my machine?
How current is this page?
Sources
- github.com/marcus/sidecar/tree/main/.claude/skills/worktree-swit — the audited source at commit a69114b893d1 and every finding aboveObserved · 10 Oct 2026
Spotted something wrong? Report a correction · Methodology
Keep going in your AI
Opens with this page as the source. We add nothing else to the prompt.
- What does the Worktree Switching skill do?
- Is Worktree Switching safe to install?
- What can Worktree Switching access on my machine?