Use when user wants to create new autonomy branch with dedicated worktree for parallel agent workflows
Creates a new autonomy branch with a dedicated worktree for parallel agent workflows. Use when user runs `/fork-worktree` to run multiple agents simultaneously on different branches with isolated working directories.
/plugin marketplace add tilmon-engineering/claude-skills/plugin install autonomy@tilmon-eng-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Create new autonomy branch with dedicated worktree for running parallel Claude agents on different branches simultaneously. All worktrees created at repository root level (.worktrees/autonomy/), regardless of where command is invoked.
Core principle: Worktrees represent branches, not iterations. Multiple iterations happen within same worktree. Worktrees enable parallel exploration with isolated working directories.
Use this skill when:
/fork-worktree commandDO NOT use for:
| Step | Action | Tool |
|---|---|---|
| 1. Parse arguments | Extract iteration (optional) and strategy-name | Manual |
| 2. Detect repository root | Find git root from anywhere (main repo or worktree) | Bash |
| 3. Validate | Check strategy-name, branch, and worktree path availability | Bash |
| 4. Resolve fork point | Find iteration tag or use HEAD | Bash |
| 5. Create worktree | Create branch + worktree at root level | Bash |
| 6. Report success | Confirm creation with navigation instructions | Direct output |
Extract arguments from command args:
Format: [iteration] <strategy-name>
Parse:
If args contains only one word:
iteration = None
strategy_name = args
Else if args contains two words:
iteration = first word
strategy_name = second word
Else:
Error: "Invalid arguments. Usage: /fork-worktree [iteration] <strategy-name>"
Validate strategy-name:
Normalize strategy-name:
# Convert to lowercase, replace invalid chars with hyphens
strategy_name=$(echo "$strategy_name" | tr '[:upper:]' '[:lower:]' | tr -cs '[:alnum:]-' '-' | sed 's/^-*//; s/-*$//')
Find the git repository root, regardless of whether we're in main repo or inside a worktree:
# Get common git directory (works from anywhere, including worktrees)
git_common_dir=$(git rev-parse --git-common-dir)
# Repository root is parent of .git directory
# For main repo: .git is directory -> parent is repo root
# For worktree: .git is file pointing to .git/worktrees/X -> common-dir points back to main .git
if [ -d "$git_common_dir" ]; then
repo_root=$(cd "$git_common_dir/.." && pwd)
else
echo "Error: Unable to determine repository root"
exit 1
fi
Why this matters:
.worktrees/autonomy/ relative to repo root.worktrees/autonomy/experiment-a/.worktrees/...)Check that we can create the new branch and worktree:
Check branch doesn't exist:
if git branch -a | grep -q "autonomy/$strategy_name\$"; then
echo "Error: Branch 'autonomy/$strategy_name' already exists."
echo ""
echo "To work on existing branch:"
echo " git checkout autonomy/$strategy_name"
echo ""
echo "To create worktree for existing branch:"
echo " cd $repo_root"
echo " git worktree add .worktrees/autonomy/$strategy_name autonomy/$strategy_name"
echo ""
echo "Available autonomy branches:"
git branch -a | grep autonomy/
exit 1
fi
Check worktree path doesn't exist:
worktree_path="$repo_root/.worktrees/autonomy/$strategy_name"
if [ -e "$worktree_path" ]; then
echo "Error: Worktree directory already exists: $worktree_path"
echo ""
echo "Remove it first:"
echo " /remove-worktree $strategy_name"
echo "Or:"
echo " git worktree remove .worktrees/autonomy/$strategy_name"
exit 1
fi
Create parent directory if needed:
mkdir -p "$repo_root/.worktrees/autonomy"
Determine what commit to fork from (same logic as forking-iteration):
If iteration specified:
# Search for iteration tag in current branch history
matching_tags=$(git tag --merged HEAD | grep "iteration-$(printf '%04d' $iteration)\$")
tag_count=$(echo "$matching_tags" | grep -c '^' || echo "0")
if [ "$tag_count" -eq 0 ]; then
echo "Error: Iteration $iteration not found in current branch history."
echo ""
echo "Most recent iterations in current branch:"
git tag --merged HEAD | grep 'iteration-' | tail -5
exit 1
elif [ "$tag_count" -eq 1 ]; then
fork_point="$matching_tags"
fork_description="iteration $iteration (tag: $matching_tags)"
else
# Multiple matches (shouldn't happen with branch-namespaced tags)
echo "Multiple iteration tags found for iteration $iteration:"
echo "$matching_tags"
echo ""
echo "Please specify which tag to fork from."
exit 1
fi
If iteration NOT specified:
# Fork from current HEAD
fork_point=$(git rev-parse HEAD)
fork_description="current commit ($(git rev-parse --short HEAD))"
Validate fork point exists:
if ! git rev-parse "$fork_point" >/dev/null 2>&1; then
echo "Error: Fork point '$fork_point' not found in git history."
exit 1
fi
Create the branch and worktree in a single git command:
# Navigate to repository root (important for relative path resolution)
cd "$repo_root"
# Create branch + worktree together
# -b creates new branch
# path is relative to repo root: .worktrees/autonomy/<strategy-name>
# fork_point is where to create the branch from
git worktree add -b "autonomy/$strategy_name" \
".worktrees/autonomy/$strategy_name" \
"$fork_point"
# Verify worktree created successfully
if [ ! -d "$worktree_path" ]; then
echo "Error: Failed to create worktree at $worktree_path"
exit 1
fi
# Verify branch exists
if ! git branch -a | grep -q "autonomy/$strategy_name\$"; then
echo "Error: Failed to create branch 'autonomy/$strategy_name'"
exit 1
fi
What this does:
autonomy/<strategy-name> at fork point.worktrees/autonomy/<strategy-name>/Announce successful worktree creation with navigation instructions:
✓ Worktree created successfully
Branch: autonomy/<strategy-name>
Worktree: .worktrees/autonomy/<strategy-name>/
Forked from: [fork_description]
Next steps:
1. Navigate to worktree:
cd .worktrees/autonomy/<strategy-name>
2. Start iteration:
/start-iteration
The worktree is an isolated working directory where you can work on this branch independently of other branches.
Calculate relative path for convenience:
# If we're already in a worktree, provide sibling navigation
current_dir=$(pwd)
if [[ "$current_dir" == *"/.worktrees/autonomy/"* ]]; then
# In a worktree, provide relative navigation to sibling
echo "From your current location:"
echo " cd ../$strategy_name"
fi
Works from anywhere:
All worktrees created at same level:
repo-root/
├── .git/
├── .worktrees/
│ └── autonomy/
│ ├── experiment-a/ # Created from main repo
│ ├── experiment-b/ # Created from experiment-a worktree
│ └── experiment-c/ # Created from experiment-b worktree
Branch persists after worktree removal:
/remove-worktree) deletes directoryautonomy/<strategy-name> and all commits persistOne branch per worktree:
Existing workflows unchanged:
/fork-iteration still creates branches without worktreesEach worktree is independent:
Shared git metadata:
.git directory is shared| Mistake | Reality |
|---|---|
| "Create worktree in current directory" | NO. Always create at repo root .worktrees/autonomy/ regardless of where invoked. |
| "I'll use relative path .worktrees/..." | YES, but must cd to repo_root first. Path is relative to repo root. |
| "Branch exists, I'll create worktree for it" | NO. This skill creates NEW branches. Existing branch = error. |
| "I'll also start the iteration" | NO. Worktree creation is separate. User navigates and runs /start-iteration. |
| "I'll checkout the branch in current directory" | NO. Branch checked out in worktree, current directory unchanged. |
| "Nested worktrees are fine" | NO. All worktrees must be at root level .worktrees/autonomy/. |
| "I'll use git rev-parse --show-toplevel" | NO. That gives worktree root, not repo root. Use --git-common-dir. |
Once worktree is created:
.worktrees/autonomy/<strategy-name>/autonomy/<strategy-name> checked out in that directorycd .worktrees/autonomy/<strategy-name>/start-iteration to begin workTypical workflow:
# Terminal 1: First agent
/fork-worktree experiment-a
cd .worktrees/autonomy/experiment-a
/start-iteration
# Agent 1 works here
# Terminal 2: Second agent (can run while agent 1 is working)
/fork-worktree experiment-b
cd .worktrees/autonomy/experiment-b
/start-iteration
# Agent 2 works here independently
# Terminal 3: Analysis (from anywhere)
/list-branches
/compare-branches experiment-a experiment-b
Each agent has: