Create a new git branch and worktree from context. Use when starting work on a task - given an ADO Work Item URI, ADO comment, or free-text description, it auto-selects a branch prefix (feature/bugfix/experiment) based on context, creates a branch like feature/<username>/<slug>, and sets up a worktree at ../<repo>.worktrees/<slug>. Triggers on "create worktree", "new branch for", "start work on", or when a user provides an ADO WI link and wants to begin coding.
Create a new git branch and worktree from context (ADO Work Item, comment, or freetext).
Determine the user's alias for branch naming. Try in order:
git config user.email — extract the part before @, lowercased (e.g., avilevin@microsoft.com → avilevin)$env:USERNAME (Windows) or $env:USER (Unix)userStore as $username for use in branch names below.
Obtain one of:
https://dev.azure.com/<org>/<project>/_workitems/edit/12345678From ADO Work Item URI (if Azure CLI is available):
# Extract WI ID and org from URI
$wiId = "12345678" # parsed from URI
$org = "https://dev.azure.com/<org>" # parsed from URI
# Query ADO for title using az cli
az boards work-item show --id $wiId --org $org --query "fields.\"System.Title\"" -o tsv
If az is not available or the command fails, ask the user for a freetext description instead.
From freetext/comment:
fix-auth-timeoutChoose prefix based on context:
| Context Signal | Prefix |
|----------------|--------|
| ADO WI type = Bug, or words like "fix", "bug", "issue", "broken" | bugfix/<username>/<slug> |
| Words like "experiment", "try", "test", "spike", "poc" | experiment/<username>/<slug> |
| Default (new feature, enhancement, task) | feature/<username>/<slug> |
Present the auto-selected branch and allow user to confirm or provide alternative prefix.
Before creating, ask user which source to use for the branch:
Suggested branch: bugfix/<username>/fix-auth-timeout
Worktree: <repo>.worktrees/fix-auth-timeout
Create branch from:
[1] origin/main (recommended) - ensures branch starts from latest remote
[2] current HEAD
Enter your choice [1]:
Default is origin/main to ensure the branch always starts from the latest remote state.
When the current repository is itself a worktree, create the new worktree as a sibling of the current worktree, not under a new nested .worktrees directory.
Correct:
C:\_SRC\Repo.worktrees\current-task
C:\_SRC\Repo.worktrees\new-task
Incorrect:
C:\_SRC\Repo.worktrees\current-task.worktrees\new-task
Always resolve $worktreeRoot before creating the worktree:
$gitRoot = (git rev-parse --show-toplevel).Replace('/', '\')
$gitRootInfo = Get-Item $gitRoot
# If any ancestor already ends in ".worktrees", use the outermost such ancestor.
# This prevents creating nested worktree roots from inside an existing worktree.
$worktreeRoot = $null
$ancestor = $gitRootInfo
while ($ancestor -ne $null) {
if ($ancestor.Name.EndsWith('.worktrees', [StringComparison]::OrdinalIgnoreCase)) {
$worktreeRoot = $ancestor.FullName
}
$ancestor = $ancestor.Parent
}
if ($worktreeRoot -eq $null) {
$repoName = Split-Path $gitRoot -Leaf
$worktreeRoot = Join-Path (Split-Path $gitRoot -Parent) "$repoName.worktrees"
}
Default behavior (origin/main):
# Resolve git root and non-nested worktree root
$gitRoot = (git rev-parse --show-toplevel).Replace('/', '\')
$gitRootInfo = Get-Item $gitRoot
$worktreeRoot = $null
$ancestor = $gitRootInfo
while ($ancestor -ne $null) {
if ($ancestor.Name.EndsWith('.worktrees', [StringComparison]::OrdinalIgnoreCase)) {
$worktreeRoot = $ancestor.FullName
}
$ancestor = $ancestor.Parent
}
if ($worktreeRoot -eq $null) {
$repoName = Split-Path $gitRoot -Leaf
$worktreeRoot = Join-Path (Split-Path $gitRoot -Parent) "$repoName.worktrees"
}
# Define paths
$branch = "feature/$username/fix-auth-timeout"
$slug = "fix-auth-timeout"
$worktreePath = Join-Path $worktreeRoot $slug
# Create worktree directory if needed
$worktreeParent = Split-Path $worktreePath -Parent
if (!(Test-Path $worktreeParent)) { New-Item -ItemType Directory -Path $worktreeParent -Force }
# Fetch latest from remote to ensure we have latest main
git fetch origin main
# Resolve to a detached commit so the new branch has NO upstream tracking
$startCommit = git rev-parse origin/main
# Create branch from that commit — no implicit remote tracking
git worktree add -b $branch $worktreePath $startCommit
# Verify
git worktree list
Alternative (current HEAD):
If user selects option [2], use git worktree add -b $branch $worktreePath without specifying a source (branches from current HEAD). No remote push — the branch stays local until explicitly pushed.
✅ Created branch: feature/<username>/fix-auth-timeout
✅ Worktree ready at: <repo>.worktrees/fix-auth-timeout
To start working:
cd <repo>.worktrees/fix-auth-timeout
Generate semantic slugs from context:
| Input | Slug |
|-------|------|
| "Fix the authentication timeout bug" | fix-auth-timeout |
| "Add retry logic to API calls" | add-api-retry |
| "Implement caching for user sessions" | user-session-cache |
| ADO WI: "Bug 123: Login fails after 30min" | login-timeout-fix |
Rules:
| Error | Resolution |
|-------|------------|
| Branch already exists | Suggest alternative slug or ask user |
| Worktree path exists | Check if it's the same branch; if not, suggest alternative |
| Computed path contains .worktrees\<slug>.worktrees\ | Stop and recompute $worktreeRoot using the Critical Worktree Location Rule |
| ADO query fails | Fall back to asking user for slug |
| Not in a git repo | Error and exit |
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer