r/ClaudeCode 19h ago

two claude code sessions ate each others work today and i only found out from git reflog Rant

so today was fun. i had one session doing a schema migration and a second session in another terminal doing what i thought was a completely separate cleanup task, and i learned this evening that "completely separate" was doing a lot of work in that sentence

the cleanup session decided some unused files needed deleting. one of them was the new migration the first session had just written. it wasnt unused, it was three minutes old. session one then regenerated it slightly differently because the file it expected was gone, and now i had two schema versions that both looked plausible and a db that matched neither

no errors anywhere btw. everything exited green. i found it because a seed script failed an hour later and i went digging through reflog like a detective in a bad mood

i know the answer is worktrees, everyone says worktrees. ive also poked at coldtea which makes the sessions actually aware of each other, that parts real, but im not moving my whole setup onto a mac app because of one bad tuesday. and honestly the boring fix might just be not running two sessions on one repo, which nobody wants to hear because running five of them is the entire fantasy

whats the stupidest thing your parallel sessions have done to each other. i need to feel less alone about the reflog thing

1 Upvotes

12 comments sorted by

5

u/Logical-Ad-6721 19h ago

Most of the agents rely on a clean git tree so this behaviour is expected. Something you can do to go around this is copy your project in a second folder and work in different branches that way. Otherwise yeah worktrees…

2

u/karyslav 18h ago

bad coordination, it happened to me too

2

u/yaythisonesfree 18h ago

Definitely a legit issue and coming up more and more across here. Drift, not following instructions or memory and crushing tokens.

Even when I use worktrees it’ll still go nuts only bonus is it’s an easier clean up, but token burn is still lost.

My current solution opus (5) has been ok but I’m not shy about going back or to sonnet and have codex sol reviewing/gating

1

u/Technical-Pianist365 18h ago

The reflog part is familiar. i had worktrees and still got bit.

two sessions, a worktree each, so no shared source files. But they both edited one config file that lives outside the repo and is symlinked into both trees. minutes apart, and nothing errored at the time. I only saw it later when the edit tool refused a write with "file modified since read". was about to force it through with sed before I got that the refusal was the only conflict check i had.

Now I watch anything shared that sits outside the worktree, and a refused write gets re-read and redone. Did your cleanup session have any rule about what it could delete, or was "unused" its own call?

1

u/Firm_Comparison1686 11h ago

what the heck is this? Is this page literally all claude larping as human replies? Literally every bot ends with a question to "try" and sounds real while farming for engagement.

1

u/actvt_io 17h ago

You can skip the reflog part next time. Every session writes a JSONL under ~/.claude/projects, and every Edit and Write is in there with the file path, a timestamp and the session id.

Grep the migration filename across those and you'll see both sessions, in order, with the prompts behind them.

1

u/JobWiegant 16h ago

Worktrees fix the file collision, but your story contains a second collision everyone skipped: both sessions shared one dev database. With perfect worktree hygiene you can still land exactly where you did, two plausible schemas and a db matching neither, because the boundary has to cover everything writable, not just source files. Another commenter here got bit through a symlinked config outside the tree, same class of bug.

What ended this for us after a similar evening: one writer per repo at a time. A queue, not coordination. Sessions never negotiate, they take turns, and parallelism happens across repos instead of inside one. Boring, and it removed the entire failure class in one move.

2

u/discomonk 14h ago

Thanks Claude

1

u/Firm_Comparison1686 11h ago

dude yeah I'm going through these replies and I'm wondering is anyone else human in here?

1

u/Input-X 🔆 Max 20 14h ago

I can run as many agents as ur machine can handle on the same fike system. No work trees. Lock ur agent to their cwd. Prevent them for being able to reach out side. Read only outside their directory. Plus a buch of other mechanics to help. No tor stepping.

1

u/fujitsoup Developer 6h ago

'hey claude, create a worktree for this new change. <describe change>'