Create and manage Git worktrees for parallel development workflows
Creates and manages Git worktrees for parallel development, triggered by repo-manager, branch-manager, or `/repo:worktree-*` commands. Handles safe creation, listing, removal, and cleanup of worktrees with metadata tracking.
/plugin marketplace add fractary/claude-plugins/plugin install fractary-repo@fractaryThis skill inherits all available tools. When active, it can use any tool Claude has access to.
scripts/cleanup.shscripts/create.shscripts/list.shscripts/metadata.shscripts/remove.shYour responsibility is to create, list, remove, and manage Git worktrees safely. You enable users to work on multiple branches simultaneously in parallel Claude Code instances by managing worktree directories and their metadata.
You are invoked by:
You execute deterministic Git worktree operations via shell scripts. </CONTEXT>
<CRITICAL_RULES> NEVER VIOLATE THESE RULES:
Worktree Path Safety
Data Safety
Metadata Tracking
Branch Relationship
Cleanup Safety
Create Worktree Request:
{
"operation": "create-worktree",
"parameters": {
"branch_name": "feat/92-add-git-worktree-support",
"base_branch": "main",
"work_id": "92"
}
}
List Worktrees Request:
{
"operation": "list-worktrees",
"parameters": {
"filter": "active"
}
}
Remove Worktree Request:
{
"operation": "remove-worktree",
"parameters": {
"branch_name": "feat/92-add-git-worktree-support",
"force": false
}
}
Cleanup Worktrees Request:
{
"operation": "cleanup-worktrees",
"parameters": {
"remove_merged": true,
"remove_stale": true,
"dry_run": false
}
}
</INPUTS>
<WORKFLOW>
1. OUTPUT START MESSAGE:
π― STARTING: Worktree Manager
Operation: create-worktree
Branch: {branch_name}
Base Branch: {base_branch}
βββββββββββββββββββββββββββββββββββββββ
2. VALIDATE INPUTS:
3. GENERATE WORKTREE PATH:
REPO_NAME=$(basename $(git rev-parse --show-toplevel))
BRANCH_SLUG=$(echo "{branch_name}" | sed 's|/|-|g')
WORKTREE_PATH="../${REPO_NAME}-wt-${BRANCH_SLUG}"
Example: ../claude-plugins-wt-feat-92-add-git-worktree-support
4. CHECK FOR EXISTING WORKTREE:
if [ -d "$WORKTREE_PATH" ]; then
ERROR: "Worktree already exists at $WORKTREE_PATH"
EXIT CODE 10
fi
# Also check git worktree list
if git worktree list | grep -q "$BRANCH_NAME"; then
ERROR: "Worktree already exists for branch $BRANCH_NAME"
EXIT CODE 10
fi
5. CREATE WORKTREE:
Execute the create-worktree script:
bash plugins/repo/skills/worktree-manager/scripts/create.sh \
"$BRANCH_NAME" \
"$WORKTREE_PATH" \
"$BASE_BRANCH"
The script will:
6. UPDATE METADATA:
Update .fractary/plugins/repo/worktrees.json:
{
"worktrees": [
{
"path": "$WORKTREE_PATH",
"branch": "$BRANCH_NAME",
"work_id": "$WORK_ID",
"created": "2025-11-12T10:30:00Z",
"status": "active"
}
]
}
7. OUTPUT COMPLETION MESSAGE:
β
COMPLETED: Worktree Manager
Operation: create-worktree
Worktree Created: {worktree_path}
Branch: {branch_name}
Status: Active
βββββββββββββββββββββββββββββββββββββββ
Next: cd {worktree_path} && claude
1. OUTPUT START MESSAGE:
π― STARTING: Worktree Manager
Operation: list-worktrees
βββββββββββββββββββββββββββββββββββββββ
2. GET WORKTREES FROM GIT:
git worktree list --porcelain
3. LOAD METADATA:
Load .fractary/plugins/repo/worktrees.json to enrich worktree information with:
4. FORMAT OUTPUT:
Active Worktrees:
1. feat/92-add-git-worktree-support
Path: ../claude-plugins-wt-feat-92-add-git-worktree-support
Work Item: #92
Created: 2025-11-12
Status: Active
2. fix/91-authentication-bug
Path: ../claude-plugins-wt-fix-91-authentication-bug
Work Item: #91
Created: 2025-11-11
Status: Active
5. OUTPUT COMPLETION MESSAGE:
β
COMPLETED: Worktree Manager
Operation: list-worktrees
Found: {count} worktrees
βββββββββββββββββββββββββββββββββββββββ
1. OUTPUT START MESSAGE:
π― STARTING: Worktree Manager
Operation: remove-worktree
Branch: {branch_name}
βββββββββββββββββββββββββββββββββββββββ
2. FIND WORKTREE:
Locate worktree for the specified branch:
git worktree list | grep "$BRANCH_NAME"
3. SAFETY CHECKS:
Check for uncommitted changes:
cd "$WORKTREE_PATH"
if [ -n "$(git status --porcelain)" ]; then
if [ "$FORCE" != "true" ]; then
ERROR: "Worktree has uncommitted changes. Use --force to remove anyway."
EXIT CODE 20
fi
WARNING: "Removing worktree with uncommitted changes (--force specified)"
fi
Check not in current directory:
CURRENT_DIR=$(pwd)
if [[ "$CURRENT_DIR" == "$WORKTREE_PATH"* ]]; then
ERROR: "Cannot remove worktree from within it. Change directory first."
EXIT CODE 21
fi
4. REMOVE WORKTREE:
Execute the remove-worktree script:
bash plugins/repo/skills/worktree-manager/scripts/remove.sh \
"$BRANCH_NAME" \
"$FORCE"
The script will:
5. UPDATE METADATA:
Remove entry from .fractary/plugins/repo/worktrees.json
6. OUTPUT COMPLETION MESSAGE:
β
COMPLETED: Worktree Manager
Operation: remove-worktree
Worktree Removed: {worktree_path}
Branch: {branch_name}
βββββββββββββββββββββββββββββββββββββββ
1. OUTPUT START MESSAGE:
π― STARTING: Worktree Manager
Operation: cleanup-worktrees
βββββββββββββββββββββββββββββββββββββββ
2. IDENTIFY CLEANUP CANDIDATES:
Merged branches:
# Find branches that have been merged to main
git branch --merged main | grep -v main
Stale worktrees:
# Find worktrees older than 30 days with no recent activity
# Check metadata created timestamp
3. CHECK SAFETY:
For each candidate:
4. EXECUTE CLEANUP:
bash plugins/repo/skills/worktree-manager/scripts/cleanup.sh \
"$REMOVE_MERGED" \
"$REMOVE_STALE" \
"$DRY_RUN"
5. OUTPUT RESULTS:
Cleanup Summary:
- Merged branches removed: 3
- feat/85-add-feature
- fix/86-bug-fix
- chore/87-update-deps
- Stale worktrees removed: 1
- feat/80-old-experiment
- Skipped (uncommitted changes): 0
6. UPDATE METADATA:
Remove all cleaned up entries from worktrees.json
7. OUTPUT COMPLETION MESSAGE:
β
COMPLETED: Worktree Manager
Operation: cleanup-worktrees
Removed: {count} worktrees
βββββββββββββββββββββββββββββββββββββββ
</WORKFLOW>
<COMPLETION_CRITERIA> β All inputs validated β Worktree path calculated correctly β Safety checks passed β Git worktree operation succeeded β Metadata updated (worktrees.json) β User notified of next steps </COMPLETION_CRITERIA>
<OUTPUTS> Return structured JSON response:Create Success:
{
"status": "success",
"operation": "create-worktree",
"worktree_path": "../claude-plugins-wt-feat-92",
"branch_name": "feat/92-add-git-worktree-support",
"commit_sha": "cd4e945...",
"work_id": "92"
}
List Success:
{
"status": "success",
"operation": "list-worktrees",
"worktrees": [
{
"path": "../claude-plugins-wt-feat-92",
"branch": "feat/92-add-git-worktree-support",
"work_id": "92",
"status": "active"
}
],
"count": 1
}
Remove Success:
{
"status": "success",
"operation": "remove-worktree",
"worktree_path": "../claude-plugins-wt-feat-92",
"branch_name": "feat/92-add-git-worktree-support"
}
Error Response:
{
"status": "failure",
"operation": "create-worktree",
"error": "Worktree already exists at ../claude-plugins-wt-feat-92",
"error_code": 10
}
</OUTPUTS>
<ERROR_HANDLING>
Invalid Inputs (Exit Code 2):
Worktree Already Exists (Exit Code 10):
Uncommitted Changes (Exit Code 20):
In Use (Exit Code 21):
Metadata Error (Exit Code 3):
Git Error (Exit Code 1):
</ERROR_HANDLING>
<DOCUMENTATION> After completing ANY operation, provide clear documentation of:Example completion message:
β
Worktree created successfully!
Branch: feat/92-add-git-worktree-support
Worktree: ../claude-plugins-wt-feat-92-add-git-worktree-support
Work Item: #92
To start working in this worktree:
1. cd ../claude-plugins-wt-feat-92-add-git-worktree-support
2. claude
To list all worktrees:
/repo:worktree-list
To clean up when done:
/repo:worktree-remove feat/92-add-git-worktree-support
</DOCUMENTATION>
This skill is focused and efficient:
By delegating deterministic operations to scripts: