Loading...
Loading...
Run multiple AI coding agent sessions in parallel using git worktrees — each agent isolated in its own worktree, working on a separate branch. Use this skill whenever the user wants to: run two or more AI agents simultaneously on different features or bugs, set up isolated agent workspaces in the same repo, push parallel branches to GitHub and open/update PRs, coordinate between concurrent agent sessions, or clean up after merging. Triggers on: "parallel agents", "multiple agent sessions", "git worktree", "run agents in parallel", "work on two things at once", "isolated agent workspace", "spin up another agent", or any request involving simultaneous AI-assisted development streams.
npx skill4agent add onsager-ai/dev-skills parallel-worktreesgit worktreeWhat does the user need?
Start a new parallel session?
→ Create a worktree + branch (Lifecycle §1–2)
→ Open a terminal/agent session pointed at the worktree path
→ Brief the agent: "Work only in <worktree-path>. Branch: <branch-name>."
Push and open a PR?
→ git push -u origin <branch>
→ gh pr create (GitHub PR Sync reference)
→ Note related PRs in the description
Sync a worktree with the latest main?
→ Inside the worktree: git fetch origin && git rebase origin/main
→ Never merge across worktrees directly
Merge and clean up?
→ Merge PR on GitHub
→ git worktree remove <path> && git branch -d <branch>
→ git worktree prune
Hit an error?
→ "already checked out" → branch open elsewhere; use a new branch name
→ ".git/index.lock" → two processes on same worktree; one agent per worktree
→ Detached HEAD → git switch -c <new-branch> inside the worktree
→ Stale entry after dir deleted → git worktree prune.git.gitignore~/projects/
myrepo/ ← main checkout (main branch)
myrepo-wt/ ← worktree root (sibling dir)
feat/auth/ ← worktree for branch feat/auth
fix/login-bug/ ← worktree for branch fix/login-bug# New branch (most common)
git worktree add ../myrepo-wt/feat/auth -b feat/auth
# From an existing remote branch
git worktree add ../myrepo-wt/fix/login-bug origin/fix/login-bugWorking directory: /home/user/projects/myrepo-wt/feat/auth
Branch: feat/auth
Scope: implement JWT authentication — do not touch files outside this scopegit addgit commitgit push -u origin feat/auth
gh pr create \
--title "feat(auth): implement JWT login" \
--body "Parallel session. Related: #<pr-number> (if any)."references/github-pr-sync.md# Inside the worktree
git fetch origin
git rebase origin/main # keep history linear# From the main repo (not inside the worktree)
git worktree remove ../myrepo-wt/feat/auth
git branch -d feat/auth
git worktree prune # removes stale metadata entries<type>/<scope>/<short-description>
feat/auth/jwt-login
fix/api/null-pointer
chore/deps/upgrade-pnpm
agent/experiment/refactor-parser ← for exploratory agent sessions| Symptom | Cause | Fix |
|---|---|---|
| Branch open in another worktree | Use a new branch name |
| Two processes on same worktree | One agent per worktree |
| Detached HEAD | Created from a commit SHA, not a branch | |
| Worktree path gone after reboot | Dir deleted externally | |
| Dir removed without | |
| Agent edits files in main checkout | Agent not scoped to worktree path | Re-brief agent with explicit working directory |
references/worktree-lifecycle.mdreferences/github-pr-sync.mdghreferences/agent-coordination.mdnpx skills add -g onsager-ai/dev-skills --skill parallel-worktrees -a claude-code -y