Manage git worktrees for AI agent workflows. Use when creating, listing, removing, or pruning worktrees, especially for ticket-based development where the agent needs to create isolated working directories for feature branches. Supports creating worktrees in .worktrees/ subdirectory, automatic branch creation from base branch (main), and cleanup of stale worktrees.
From generalnpx claudepluginhub bobmaertz/prompt-library --plugin generalThis skill uses the workspace's default tool permissions.
scripts/create_worktree.pyscripts/list_worktrees.pyscripts/prune_worktrees.pyscripts/remove_worktree.pyEnables AI agents to execute x402 payments with per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents pay for APIs, services, or other agents.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Manage git worktrees for AI agent workflows where Claude creates isolated working directories for tickets, features, or bug fixes.
This skill provides scripts to:
.worktrees/ with branches from a base branchWorktrees are organized in a project-based subdirectory pattern:
my-project/
├── .git/
├── src/
├── .worktrees/
│ ├── feature-add-auth/ # Created for feature/add-auth
│ ├── feature-fix-bug-123/ # Created for feature/fix-bug-123
│ └── hotfix-security/ # Created for hotfix/security
└── ...
Branch names are sanitized for directory names (e.g., feature/add-auth → feature-add-auth).
All scripts are in the scripts/ directory and should be run with Python 3.
Create a new worktree with a branch from a base branch.
Usage:
python3 scripts/create_worktree.py <branch-name> [base-branch] [repo-path]
Parameters:
branch-name (required): Name of the branch (e.g., feature/add-auth)base-branch (optional): Base branch to branch from (default: main)repo-path (optional): Path to repository (default: current directory)Behavior:
.worktrees/ directory if it doesn't exist/ with -)Examples:
# Create worktree for feature/add-auth from main
python3 scripts/create_worktree.py feature/add-auth
# Create worktree from develop branch
python3 scripts/create_worktree.py feature/new-ui develop
# Create worktree in specific repo
python3 scripts/create_worktree.py feature/fix-bug main /path/to/repo
Output:
List all worktrees with their current status.
Usage:
python3 scripts/list_worktrees.py [--json] [repo-path]
Parameters:
--json (optional): Output as JSON instead of formatted textrepo-path (optional): Path to repository (default: current directory)Output includes:
Examples:
# List worktrees in current repo
python3 scripts/list_worktrees.py
# List worktrees as JSON
python3 scripts/list_worktrees.py --json
# List worktrees in specific repo
python3 scripts/list_worktrees.py /path/to/repo
Remove a specific worktree by path or branch name.
Usage:
python3 scripts/remove_worktree.py <path-or-branch> [--force] [--delete-branch] [repo-path]
Parameters:
path-or-branch (required): Worktree path or branch name--force or -f (optional): Force removal even with uncommitted changes--delete-branch or -d (optional): Also delete the associated branchrepo-path (optional): Path to repository (default: current directory)Safety features:
--force)Examples:
# Remove by branch name
python3 scripts/remove_worktree.py feature/add-auth
# Remove by path
python3 scripts/remove_worktree.py /path/to/repo/.worktrees/feature-add-auth
# Force remove with uncommitted changes
python3 scripts/remove_worktree.py feature/old-feature --force
# Remove worktree and delete branch
python3 scripts/remove_worktree.py feature/completed --delete-branch
# Combine flags
python3 scripts/remove_worktree.py feature/abandoned --force --delete-branch
Prune stale worktrees (where directory no longer exists).
Usage:
python3 scripts/prune_worktrees.py [--dry-run] [repo-path]
Parameters:
--dry-run or -n (optional): Show what would be pruned without making changesrepo-path (optional): Path to repository (default: current directory)Behavior:
Examples:
# Preview stale worktrees
python3 scripts/prune_worktrees.py --dry-run
# Prune stale worktrees
python3 scripts/prune_worktrees.py
# Prune in specific repo
python3 scripts/prune_worktrees.py /path/to/repo
Create a worktree when:
Remove a worktree when:
Run prune regularly to:
# 1. Start work on ticket
worktree_path = create_worktree("feature/ticket-123")
# 2. Do work in worktree
os.chdir(worktree_path)
# ... make changes, commit, etc.
# 3. Clean up when done
remove_worktree("feature/ticket-123", delete_branch=True)
# 4. Periodically prune stale worktrees
prune_worktrees()
All scripts:
Common errors:
# Agent receives ticket: "Add user authentication"
python3 scripts/create_worktree.py feature/add-auth
# Work in the worktree
cd .worktrees/feature-add-auth
# ... implement feature, test, commit ...
# When done
cd ../..
python3 scripts/remove_worktree.py feature/add-auth --delete-branch
# Agent receives bug report: "Fix login crash"
python3 scripts/create_worktree.py feature/fix-login-crash
# Fix the bug
cd .worktrees/feature-fix-login-crash
# ... fix bug, test, commit ...
# Create PR, then cleanup
cd ../..
python3 scripts/remove_worktree.py feature/fix-login-crash
# Keep branch for PR, so don't use --delete-branch
# List current worktrees to see what's in progress
python3 scripts/list_worktrees.py
# Switch between tickets by changing directory
cd .worktrees/feature-ticket-123
# ... work on ticket 123 ...
cd ../feature-ticket-456
# ... work on ticket 456 ...
# Clean up completed tickets
cd ../..
python3 scripts/remove_worktree.py feature/ticket-123 --delete-branch