worktree-switching

Support for switching between Git worktrees, which are separate working folders linked to one repository. It manages each folder's project state while changing between them.

In plain words
What is it for?
Use it when moving between branches or parallel worktree folders, including restoring the selected plugin and handling a worktree that was deleted.
Why use it?
It keeps plugins, themes, selected views, and other project-specific settings aligned with the worktree you are using.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/marcus/sidecar/worktree-switching
Any agent
npx skills add marcus/sidecar --skill worktree-switching
Clone the repo
git clone --depth 1 https://github.com/marcus/sidecar

Made for: Claude Code, Codex.

Per session 74 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,563 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00074 $0.01563
Opus 5 $0.00037 $0.00781
Sonnet 5 $0.00015 $0.00313
Haiku 4.5 $0.00007 $0.00156

Measured 3d ago against content hash b9aba13b8e04, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

worktree-switching scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/worktree-switching/SKILL.md · 217 lines

How it starts

The opening of the file, as written. The whole thing — 217 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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:

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:

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
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
}

Read the full file on GitHub · 217 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 217 lines · 74 tokens per session scan A b9aba13b8e04

Subscribe to this mod's changes

worktree-switching is a skill published in the GitHub repository marcus/sidecar (1,049 stars, last pushed 3d ago), licensed MIT. It adds 74 tokens to every session and 1,563 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

pre-merge

The CI gate. Takes a feature branch from "eng says done" to "PR open against staging with green checks". Runs the project's preflight-resolved pipeline from devkit/policy.json components[]: sync → parallel correctness + security waves → coverage → regression tail → security/migration → PRD-consistency → open PR. Emits…

ndisisnd/msg · 101 tokens

intake

The planning front-door. Captures feature ideas and bugs as graded rows in the root INTAKE.md ledger. Use it when the user says "log an idea", "capture a bug", "add to the backlog", "note this down", "track this feature", or invokes /intake. Owns the requirements interview — fleshes out thin ideas, proactively…

ndisisnd/msg · 239 tokens

merge

The ship gate — the only skill that merges. --staging merges the feature→staging PR on green CI, deploys, verifies, emits a human test script and stamps the staging sign-off on approval. --production ships the double-confirmed release to main and deploys production. Never self-certifies staging; nothing reaches main…

ndisisnd/msg · 94 tokens

msg

Root menu for msg skills, plus harness modes. --init is the one-time project bootstrap — use it when the user says "initialise project", "bootstrap repo", "set up the framework", "start a new project", or asks to set up project structure in an empty repo. Other modes: --init-staging (add a staging branch), --update…

ndisisnd/msg · 162 tokens

lorekeeper-reconcile

Reconcile and fact-check Lorekeeper memories against source materials, existing documentation, and internal consistency. Use when (1) the user provides reference materials to verify against, (2) the user requests a general knowledge audit, or (3) the user wants to verify specific topics. Updates memory scores and…

Jessinra/Lorekeeper · 72 tokens

lorekeeper-search

Search the Lorekeeper knowledge base and provide relevance feedback with confidence ratings. Use when the agent needs to recall domain knowledge, look up facts, or query the memory store. Ensures every search ends with a loreupdate feedback call (including confidence) to improve knowledge quality over time.

Jessinra/Lorekeeper · 61 tokens