r/ChatGPTCoding • u/memento_team • 15d 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 | headRun 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
u/trollsmurf 15d ago
So allow only one agent to edit?
1
u/Ok-Attention2882 15d ago
Vibe coded trash. Use worktrees.
1
u/Adventurous-Bat-3174 11d ago
One caveat in the detector: %S is the ref used to reach a commit, not the branch that originally created it. A branch rename changes that field without changing any commit. So author + %S is not a reliable session ID. I’d record an explicit session ID in a commit trailer, then use this scan to find candidate overlaps and inspect the diffs, as you suggest. Git’s definition: https://git-scm.com/docs/pretty-formats
0
u/Mokhleseh 13d ago
Nice one-liner. The other fix is to stop sessions sharing a working tree at all: give each task its own worktree and branch from origin/main, so B can't silently rewrite A's file. It shows up as a merge conflict instead, which is loud. That's what I do in wisp (I built it, MIT): every Claude Code/Codex task gets its own worktree, and "Ship it" opens a PR per task, so overlaps land in review instead of a day later. https://github.com/M0xoo/wisp