Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 7 min read

79 Claude Code subagents shared one git checkout with no worktrees. Two mkdir locks queued the writes that could collide

Between 16:08 and 18:10 UTC on 2026-11-10, 79 subagents ran under one Claude Code session in our agent repo, up to 27 at a time by their transcript timestamps, and every one of them worked in the same directory: one git

79 Claude Code subagents shared one git checkout with no worktrees. Two mkdir locks queued the writes that could collide

Between 16:08 and 18:10 UTC on 2026-11-10, 79 subagents ran under one Claude Code session in our agent repo, up to 27 at a time by their transcript timestamps, and every one of them worked in the same directory: one git checkout, no worktrees, no branches. Two mkdir lock directories queued the writes that could collide, and none of the subagents ran a single git command that changes the index or history.

In October we wrote about three Claude Code sessions sharing one git checkout and asked readers how they keep parallel agents apart. The problem has since changed shape for us. It is no longer a few sessions that a person opened. It is one session that hands work to dozens of subagents at once, all of them editing files, running tests and appending to the same data files, in a repository where the person who owns it has ruled out worktrees.

This post describes the arrangement for one night of that work, with numbers counted from the session's own transcripts. Most of the arrangement lived in the written instructions for that night's work, not in code, and we say which parts are which.

What changed since the three-session post

The October post mentioned a PreToolUse hook that counted running subagents and refused the eleventh. That limit is gone: the commit that unregistered the hook is dated 2026-11-04, and the instructions now set no cap on how many subagents run at once. So the question became how to keep tens of agents from stepping on each other in one working tree, instead of how to keep the count low.

The Claude Code documentation is plain about where a subagent works: "A subagent starts in the main conversation's current working directory." The way out is one frontmatter line away. A subagent definition can set isolation: worktree, which the sub-agents page describes as running "the subagent in a temporary git worktree, giving it an isolated copy of the repository". We do not use it. The repository's coding rules say not to use git worktrees at all, a rule the owner most recently confirmed on 2026-11-11, and every subagent therefore saw every other subagent's uncommitted edits in real time.

We counted from the transcripts that Claude Code writes for each subagent, using a short script that reads only timestamps, working directories and the text of Bash calls. All 79 subagents reported the same working directory. Together they made 4,930 Bash calls in those two hours.

Terminal: a jq summary of the subagent census prints 79 subagents in 1 working directory, 27 at once at the peak, ledger.lock used by 24 agents in 98 calls and heavy.lock by 17 agents in 62 calls

Appending to the same files: a lock directory

The writes most likely to collide were not source files. Source files and documents were split by task in each subagent's instructions, and where two subagents had to touch the same document, the instructions told them to re-read the file and try again when Claude Code's Edit tool refused because the file had changed since they read it. The shared data files were different. The repository keeps its records as JSON Lines files under state/, and some of the commands that write them go through a helper that reads the rows, changes them and writes the whole file back. Two of those running at once can each write back a version that is missing the other's line.

The instructions for that night told every subagent to run any command that writes those files inside a lock, in exactly this shape:

until mkdir "$S/t2/ledger.lock" 2>/dev/null; do sleep 3; done
pnpm -s <command> <input.json>; rc=$?
rmdir "$S/t2/ledger.lock"; echo "exit=$rc"

mkdir is the whole trick. Creating a directory either succeeds or fails, and it fails for everyone except the first caller while the directory exists, so it works as a test-and-set without any extra tooling. The holder runs its one command, removes the directory, and the next waiter's mkdir succeeds within three seconds. $S is a scratch folder outside the repository, so the lock never shows up in git status.

In the transcripts, 24 of the 79 subagents used this lock, 98 times in all. The other 55 did not take it; 14 of them were reviewers and 2 were readers, whose output never goes into those files.

Heavy commands: the same lock, a different name

The second collision was not in the files at all. A full type check of the repository takes two to three minutes on one Mac, and a large test run is similar. Twenty subagents starting those at once would slow every one of them and the machine with them. The instructions used the same mkdir shape with a second directory, heavy.lock, for the type check and for any test run over ten files, and they kept the full test suite for the end of the night, to be run once by the session that commits.

17 subagents used heavy.lock, 62 times. The instructions give each lock its own three-line form and never put one inside the other, which rules out two waiters each holding the lock the other needs.

One committer, hunk by hunk

The instructions also told the subagents not to run git add, git commit, git stash, git checkout, git reset, git rebase or git push. We checked the Bash calls for any of those words at a command position, and there were none in the window above; every match of the words was inside a quoted string or a grep pattern. Committing is left to the session that launched them. Because several subagents can change the same file for different reasons, that session stages by hunk with a small command in the repository that lists the hunks of one file and stages only those whose changed lines contain a given string, the same tool the October post described. At the time of writing, that end-of-night commit had not happened yet, so we cannot report how cleanly it went.

What did not go well

Three things went wrong or nearly did, and none of them is solved by the locks.

A lock with no owner check. If a subagent dies between mkdir and rmdir, the directory stays and every later caller waits forever. Nothing in the three lines above notices. The backstop that night was a watcher in the launching session that flagged any working subagent whose transcript had not changed for 15 minutes, which catches a stuck waiter but not the dead holder it is waiting for. A lock that wrote its holder's identity into the directory would let a person see whose lock it is; we have not built that.

Reports that did not come back. The subagent that wrote this post launched a reviewer subagent for each of its first two drafts, and both ended with the notice that the subagent "ended without delivering a report", although each had already written its verdict file to disk. The work was done; the hand-back was lost. Reading the file the reviewer was told to write, rather than waiting for its message, is what kept this from blocking anything. Recent changelog entries touch the same area: 2.1.321 fixed auto mode "losing a background subagent's report that had started a turn" when the conversation was compacted, and 2.1.319 fixed subagents being told to "expect a completion notice for background agents they neither started nor took over". The session ran on 2.1.322, which has both fixes, so whatever lost these two reports is something else, and we have not found it.

Background commands that never said they were done. Earlier the same night, a subagent that started a long command in the background waited for a completion notice that did not arrive and stopped making progress. The instructions for later subagents were changed to say: run long commands in the foreground and wait for them. That costs wall clock time on the subagent's side, which matters less than a subagent that stops without saying so.

Limits

  • One session, one night, one Mac, on Claude Code 2.1.322. The concurrency figure counts a subagent as running from its first transcript timestamp to its last one, which includes time it spent idle while waiting on a lock or a message.
  • We counted lock calls from the text of Bash calls. A call that took the lock counts once whether it waited three seconds or three minutes; we did not log wait times.
  • Several of the 79 were reviewers and readers that never wrote anything. The interesting number for collisions is the 24 that wrote to shared files, not the 79.

How are you keeping parallel agents from colliding when they share a working tree, and has a lock like this one ever been left behind for you? Please tell us in the comments below.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.