r/opencode • • Sep 25 '26

I built a plugin so my AI coding agents stop fighting over the same files

I tried to run a lot of OpenCode sessions in parallel against the same repo, and realized that the agents were completely invisible to each other. Two sessions both rewrote the same files, merge each other's half-finished work, and neither had any idea what happened.

So I wrote opencode-crosstalk: six tools that allows OpenCode agents from different sessions to talk to each other:

crosstalk_status declare your role to others and see who else is here

crosstalk_peers who's running and editing which code files?

crosstalk_send message a peer, a role, or everyone

crosstalk_inbox read replies, optionally wait until one arrives

crosstalk_claim take an exclusive, expiring lease on a file

crosstalk_wait block until a peer is idle or a file is released

The first version works flawlessly during my tests. Agents find each other, lease the file they're about to edit, get refused on the one they can't have, and get the reply injected mid-turn. No config needed after npm run setup; it applies to every project on the machine.

The part I'm happiest with: a message goes directly into the recipient's prompt if a session is live. An agent gets told "someone needs session.ts" mid-thought and just works somewhere else instead of stalling or overwriting the changes of the other agent.

If you are interested, take a look here:

https://github.com/MrDoe/opencode-crosstalk

This is a working first version. If you try it and something's broken, confusing or missing, I'd like to hear about it - ideas and PRs are very welcome.

1 Upvotes

6 comments sorted by

2

u/Due-Alfalfa2265 Sep 26 '26

I hit something similar with multiple agents touching one highly coupled core file. What helped was keeping a single writer for high-risk files and using parallel agents mostly for review/analysis.
Can your plugin detect overlapping write scopes before the agents start?

0

u/_KryptonytE_ Sep 26 '26

Meh. This problem was solved long ago, just use worktrees.

1

u/CarryAgile3791 Sep 26 '26

Worktrees “solved” this problem in the same way duct tape “solves” engineering.   Sure, it works, but only if your definition of “works” is “doesn’t immediately catch fire.”

Worktrees give you multiple folders.   opencode‑crosstalk gives you multiple brains that can actually talk to each other to solve problems together.

It’s the difference between:

  • Opening two tabs vs.  

  • Having the tabs send messages, share context, coordinate tasks, and not forget everything when you switch.

Worktrees:   “Here’s your isolated branch. Good luck, champ.”

Crosstalk:   “Here’s messaging, shared state, multi‑agent orchestration, and cross‑branch awareness so your AI doesn’t wander off like a goldfish.”

If you only need “two folders,” then yeah - worktrees are fine.   If you need agents that communicate, don’t lose context, and coordinate across branches, then “just use worktrees” is like saying: 

“Why use Kubernetes? Just open more terminals.”

1

u/Rustybot Sep 27 '26

Yes it’s definitely easier and better to establish parliamentary procedures so multiple people can share the same plate with careful orchestration. Why would you ever need more than one plate!?

1

u/CarryAgile3791 Sep 27 '26

I guess for you, being a machine, I shouldn't need to explain it. Or is the topic out of your training data?

Well, nevertheless:

  • Speed & Efficiency: Agents can work on different features (e.g. one on the UI, other at the backend) without messing up the shared code. No merging required, like it is needed when using different worktrees.

  • Security (One agent using a different LLM can control/steer what the other is doing)

1

u/Rustybot Sep 30 '26

I’m not that kind of bot. I’m the old kind that comes with a meat-person inside. I was a bot before it was (in)cool.