saar120

worktree-manager

Manage git worktrees using the `w` shell function. Use when the user asks to create, switch to, list, remove, or clean up git worktrees, or when starting feature work that needs an isolated workspace. Triggers on keywords like "worktree", "create worktree", "switch worktree", "w <name>", or when needing to work on a branch in isolation. Also use proactively when implementing features that benefit from workspace isolation.

saar120 0 Updated 3mo ago

Resources

1
GitHub

Install

npx skillscat add saar120/dotfiles/worktree-manager

Install via the SkillsCat registry.

SKILL.md

Worktree Manager

Interact with the user's w worktree manager via Bash.

Source: ~/.zsh/worktree-manager/worktree-manager.zsh

Commands

Command Description
w <name> Create (if needed) and cd into worktree for <name> branch
w <name> <cmd> Run <cmd> inside the worktree, then return
w list List worktrees for current repo
w list --all List all worktrees across all repos
w rm <name> Remove a worktree
w rm --force <name> Force-remove a worktree
w clean Remove all worktrees for current repo
w home cd back to the main (non-worktree) repo
w --where Print repo_root, repo_rel, and worktrees_base (3 lines)

--list, --rm, --clean, and --home still work as aliases for list, rm, clean, and home.

Key Behavior

  • Worktrees are created under $W_WORKTREES_DIR/<repo-rel>/<name> (default: ~/projects/worktrees/)
  • Branch name = <W_DEFAULT_BRANCH_PREFIX>/<name> if prefix is set, otherwise just <name>
  • On creation, w automatically:
    • Fetches all remotes
    • Reuses existing local/remote branch or creates a new one from HEAD
    • Symlinks shared dirs (plans, thoughts) from the main repo
    • Adds exclude patterns to .git/info/exclude

Usage from Claude Code

Run commands via the Bash tool. Since each Bash invocation is a fresh shell, cd effects don't persist — use w <name> <cmd> to run commands inside a worktree.

# Create/switch and run a command inside the worktree
w my-feature "go test ./..."

# List existing worktrees
w list

# Check where worktrees live
w --where

To get the worktree path for file operations (Read/Write/Edit):

# Parse the worktrees base from --where output
w --where | tail -1   # prints the worktrees base dir

Configuration

See references/config.md for environment variables and customization.