Use OpenCode V2 from Anywhere with Tailscale
Access OpenCode V2 from your phone or another computer using Tailscale Serve, HTTPS, and one-time pairing links without exposing it publicly.
- How Does It Work?
- What Do We Need?
- Configure the OpenCode Service
- Share It with Tailscale
- Connect from Another Device
- Something Isn't Working?
- Conclusions
You leave OpenCode running on your computer, go outside, and a few minutes later want to check how things are going. Do you really need to return to your desk?
The short answer is no. We can connect to the same OpenCode service from another computer or our phone without exposing it to the public internet.
In this article I'm going to show you how to do it using OpenCode V2 and Tailscale. A few commands, a pairing link, and we're ready.
How Does It Work?
OpenCode V2 uses a client-server architecture. What does this mean? The interface you interact with connects to a background service that manages sessions, permissions, integrations, and tool execution.
That service normally listens only on your computer. We need a way to reach it when we're somewhere else.
This is where Tailscale comes in. It connects your devices through a private network called a tailnet. With Tailscale Serve, we can make our local OpenCode service available through an HTTPS address inside that network.
The connection looks like this:
Phone or remote computer
|
| HTTPS over your tailnet
v
https://my-computer.my-tailnet.ts.net
|
| Tailscale Serve
v
http://127.0.0.1:4096
|
v
OpenCode service
The code and tools still run on the host computer. Your phone is a client, not a tiny replacement for your development machine 😉.
Important: Tailscale Serve shares a service within your tailnet. Tailscale Funnel exposes it to the public internet. For this tutorial we're using Serve, not Funnel.
What Do We Need?
Before starting, make sure you have:
- OpenCode V2 installed and configured on the computer where your projects live.
- Tailscale installed on that computer and your remote device.
- Both devices connected to the same tailnet.
- Permission under your tailnet's access rules to reach the host.
Your devices don't need to use the same Wi-Fi network. That's the point! Your computer can be at home while your phone uses mobile data.
The host does need to remain powered on, awake, and connected to the internet. Tailscale can connect devices, but it can't convince a sleeping laptop to write code.
Configure the OpenCode Service
On the computer where OpenCode will run, execute:
opencode service set password 'replace-this-with-a-long-unique-password'
opencode service set hostname 127.0.0.1
opencode service set port 4096
opencode service set remote false
opencode service start
Let's see what each command does:
passwordreplaces the generated service password with one you choose. Use a strong, unique password, not the example.hostname 127.0.0.1keeps OpenCode listening on localhost. Tailscale Serve will handle remote connections.port 4096gives us a fixed port to forward.remote falsedisables OpenCode's built-in OpenTunnel remote access if it was previously enabled. We don't need it for this setup.startstarts the background service.
Note that 4096 is the port we're choosing for this tutorial, not OpenCode V2's default port.
Changing service settings stops the background service, which is why we start it after finishing the configuration.
The password command contains a secret. Be mindful of shell history, terminal recordings, and screenshots.
Now check the address:
opencode service status
It should report:
http://127.0.0.1:4096
We already have OpenCode running locally. Now let's make it reachable from our other devices.
Share It with Tailscale
On the same computer, execute:
tailscale serve --bg 4096
With this command:
4096identifies the local service Tailscale should forward requests to.--bgkeeps the Serve configuration active in the background.
If HTTPS isn't enabled for your tailnet, Tailscale will provide a setup URL. Follow the instructions to enable it.
Once configured, check the result:
tailscale serve status
You'll see something similar to this:
https://my-computer.my-tailnet.ts.net (tailnet only)
|-- / proxy http://127.0.0.1:4096
Copy the HTTPS address shown by your command. The hostname above is only an example.
Tailscale handles the HTTPS certificate and forwards requests to OpenCode on localhost. We don't need to change OpenCode's listening address to 0.0.0.0 or open a port on the router.
And no, having an HTTPS address doesn't make this a public website. Access still goes through Tailscale and your tailnet's access rules.
Connect from Another Device
We have the service and the network connection. What's missing? Pairing the client!
On the host computer, generate a link using the HTTPS address from the previous step:
opencode pair --url https://my-computer.my-tailnet.ts.net
OpenCode prints a pairing link and a QR code.
The --url option tells OpenCode which external address to put in the link. It doesn't create a tunnel or publish the service itself; that's what we configured with Tailscale Serve.
From Your Phone
- Connect your phone to Tailscale.
- Open the OpenCode app.
- Scan the QR code, or paste the complete pairing link into the app's server address field.
You can also open the generated link in a browser on a device connected to your tailnet.
The pairing link authenticates the client. You don't necessarily need to enter the service password again when using it.
There are two details you shouldn't miss:
- Pairing links expire after five minutes.
- Each link works only once.
If you open a link in your browser and then try to reuse it in the app, generate another one. The same applies when pairing a second device.
Treat the link like a temporary credential. Don't publish it in screenshots or paste it into a public chat.
Done! You can now interact with the OpenCode service on your host computer from your remote device.
To verify that you're really connecting from outside your home network, turn off your phone's Wi-Fi, leave Tailscale connected, and try using mobile data.
Something Isn't Working?
Before changing random settings, let's check the basics.
The HTTPS Address Doesn't Open
Confirm that Tailscale is connected on both devices and that you're using the exact hostname from:
tailscale serve status
If your tailnet has restrictive access rules, they must allow the remote device to reach the host's Serve endpoint, normally on HTTPS port 443.
Tailscale Connects, but OpenCode Doesn't Respond
On the host, check the service:
opencode service status
opencode api get /api/info
Also confirm that Tailscale is forwarding to the same port OpenCode uses. If one says 4096 and the other says something else, we've found the problem.
The Pairing Link Fails
Generate a fresh one:
opencode pair --url https://my-computer.my-tailnet.ts.net
Remember: five minutes and one use. Also make sure you copied the full link, not just the hostname.
It Worked Until You Closed the Laptop
Check whether the host went to sleep. The background service and Tailscale Serve don't prevent the operating system from suspending the computer.
For regular remote use, an always-on machine is usually more practical.
Conclusions
As you can see, accessing OpenCode remotely doesn't require exposing your development environment to the entire internet.
OpenCode runs on your computer, Tailscale provides private connectivity, and the pairing link connects your client. Keep the host awake, protect your credentials, and review permissions carefully: you're connecting to a coding agent that can execute tools, not just a page that displays text.
For more information, see the official documentation for OpenCode's web interface, pairing commands, and Tailscale Serve.