Agent skill

managing-kata-worktrees

Manage kata-mono git worktrees — switching branches, syncing standby branches to main after PR merges, diagnosing drift, and verifying worktree health. Use when the user mentions worktrees, standby branches, syncing after a merge, "wt-" prefixed names, worktree setup, or asks why a worktree is behind main. Also use when starting work on a ticket (to verify the worktree is current) or finishing work (to return to standby).

Stars 28
Forks 2

Install this agent skill to your Project

npx add-skill https://github.com/gannonh/kata/tree/main/.agents/skills/managing-kata-worktrees

SKILL.md

Managing Kata Worktrees

Architecture

kata-mono uses a multi-worktree layout where each worktree maps to a monorepo app:

Worktree Path Standby Branch App
main (root) kata-mono/ main — (no direct work)
wt-cli kata-mono.worktrees/wt-cli/ wt-cli-standby apps/cli
wt-context kata-mono.worktrees/wt-context/ wt-context-standby apps/context
wt-desktop kata-mono.worktrees/wt-desktop/ wt-desktop-standby apps/desktop
wt-orc kata-mono.worktrees/wt-orc/ wt-orc-standby apps/orc
wt-symphony kata-mono.worktrees/wt-symphony/ wt-symphony-standby apps/symphony

Why standby branches exist: Git prohibits checking out the same branch in multiple worktrees. Since all worktrees need to track main when idle, each has a local "standby" branch that mirrors origin/main. No work happens directly on main in any worktree.

Standby branch tracking

Each standby branch must track origin/main so git pull works:

bash
git branch --set-upstream-to=origin/main wt-cli-standby

If git pull reports "no tracking information," re-run that command. Tracking can be lost if a branch is recreated.

For initial setup of a new standby branch, set tracking and then pull from within the worktree to sync both the ref and working tree:

bash
git branch --set-upstream-to=origin/main wt-<name>-standby
git -C /Volumes/EVO/kata/kata-mono.worktrees/wt-<name> pull

Starting work on a ticket

  1. Verify the worktree is on its standby branch and current with main:
    bash
    git -C /Volumes/EVO/kata/kata-mono.worktrees/wt-<name> log --oneline -1
    # Should match: git log --oneline -1 main
    
  2. If behind, sync first (see below).
  3. Create and check out a feature branch:
    bash
    git -C /Volumes/EVO/kata/kata-mono.worktrees/wt-<name> checkout -b feat/my-feature
    

Returning to standby after a PR merge

After merging a PR on GitHub:

bash
# In the worktree (or using -C from anywhere)
git checkout wt-<name>-standby
git pull

git pull works because the standby branch tracks origin/main. This fast-forwards the standby branch to include the newly merged PR.

If pull fails with conflicts: This means the standby branch diverged from main (e.g., commits landed on standby that weren't in the PR). If the PR contained all the work, reset is safe:

bash
git checkout wt-<name>-standby
git fetch origin
git reset --hard origin/main

Only use reset when you're certain the PR captured all the work. If unsure, inspect with git log wt-<name>-standby..origin/main and git log origin/main..wt-<name>-standby to see what each side has.

Diagnosing worktree drift

To check if all worktrees are current:

bash
git worktree list

All entries should show the same commit hash when idle. If any differ:

bash
# See what main has that the standby doesn't
git log --oneline wt-<name>-standby..main

# See what the standby has that main doesn't (should be empty)
git log --oneline main..wt-<name>-standby

Sync all worktrees after a merge

After merging a PR, pull main from the root repo. Worktrees share the same git object store, so they see the updated refs automatically. Then pull from within each worktree to fast-forward its standby branch:

bash
# From the main repo root
git checkout main && git pull

# Then from each worktree (or using -C)
for wt in wt-cli wt-context wt-desktop wt-orc wt-symphony; do
  git -C /Volumes/EVO/kata/kata-mono.worktrees/$wt pull
  echo "$wt: $(git -C /Volumes/EVO/kata/kata-mono.worktrees/$wt log --oneline -1)"
done

Do not use git update-ref or git reset --hard to sync worktrees. These operate on refs or working trees in isolation and cause dirty state. Use git pull from within the worktree, which updates both the branch pointer and working tree together.

Health check (all worktrees)

Quick verification that everything is in sync:

bash
MAIN_SHA=$(git rev-parse main)
for wt in wt-cli wt-context wt-desktop wt-orc wt-symphony; do
  WT_SHA=$(git -C /Volumes/EVO/kata/kata-mono.worktrees/$wt rev-parse HEAD)
  if [ "$WT_SHA" = "$MAIN_SHA" ]; then
    echo "$wt: current"
  else
    echo "$wt: BEHIND (at $(git log --oneline -1 $WT_SHA))"
  fi
done

Common pitfalls

  • Standby branch loses tracking: Happens if the branch is deleted and recreated. Fix: git branch --set-upstream-to=origin/main wt-<name>-standby
  • Add/add merge conflicts on sync: Happens when the standby branch has commits that also reached main via a PR (same content, different history). Safe to git reset --hard origin/main if the PR captured everything.
  • Working on the wrong worktree: Always verify pwd resolves to the intended worktree, not the main repo. See memory: feedback_worktree_paths.md.

Expand your agent's capabilities with these related and highly-rated skills.

gannonh/kata

kata-context

Structural and semantic codebase intelligence with persistent memory — index TypeScript and Python repos into a knowledge graph with vector embeddings, query symbol dependencies, run semantic search by intent, search code patterns, fuzzy-find symbols, and persist/recall agent memories with git audit trail. Use when you need to understand code structure, find what depends on a symbol, trace dependencies, search by meaning, search for code patterns, find symbols by name, or remember/recall project decisions, patterns, and learnings.

28 2
Explore
gannonh/kata

claude-md-improver

Audit and improve CLAUDE.md files in repositories. Use when user asks to check, audit, update, improve, or fix CLAUDE.md files. Scans for all CLAUDE.md files, evaluates quality against templates, outputs quality report, then makes targeted updates. Also use when the user mentions "CLAUDE.md maintenance" or "project memory optimization".

28 2
Explore
gannonh/kata

frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.

28 2
Explore
gannonh/kata

debug-like-expert

Deep analysis debugging mode for complex issues. Activates methodical investigation protocol with evidence gathering, hypothesis testing, and rigorous verification. Use when standard troubleshooting fails or when issues require systematic root cause analysis.

28 2
Explore
gannonh/kata

swiftui

SwiftUI apps from scratch through App Store. Full lifecycle - create, debug, test, optimize, ship.

28 2
Explore
gannonh/kata

sym-address-comments

Help address review/issue comments on the open GitHub PR for the current branch using gh CLI; verify gh auth first and prompt the user to authenticate if not logged in.

28 2
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results