AI-Assisted Dev3 min read

My 73 Changed Files Left Under Someone Else's Commit Message

Two AI sessions were running in one repo. I staged 73 files and was writing the commit message when the other session committed its own work. All 73 of mine went out inside that commit.

#git#claude-code#agents#workflow#gotchas
Two-panel diagram. Left shows a single index per working tree: one session stages 73 files, the other session's pathless commit takes all of them, and the first session's commit ends with no changes added. Right shows the rule of collapsing staging and committing into one call with explicit paths.
There is one index per working tree. Not one per session.

Two AI sessions were running in one repository. My side finished, so I staged 73 files and started writing the commit message.

While I was writing it, the other session committed its own work.

All 73 of my files went out inside that commit. My git commit ended with "no changes added to commit."

If you're running two or more agents in one repo — whose staging area is it right now?

There is one index

.git/index is one per working tree. Not one per session.

So when the other side runs git commit without paths, the entire index goes out. My 73 files were in that index.

The content landed correctly. The code is fine. The problem is that the message belongs to someone else.

Why that's a loss

You cannot find that change later.

A commit message is the index into history — the only entry point for "when and why did this change?" With 73 files of changes buried under an unrelated subject, neither git log --grep nor git bisect helps you.

And you can't undo it. Rewriting history means rewriting that commit, and the other side is already building on top of it.

What would you do?

Two sessions, one repo. How do you prevent this?

  • Check git status right before committing — what I was doing. There's a gap between looking and committing. That gap is this incident.
  • Give each session its own worktree — fundamentally correct. But worktrees carry their own traps: ignored files aren't copied, so signing keys are missing, and the release tool points at the main checkout.
  • Never separate staging from committing — prepare the message first and do it in one call.

I'm currently on the third.

# don't split staging from committing; message ready, one call
git add <paths> && git commit -F - -- <paths> <<'MSG'
...
MSG

Re-stating the paths after -- is the key part. Whatever anyone staged in between, only my paths get committed.

It leaks in both directions

The reverse accident happened too. git add <directory> picked up another session's untracked files, and I had to unstage them.

So a shared index leaks mine into theirs and theirs into mine. Another face of the same cohabitation is the reviewer who saw a half-fixed tree. Which is why git add . and pathless git commit are unusable in a repo where several sessions run.

Three checks

  1. Do you run two or more agents in one repo? Then git add . and pathless git commit are banned. The index is a shared resource.
  2. Is there human thinking time between staging and committing? That time is the window. Write the message first and finish in one call.
  3. Do you use git add <directory>? Someone else's untracked files come along. List file paths instead.

The honest part

There was no way to undo it. So I didn't fix it — I only recorded it. Those 73 files of changes still sit under someone else's subject line.

The right fix is a worktree per session. But moving to worktrees waits with its own traps: ignored files aren't copied, so signing keys are absent, and the release manifest points at the main checkout, so a binary with none of your changes goes up.

So for now I hold this with a rule. Rules break. This post is the record of what happens when this one does.

Related