Idea: use Turso/ZeroMQ/WebSockets for shared event bus, synchronize multiple opencode TUIs and servers #1829

Open
opened 2026-02-16 17:32:50 -05:00 by yindo · 5 comments
Owner

Originally created by @remorses on GitHub (Sep 25, 2025).

Originally assigned to: @thdxr on GitHub.

Currently opencode uses an in memory event notification system, this means that you cannot have 2 opencode sessions open at the same time or use opencode serve and opencode tui at the same time.

This is a problem for kimaki: if you try to write messages in Discord and also the tui the opencode chat will hang, probably because it is in a broken state, because state is not synchronized between the 2 processes

If instead opencode uses ZeroMQ for the process notification bus

  • Multiple processes could publish and subscribe to same session (you can use both tui and serve at the same time
  • If you open an opencode session in 2 multiple terminals they will both show the latest chat state https://github.com/sst/opencode/issues/2403

Unfortunately ZeroMQ does not seem to work in Bun right now so we would need to create a port form Zig bindings using ffi or NAPI

Originally created by @remorses on GitHub (Sep 25, 2025). Originally assigned to: @thdxr on GitHub. Currently opencode uses an in memory event notification system, this means that you cannot have 2 opencode sessions open at the same time or use `opencode serve` and `opencode` tui at the same time. This is a problem for [kimaki](https://kimaki.xyz): if you try to write messages in Discord and also the tui the opencode chat will hang, probably because it is in a broken state, because state is not synchronized between the 2 processes If instead opencode uses [ZeroMQ](https://zeromq.org/get-started/) for the process notification bus - Multiple processes could publish and subscribe to same session (you can use both tui and serve at the same time - If you open an opencode session in 2 multiple terminals they will both show the latest chat state https://github.com/sst/opencode/issues/2403 Unfortunately ZeroMQ does not seem to work in Bun right now so we would need to create a port form Zig bindings using ffi or NAPI
Author
Owner

@github-actions[bot] commented on GitHub (Sep 25, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #2403: Shows the exact same problem you're describing - messages created by the SDK aren't shown in real time in the CLI when using different processes, and state synchronization issues between multiple sessions
  • #878: Feature request for connecting TUI to existing opencode serve instances (closed but directly related to multi-session support)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Sep 25, 2025): This issue might be a duplicate of existing issues. Please check: - #2403: Shows the exact same problem you're describing - messages created by the SDK aren't shown in real time in the CLI when using different processes, and state synchronization issues between multiple sessions - #878: Feature request for connecting TUI to existing `opencode serve` instances (closed but directly related to multi-session support) Feel free to ignore if none of these address your specific case.
Author
Owner

@taqtiqa-mark commented on GitHub (Sep 28, 2025):

this means that you cannot have 2 opencode sessions open at the same time or use opencode serve and opencode tui at the same time.

@remorses I believe that the new opencode attach <prot://host:port> resolves this?

https://github.com/sst/opencode/pull/2635#issuecomment-3301698491 see 40c206c2f9

@taqtiqa-mark commented on GitHub (Sep 28, 2025): > this means that you cannot have 2 opencode sessions open at the same time or use `opencode serve` and `opencode` tui at the same time. @remorses I believe that the new `opencode attach <prot://host:port>` resolves this? https://github.com/sst/opencode/pull/2635#issuecomment-3301698491 see 40c206c2f9999689572926a758c3661297e99a95
Author
Owner

@remorses commented on GitHub (Sep 29, 2025):

it's not a great DX. I don't know the port the server is listening to, i want to use /sessions command instead

Also doesn't work if i have an already open tui and want to start a server for the same project

This behavior needs to be baked in

@remorses commented on GitHub (Sep 29, 2025): it's not a great DX. I don't know the port the server is listening to, i want to use /sessions command instead Also doesn't work if i have an already open tui and want to start a server for the same project This behavior needs to be baked in
Author
Owner

@taqtiqa-mark commented on GitHub (Sep 29, 2025):

Some of this isn't documented, or the docs are wip:

I don't know the port the server is listening to

That is either the default port 4096, or the port you nominated with opencode serve --port 1234 --hostname 127.0.0.1
Note that opencode starts a server with default port and hostname, and connects the TUI client to that.

Also doesn't work if i have an already open tui and want to start a server for the same project.

As above, when you started the TUI, it started a server (with defaults) for you.

Test:

opencode &

# Step 3: Wait briefly for server to start (adjust sleep if needed)
sleep 5

# Step 4: Check if port 4096 is listening (using ss; install net-tools if using netstat)
ss -tuln | grep 4096  # If output shows LISTEN on :::4096 or 0.0.0.0:4096, it's running

# Alternative: Use curl to verify the API docs endpoint (should return HTML if server is up)
curl -f http://127.0.0.1:4096/doc || echo "Server not responding"

# Step 5: Clean up (stop the server and any processes)
pkill -f opencode  

i want to use /sessions command instead

Maybe that can be a separate issue, given this one concerns "multiple opencode TUIs and servers)"?

@taqtiqa-mark commented on GitHub (Sep 29, 2025): Some of this isn't documented, or the docs are wip: > I don't know the port the server is listening to That is either the default port `4096`, or the port you nominated with `opencode serve --port 1234 --hostname 127.0.0.1` Note that `opencode` starts a server with default port and hostname, and connects the TUI client to that. > Also doesn't work if i have an already open tui and want to start a server for the same project. As above, when you started the TUI, it started a server (with defaults) for you. Test: ``` opencode & # Step 3: Wait briefly for server to start (adjust sleep if needed) sleep 5 # Step 4: Check if port 4096 is listening (using ss; install net-tools if using netstat) ss -tuln | grep 4096 # If output shows LISTEN on :::4096 or 0.0.0.0:4096, it's running # Alternative: Use curl to verify the API docs endpoint (should return HTML if server is up) curl -f http://127.0.0.1:4096/doc || echo "Server not responding" # Step 5: Clean up (stop the server and any processes) pkill -f opencode ``` > i want to use /sessions command instead Maybe that can be a separate issue, given this one concerns "multiple opencode TUIs and servers)"?
Author
Owner

@athal7 commented on GitHub (Jan 2, 2026):

Still encountering this - opening multiple TUI instances for the same directory doesn't sync the session list. Would love to see this addressed. Happy to help test any solutions.

@athal7 commented on GitHub (Jan 2, 2026): Still encountering this - opening multiple TUI instances for the same directory doesn't sync the session list. Would love to see this addressed. Happy to help test any solutions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1829