git worktrees and agentmash: use both
published · updated
git worktrees, like Claude Code’s and Cursor’s, give each agent its own checkout, so no two agents write the same file on disk. agentmash tells your agent what your teammates’ agents are changing, on any branch and any machine, before it edits. by default it doesn’t warn your own agents about each other: keeping them apart is the worktree’s job.
what worktrees do
a git worktree is a second working directory of the same repository, with its own files and its own branch, sharing one history. git worktree add ../app-feature-a -b feature-a makes one, git worktree list shows them all, and by default git won’t check out a branch that another worktree already has.
Claude Code and Cursor make them too. as their docs read on , Claude Code’s --worktree flag, or -w, starts a session in a worktree of its own under .claude/worktrees/<name>/, on a new branch named worktree-<name>, and Cursor runs an agent’s task in a worktree from its Agents Window, or with /worktree in the editor. either way, agents running side by side on one machine stop editing the same files on disk.
git worktree vs claude code’s --worktree
git worktree add and the flag both make a checkout, and the flag does the bookkeeping around it: it names the folder and the branch, copies the gitignored files a .worktreeinclude lists, keeps its edit tools’ writes out of the main checkout (a shell write such as cp or a redirect isn’t refused, and the repository’s own filter drivers, Git LFS installed with --local among them, are skipped), and, when an interactive session ends, removes the worktree or asks whether to keep it. plain git worktree add is for an existing branch or a folder outside the repository, which is when Claude Code’s worktrees page says to make one with git directly.
how each tool makes a worktree
each tool makes the same kind of checkout and keeps it somewhere of its own, as their docs read on :
| tool | how you start one | where it goes |
|---|---|---|
| Claude Code | claude --worktree <name>, or -w | .claude/worktrees/<name>/, on a new branch, worktree-<name>, from the default branch, by default |
| Codex, in the ChatGPT desktop app | Worktree under the composer, then a starting branch | $CODEX_HOME/worktrees, in a detached HEAD; the 15 most recent are kept by default |
| Cursor | the Agents Window, or /worktree and /best-of-n in the editor | set up by .cursor/worktrees.json; 25 kept per machine by default |
| the GitHub Copilot app | a new working tree, chosen when a session starts | a working tree and a branch of the session’s own; a session can also run in your local repository or in a cloud sandbox |
whichever makes it, a worktree keeps that tool’s agents on one machine out of each other’s files. none of them reaches a teammate’s checkout. agentmash’s hooks are the Codex CLI’s and GitHub Copilot’s in VS Code and its CLI; its docs don’t describe what a session in the ChatGPT desktop app or the Copilot app gets.
claude code worktree cleanup
when an interactive session exits and its worktree is clean, Claude Code removes the worktree and branch of a session without a name, and asks first when the session has one (a name given with /rename or --name, not the worktree’s). a worktree with changes, untracked files or new commits always gets the question, keep or remove. a run with -p never cleans up, so git worktree remove takes its worktree out (with --force if it still has changes or untracked files), after git worktree unlock if git says it’s locked. Claude Code’s worktrees page describes all of this, and Cursor’s puts its own default cap at 25 worktrees per machine.
what a worktree leaves out: .env files, ports and databases
- untracked files. a new worktree checks out tracked files only, so
.envand anything else gitignored isn’t in it. Claude Code copies what a.worktreeincludelists, and Cursor runs the setup commands in.cursor/worktrees.json, which Cursor’s worktrees page shows copying.envover from the main checkout. - dependencies and builds. a new worktree is a fresh checkout, so it needs its own install and its own build output. Cursor’s worktrees page advises against symlinking dependencies in from the main checkout, since that can cause problems in the main one.
- ports, databases and other services. worktrees isolate file edits, as Claude Code’s page puts it, and the programs you start from them share one machine. two dev servers started from two worktrees with the same config still want the same port, and if both point at one local database, a migration or a seed run in one changes it for the other.
- the repository itself. every worktree writes to the one
.git. branches, tags and stashes are refs, which every worktree shares, and so, by default, is the repository’s config. a branch is checked out in one worktree at a time unless you force it.
what worktrees don’t catch
- the same file, changed on two branches. your agent works in a clean checkout, so it isn’t told that a teammate’s agent is changing the same file on another branch. the conflict shows up at the merge.
- a break across files. your agent changes the signature of an exported function,
createUserinsrc/models/user.ts; a teammate’s agent, three files away insrc/api/handlers.ts, keeps building against the old one. no path is shared, so nothing about the files says they collide, and git merges the two without a conflict: a semantic merge conflict, found when something breaks. - a teammate’s worktree. worktrees separate the agents on one machine. a teammate’s agents work in their own checkout on their own laptop, and nothing on your machine knows about their changes.
what agentmash adds, across branches
the edits each developer’s connected agents report go to one room for the repository, and every worktree of it reports to that same room, each on its own branch. a worktree in a detached HEAD reports its commit instead. agentmash compares each developer’s edits with their teammates’, and by default not with their own, so before an edit your agent is told about a teammate’s change to the same file, worded by where that change is:
- on another branch, or in a clone of their own,
PARALLEL EDIT: there’s nothing to re-read, so the agent keeps its edit additive, doesn’t reformat or reorder, and names any divergence in its reply. a teammate’s change on another branch reaches your agent before the edit instead of at the merge. - in the same checkout,
ACTIVE COLLISION, orSTALE READonce the teammate has gone: their write is already in your working tree, so the agent re-reads the file and rebuilds its edit against what’s there. each edit carries an opaque id of the checkout it came from, so the hook can tell a shared checkout from a clone on a branch of the same name; when it can’t, the advice says what to do either way. - across files: the hooks send the exported names an edit changed and what each file imports, so a teammate’s change to
createUsercan reach your agent before it edits a file that imports it directly, whatever directory it’s in, when the change is within the conflict window (30 minutes by default) and their agent reports the names it changed (Claude Code’s edits do; a Codex patch and Cursor’s edits don’t). for this match, the server gets the names, not the code. a re-export barrel, the ten quiet minutes after an advisory and the agents that hear it only after an edit are in known limitations. - before anyone writes: an agent can claim the paths it’s about to change, and learns whether a teammate already has part of them, so it can take other work.
- after the fact: in Claude Code, Codex and GitHub Copilot, if your agent and a teammate’s changed the same file anyway, you’re told once, as the session finishes, with whose change it meets, before either change lands. nothing is merged, pushed or opened for you: a person decides. a room can turn this notice off (
agentmash reconcile off).
side by side
| what happens | git worktrees | agentmash | both |
|---|---|---|---|
| two of your own agents writing one file on disk | can’t happen: each has its own checkout | can happen, and by default neither is warned | can’t happen |
| two of your own agents changing one file on two branches | found at the merge | by default neither is warned: both report as you | found at the merge |
| knowing what a teammate’s agent is changing | no | yes, before each edit | yes, before each edit |
| a teammate’s agent changing the same file on another branch | found at the merge | told before the edit | told before the edit |
| a teammate’s change to a function your file imports | found when something breaks | told before the edit, in JavaScript and TypeScript, within the conflict window, when their agent reports the names it changed (Claude Code’s edits do) | told before the edit, in JavaScript and TypeScript, within the conflict window, when their agent reports the names it changed |
| teammates’ agents on other machines | not seen | in the same room | in the same room |
| a teammate’s agent and yours changed the same file anyway | a merge conflict for a person | in Claude Code, Codex and GitHub Copilot, by default, you’re told as the session finishes, before either change lands | in Claude Code, Codex and GitHub Copilot, by default, you’re told as the session finishes, before either change lands |
keep your worktrees
nothing about a worktree flow changes. someone connects the repository once, each developer signs in once on each machine with npx agentmash login, and every worktree of the repository that a connected agent works in reports to its room from then on. the setup page has the steps for Claude Code, Cursor and the other coding agents.
what it doesn’t do
- symbols are read from the JavaScript and TypeScript family only. Python, Go and Rust files are matched by path alone, so a break across files in them goes unseen.
- a match across files needs the teammate’s change within the conflict window, 30 minutes by default, and an agent that reports the names it changed. Claude Code’s edits do; a Codex patch and Cursor’s edits don’t, so a change made in either reaches only the files it changed, unless a claim lists the names.
- an advisory is not a lock: it informs the agent, and the edit goes ahead (in Cursor and the tools like it, on the agent’s second try).
AGENTMASH_STRICT=1is the setting that blocks. - it warns about teammates’ agents, and not your own unless you set
AGENTMASH_WARN_SELF=1. two of your agents, in two worktrees or in one checkout, both report as you, so by default neither is warned about the other, and a file both change raises no overlap notice. - agentmash makes no checkouts. keeping your own agents out of each other’s files is the worktree’s job.
- in a Claude Code worktree session started from the desktop app, or one that moved into a worktree after it started, the files a shell command changes in the worktree aren’t reported; edits made with Claude Code’s own edit tools are.
what counts as a conflict →the five levels →claims →reconciliation →known limitations →