Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

OpenCode uses a client/server architecture. The terminal interface (TUI), browser interface, and Desktop app are clients; the OpenCode server is the process that owns the HTTP API, sessions, and working state. Two interfaces share sessions only when they connect to the same running server process and URL.

opencode web starts a server with a browser interface, and a terminal can join that exact instance with opencode attach <server-url>. Desktop normally starts its own local opencode-cli server sidecar, although it can be configured to use another server. A separately launched web or serve process is not automatically Desktop’s backend.

The service is a backend process, not a cloud account

OpenCode’s server documentation describes the TUI as “the client that talks to the server.” The server exposes HTTP endpoints and an OpenAPI 3.1 specification, so a terminal, browser, Desktop shell, or another compatible client can send requests to it. The server process is where the shared session context lives; the visible interface is only the client used to access that context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This distinction explains most confusing behavior. If two clients use one server URL, they can see the same sessions and state. If each client starts or selects a different server process, they have separate backends even if they run on the same computer. “Shared” therefore describes a connection arrangement, not an account-wide synchronization service.

The official architecture is documented in the OpenCode server documentation.

What starts the server in each interface

OpenCode has several startup paths. They differ by who launches the backend, whether a browser is included, and whether another client can attach to that exact process.

Entry point What it starts Interface Sharing implication
opencode Starts the TUI together with an OpenCode server. Terminal The TUI is a client of the server it starts. Another client must be directed to that server’s URL to share its state.
opencode serve Starts a headless server for API clients. No browser UI Useful when a separate TUI, web client, or other client should connect to a known endpoint.
opencode web Starts a server and opens the browser interface. Browser A TUI attached to this server uses the same sessions and state.
Desktop Runs a local opencode-cli server sidecar by default, or connects to a configured server URL. Desktop app Desktop shares state with whichever URL it has selected, not automatically with every server running on the machine.

The command distinctions are listed in the CLI reference. Exact defaults and flags can change, so check the documentation shipped with the release you installed when a port, host, or option matters.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How terminal and web share one session

The most explicit shared arrangement is to let opencode web own the server and attach the TUI to it. Both clients then address one backend rather than starting independent services.

  1. Start the web server. Run opencode web. It starts an OpenCode server, chooses an available port unless you assign one, binds to localhost by default, and opens the browser interface.
  2. Identify the server URL. Use the URL printed by the command or shown by the browser startup information. The URL must identify the running server, including its host and port.
  3. Attach the terminal. In another terminal, run opencode attach <server-url>, replacing the placeholder with that URL.
  4. Work from either client. The browser and TUI now operate against the same server process. Sessions created or changed through one interface are available through the other because both are reading and writing the same backend state.

Closing one client does not mean the other client has moved to a new backend. Conversely, starting another opencode web or opencode serve creates another process unless you explicitly point clients to the already-running URL.

The web command’s startup, attach behavior, host options, and authentication guidance are covered in the web documentation.

How Desktop chooses its backend

Desktop’s default is different from the terminal-plus-web workflow. The troubleshooting documentation describes a local opencode-cli server sidecar running in the background. Desktop uses that sidecar unless its configuration selects a different server URL.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That means launching opencode web separately does not, by itself, make Desktop display the web server’s sessions. To make Desktop use a particular backend, inspect the app’s server selection or connection settings and set the URL of the intended server. The selected URL is the practical answer to “which service is Desktop using?”

If Desktop cannot connect, check the selected URL first, then verify that the server is running, listening on the expected host and port, and configured for any required password or network access. The documented Desktop behavior and connection troubleshooting are in OpenCode’s troubleshooting guide.

Desktop and a server running in WSL

On Windows, the web documentation recommends running the web command from Windows Subsystem for Linux (WSL) when you need Linux file-system access and terminal integration. Desktop can connect to a server running in WSL. If that WSL server binds to 0.0.0.0, protect it with a password before allowing the Desktop client or other network clients to connect.

Comparing common connection setups

Setup Server owner Client connection Shared state result Typical reach
Terminal only The opencode command TUI connects to its companion server One terminal client and its server Usually local
Headless service plus clients opencode serve Clients use the server URL Any clients pointed to that URL can share the backend Localhost by default for documented defaults; host can be configured
Web plus terminal opencode web Browser opens automatically; TUI uses opencode attach Shared sessions and state on the same server Browser on localhost by default; network exposure is optional
Desktop default Desktop’s local opencode-cli sidecar Desktop connects internally Desktop’s sidecar state, separate from an unrelated web process Usually local
Desktop with configured URL The server at the configured URL Desktop connects to that endpoint Shared with other clients using that same endpoint Local or network, depending on server binding

