worktree-lifecycle
БесплатноБез исполняемых скриптовНе проверенUse when starting isolated feature work or before executing implementation plans. Manages full worktree lifecycle from creation through cleanup with safety…
от MadAppGang★ 290 звёзд на GitHubОб этом скилле
Worktree Lifecycle
Purpose: Manage git worktrees for isolated feature work with safety checks, multi-stack setup, and clean lifecycle management.
When to Use
This skill applies whenever you:
- Start a new feature that requires isolated workspace
- Execute risky or experimental changes
- Need to keep current work untouched while testing alternatives
- Coordinate parallel agent work (each agent in separate worktree)
- Follow an implementation plan requiring clean environment
- Preserve long-running feature work across sessions
Trigger keywords: experiment, prototype, risky, breaking, parallel, isolate, worktree, workspace
Red Flags (Anti-Patterns)
- Creating worktree without checking if branch already exists
- Creating worktree without checking if directory path is available
- Forgetting to add worktree directory to .gitignore
- Manually deleting worktree with
rm -rf(usegit worktree remove) - Removing worktree with uncommitted changes without user confirmation
- Using same branch in multiple worktrees simultaneously
- Working in worktree after returning to main directory (stale CWD)
- Not storing original CWD before entering worktree
- Skipping dependency installation in new worktree
- Not running baseline tests before starting work
6-Phase Lifecycle
Phase 1: Pre-flight Checks
Purpose: Verify all prerequisites before creating anything.
Required checks (all must pass):
# 1. Verify git repository
git rev-parse --git-dir &>/dev/null
if [ $? -ne 0 ]; then
ERROR: "Not a git repository"
RECOVERY: Abort with clear error message
fi
# 2. Detect detached HEAD state
if ! git symbolic-ref HEAD &>/dev/null; then
WARNING: "Currently in detached HEAD state"
RECOVERY: Ask user if they want to create branch from current commit
fi
# 3. Check if branch already in a worktree
if git worktree list | grep -q "$BRANCH"; then
ERROR: "Branch $BRANCH already checked out in a worktree"
RECOVERY: Ask user - reuse existing, rename branch, or cancel
fi
# 4. Check if branch exists (but not in worktree)
if git branch --list "$BRANCH" | grep -q .; then
WARNING: "Branch $BRANCH already exists"
RECOVERY: Ask user - use existing branch or create new with different name
fi
# 5. Check if target path is available
# IMPORTANT: Create directory first before checking (git check-ignore needs path to exist)
mkdir -p "$WORKTREE_DIR"
if [ -d "$WORKTREE_PATH" ]; then
ERROR: "Directory $WORKTREE_PATH already exists"
RECOVERY: Ask user - choose different path or remove existing
fi
Error Recovery Table:
| Error | Detection | Recovery |
|---|---|---|
| Not a git repo | git rev-parse --git-dir fails |
Abort with clear error |
| Detached HEAD | git symbolic-ref HEAD fails |
Ask: create branch from commit? |
| Branch in worktree | git worktree list | grep $BRANCH succeeds |
Ask: reuse, rename, or cancel |
| Branch exists | git branch --list $BRANCH returns result |
Ask: use existing or rename |
| Path exists | Directory already present | Ask: choose different path or remove |
| Parent not writable | Cannot create parent directory | Abort with permission error |
Phase 2: Directory Selection
Priority order (cascading, first match wins):
- Check for existing
.worktrees/directory → use it (no prompt) - Check for existing
worktrees/directory → use it (no prompt) - Check CLAUDE.md for worktree preference → follow it (no prompt)
- Ask user (only if no default found)
For orchestrator integration: Pass WORKTREE_DIR=".worktrees" to skip this phase entirely.
Example detection:
if [ -d ".worktrees" ]; then
WORKTREE_DIR=".worktrees"
elif [ -d "worktrees" ]; then
WORKTREE_DIR="worktrees"
elif grep -q "worktree.*directory" CLAUDE.md 2>/dev/null; then
WORKTREE_DIR=$(grep "worktree.*directory" CLAUDE.md | extract_path)
else
# Ask user via AskUserQuestion
# Options: .worktrees/, worktrees/, custom
fi
Phase 3: Creation
Steps (must be executed in order):
# 1. Verify .gitignore safety
# IMPORTANT: Directory must exist before git check-ignore
mkdir -p "$WORKTREE_DIR"
if ! git check-ignore -q "$WORKTREE_DIR" 2>/dev/null; then
echo "$WORKTREE_DIR/" >> .gitignore
git add .gitignore
git commit -m "chore: add $WORKTREE_DIR to .gitignore"
fi
# 2. Store original CWD (critical for Phase 6 cleanup)
ORIGINAL_CWD=$(pwd)
# 3. Create worktree
git worktree add "$WORKTREE_PATH" -b "$BRANCH"
# 4. Verify creation succeeded
if [ ! -d "$WORKTREE_PATH" ]; then
ERROR: "Worktree creation failed"
RECOVERY: Clean up any partial state, report error
exit 1
fi
# 5. Change to worktree directory
cd "$WORKTREE_PATH"
# 6. Initialize submodules (if any)
if [ -f .gitmodules ]; then
git submodule update --init --recursive
fi
# 7. Write statusline worktree marker (persists across compaction)
if [ -n "$SESSION_ID" ]; then
cat > "$HOME/.claude/.statusline
Установить worktree-lifecycle в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл worktree-lifecycle?
Use when starting isolated feature work or before executing implementation plans. Manages full worktree lifecycle from creation through cleanup with safety checks and error recovery.
Как установить скилл worktree-lifecycle?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл worktree-lifecycle запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic