worktree

Guides git worktree creation, session re-rooting, and recovery from failed provisioning hooks.

Updated May 9, 2020
One-click install
npx skills add https://github.com/avdi/purse --skill worktree-avdi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: worktree
Source: https://github.com/avdi/purse/tree/main/home/dot_agents/skills/worktree
Command: npx skills add https://github.com/avdi/purse --skill worktree-avdi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Working with git worktrees in Claude Code sessions is error-prone: shell commands like wt switch change the cwd without re-rooting the session, and failed pre-start hooks leave half-provisioned worktrees that silently share the primary checkout's databases and ports. This Skill defines the correct commands and recovery procedure so worktree operations stay safe. ## Core Features & Use Cases - Correct session navigation: Mandates the EnterWorktree tool for entering or re-rooting sessions instead of wt switch or raw git worktree commands. - Safe shell operations: Lists which wt commands are appropriate for non-navigation tasks such as creating, listing, removing, and merging worktrees. - Hook failure recovery: Diagnoses the misleading "hook succeeded but returned no worktree path" error and recovers by re-running wt hook pre-start directly. - Use Case: You create a worktree and EnterWorktree fails with a swallowed error. Instead of retrying wt switch (which silently short-circuits), you run wt hook pre-start, fix the reported failure, and then enter the fully provisioned worktree. ## Quick Start Load the worktree skill before creating, entering, resuming, listing, removing, or troubleshooting any git worktree in this session.

Frequently Asked Questions about worktree

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I switch into a git worktree in Claude Code?

Always use the EnterWorktree tool to switch into or re-root a session inside a worktree. Shell commands like wt switch or git worktree only change the cwd and do not re-root the Claude Code session.

Which wt commands are safe to run from the shell?

Non-navigation commands are safe: wt switch --create <branch> --no-cd --format=json to create, wt list to list, and wt remove or wt merge to clean up. Never use wt switch to navigate between worktrees.

Why does EnterWorktree fail with "hook succeeded but returned no worktree path"?

The plugin's WorktreeCreate hook pipes wt switch --create --format=json into jq without pipefail, so wt's real exit code and stderr are swallowed. The underlying cause is a failed pre-start hook that left the worktree half-provisioned.

How do I recover a worktree whose pre-start hooks failed?

Run wt hook pre-start directly from inside the worktree; it re-runs the provisioning pipeline against this worktree's branch and cwd and shows the real error. Fix what it reports, re-run until it succeeds, then call EnterWorktree with the path.

Why doesn't retrying wt switch fix a failed worktree setup?

From inside the worktree it names, wt switch short-circuits to "Already on worktree for <branch>" and skips the pre-start pipeline entirely. It exits 0, so nothing gets provisioned and the failure stays silent.