Localhost, network binding, and authentication

“Works on my computer” and “reachable from another device” are different configurations. The documented default for opencode serve is port 4096 on hostname 127.0.0.1. That loopback address accepts connections from the same machine, not from other machines on the network. The command can be configured with a different port or hostname, and the documentation also describes mDNS and allowed CORS origins.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

opencode web chooses an available port by default and binds to 127.0.0.1. You can assign a port or hostname. Binding to 0.0.0.0 makes the service reachable through the machine’s network interfaces, which changes the security requirement: the web guide warns that an exposed service without a password is unsecured.

Password protection

Set OPENCODE_SERVER_PASSWORD when network access requires protection. OpenCode documents HTTP Basic Authentication for this service. The default username is opencode; the documentation also provides an environment-variable setting to override that username if your deployment needs a different one.

Do not treat CORS as a substitute for authentication. CORS controls which browser origins may make cross-origin requests; it does not prove the identity of a user or protect a server exposed on a network. Use the documented password setting whenever the service is reachable beyond a trusted localhost-only workflow.

Safer exposure checklist

  • Keep the hostname at 127.0.0.1 when only local clients need access.
  • If another machine, Desktop instance, or WSL boundary must connect, choose the narrowest network binding that meets that need.
  • Set OPENCODE_SERVER_PASSWORD before binding to 0.0.0.0 or another non-loopback address.
  • Use CORS allow-list settings only for the browser origins you actually need; remember that they are not authentication.
  • Confirm the actual port and hostname in the running command’s output instead of assuming the defaults.

How to diagnose a client that shows the wrong sessions

When an interface appears empty or fails to find a session, the most likely cause is that it is connected to a different backend, not that the session was deleted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Check the server URL. Compare the host and port displayed by the client with the URL of the server where the session was created.
  2. Check who started the process. Determine whether the backend came from opencode, opencode serve, opencode web, or Desktop’s sidecar. Two commands started independently normally mean two server processes.
  3. Check Desktop’s selection. If Desktop is involved, inspect its configured server URL rather than assuming it uses a separately launched web process.
  4. Check reachability. A localhost URL may work in one environment but fail across a host/WSL boundary or from another device. Verify the server’s hostname and port.
  5. Check authentication. A server protected with OPENCODE_SERVER_PASSWORD requires the client to authenticate. A network-exposed server without that protection should be secured before further troubleshooting.
  6. Attach deliberately. For a terminal that should share the web instance, run opencode attach <server-url> against the web server’s actual URL rather than launching a new standalone TUI.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What “shared” does and does not guarantee

It does guarantee one backend when URLs match

When the browser and TUI attach to the same running server, they address the same session store and API process. This is the supported way to move between terminal and web views without creating a second context.

It does not merge independent servers

Starting a server from the TUI, starting another with opencode serve, and launching opencode web are not three views of one universal service. Unless clients are directed to one process, each service can have its own sessions and state.

It does not make Desktop’s default sidecar global

Desktop’s local sidecar is a default implementation detail for that installation. Other interfaces will not automatically discover or reuse it. Configure a server URL when Desktop must join a backend that another client already uses.

Version and documentation caveats

OpenCode’s documentation is maintained on a development branch, and command flags and defaults can change. The architectural rule—clients connect to a particular server—is stable enough to guide setup, but exact port selection, host defaults, authentication labels, and UI locations should be verified against the release installed on your machine.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In particular, keep serve and web distinct in your planning: serve is the headless API path, while web starts the browser interface as part of its workflow. If a current build presents different labels or defaults, use that build’s CLI help and settings while preserving the same URL-based mental model.

A practical decision rule

  • Need only a terminal? Run opencode and use its local server.
  • Need browser and terminal on one context? Run opencode web, then attach the TUI to the printed server URL.
  • Need a backend without a browser? Run opencode serve and point clients at its URL.
  • Need Desktop to share another client’s sessions? Configure Desktop to that server’s URL; do not rely on automatic discovery.
  • Need access from another machine or across WSL? Bind the server appropriately, set OPENCODE_SERVER_PASSWORD, and verify the exact URL and port.

The reliable mental model is simple: identify the server process, read its URL, and make every client that should share state connect to that URL. Different URLs mean different backends; the interface—terminal, browser, or Desktop—does not change that rule.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.