A sane workflow for running multiple agents (and/or multiple parallel tasks) in the same repo.
Now that you've got AI coding agents chugging away at your codebase, you have a problem: agents are stepping on each other's toes (and maybe yours).
The solution is Git Worktrees: multiple working folders that share the same Git history, but each checks out its own branch. Each agent gets its own worktree.
- Run these commands from your main project root with
developchecked out. Keepdevelopclean and up to date. - Run
sesh <branch>to create a sibling worktree for a task/agent. This will branch off ofdevelopinto a new copy of the code located next to your main project. The sibling folder will be named<project>-<branch>. - When you’re done, run
sesh-killfrom inside the worktree you want to remove (or remove it manually; instructions below).
- Clone this repository or download the
sesh.zshscript to a location of your choice:
git clone <repository-url> ~/.sesh-agent-workflow
# or download sesh.zsh to any directory you prefer- Add this line to your
~/.zshrc:
source ~/.sesh-agent-workflow/sesh.zsh- Reload your shell configuration:
source ~/.zshrcOr simply open a new terminal window.
Creates a new sibling worktree and checks out a new branch from develop.
It will:
- Update
develop(fetch+switch develop+pull --ff-only) - Create a new worktree in a sibling folder named
<project>-<branch> - Install dependencies:
- By default: detects Node lockfiles and runs the appropriate install in repo root,
client/, andserver/(if present) - Configurable: see Configuring install commands below
- By default: detects Node lockfiles and runs the appropriate install in repo root,
Example:
cd /Users/you/Sites/<project>
sesh bug/secure-ai-endpointDifferent projects have different install commands (monorepos, pnpm/yarn, backend-only repos, etc).
To customize installs for a repo, create a file at the repo root of your develop worktree:
.seshrc(or.seshrc.zsh)
If that file defines a sesh_install function, sesh will call it from inside the new worktree root.
Example (.seshrc):
sesh_install() {
# Runs from inside the NEW worktree root
(cd client && npm ci)
(cd server && npm ci)
}To skip installs entirely:
export SESH_SKIP_INSTALL=1Deletes the current worktree folder and deletes its local branch, but only if:
- The working tree is clean (no changes)
- You are not on
developormain - You are not inside the
developworktree
Example (run from inside the sesh worktree you want to delete):
sesh-killgit worktree listMore detail:
git worktree list --porcelainFrom your main develop worktree:
git fetch origin
git switch develop
git pull --ff-only
git worktree add -b bug/my-fix ../my-project-bug-my-fix developgit worktree remove /path/to/worktree
git worktree pruneWorktree removal does not delete branches.
git branch -d branch-name # safe (won't delete if unmerged)
git branch -D branch-name # forceRemote (optional):
git push origin --delete branch-name- “branch is already checked out at …”
- That branch is currently checked out in another worktree. Use that worktree, or switch it off that branch before checking it out elsewhere.
- “cannot switch branch while merging”
- Your
developworktree is mid-merge (or mid-rebase/cherry-pick). Finish it (git status→ resolve → commit/continue) or abort it, then rerunsesh.
- Your
- Don’t delete worktree folders in Finder
- Prefer
git worktree remove …so Git cleans up its metadata.
- Prefer