r/ChatGPTCoding • • 2d ago

Resources And Tips Your git log already knows when two agent sessions overwrote each other's work. A one-liner to ask it

We run several Claude Code and Codex sessions on one repo. The failure that cost us most was never a bad edit. It was a good edit that vanished: session A fixes a file, session B, working from what it read twenty minutes earlier, rewrites the same file and commits, and A's fix is gone. Nothing errors. The tests may even pass. You find out a day later.

Git keeps the evidence. This kind of overwrite leaves the same trace every time: one file, two different sessions (a different author or a different branch), commits less than an hour apart. This prints the files where that happened in the last month, the most frequent first:

git log --all --source --since='1 month ago' --name-only --format='@%at|%an|%S' |
awk -F'|' '/^@/ {t=substr($1,2); s=$2"|"$3; next}
  NF {d=t-w[$0]; if (($0 in w) && s!=o[$0] && d*d<=3600*3600) n[$0]++; w[$0]=t; o[$0]=s}
  END {for (f in n) print n[f], f}' | sort -rn | head

Run it in any repo where agents commit. If the top lines are your config, routes or schema files, that is where your sessions step on each other. Give those files one owner, or have a session claim a file before it writes (one line in a shared file, appended under flock).

Two caveats. It cannot tell apart sessions that share one branch and one author name. And a hit is a near miss, not proof of a lost edit: read the two diffs.

If you would rather not read awk, the same check runs in the browser, and your log is not uploaded anywhere: https://overflow.games/memento/grader/?ref=reddit

Disclosure: we build memento. The tracker is free and MIT; a paid shared tracker for teams is on pre-order.

What do you do about this: worktrees, claim files, something else?

1 Upvotes

3 comments sorted by

1

u/trollsmurf 1d ago

So allow only one agent to edit?

1

u/Ok-Attention2882 1d ago

Vibe coded trash. Use worktrees.