Repository navigation
Description
Description
On macOS 15+, the OpenCode background service cannot open TCP connections to LAN addresses (192.168.x.x, 10.x.x.x). The connect fails before any HTTP status is returned, surfacing as EHOSTUNREACH / FailedToOpenSocket and the generic message Cannot connect to API: Was there a typo in the url or port?. Apple-signed clients on the same machine (/usr/bin/curl, /usr/bin/ssh) reach the same host:port at the same moment.
The cause is macOS Local Network Privacy (LNP), described in Apple's TN3179. It is not DNS, not provider configuration, and not a bug in Bun's networking.
Two things combine:
-
LNP gates outgoing TCP/UDP to local-network addresses and only allows programs whose identity macOS can establish. It is not TCC: there is no
tccutilequivalent, MDM cannot configure it, and a program with no bundle identity never gets a prompt and never appears in System Settings > Privacy & Security > Local Network. The denial happens in the network stack, so users only seeEHOSTUNREACH. -
opencodestarts a persistent server throughlaunchctland it gets reparented to PID 1:PID 25455 PPID 1 /opt/homebrew/bin/opencode serve --serviceTN3179 exempts command-line tools run from Terminal or SSH, including their children. After reparenting, the service is no longer a child of the terminal and is not a launchd daemon either, so neither exemption applies. The TUI you type into is only a client of
127.0.0.1:49374; the provider and MCP sockets are opened by the detached service.
The shipped binary also has no bundle to attribute: codesign reports Identifier=opencode and a valid Developer ID, but spctl says the code is valid but does not seem to be an app. A bare Mach-O has no CFBundleIdentifier and no NSLocalNetworkUsageDescription, so macOS has nothing to show in an alert and no identity to store a decision against.
The practical result is that the same config works and fails depending on how OpenCode was started:
| Context | LAN access |
|---|---|
opencode --standalone from Terminal.app |
works |
opencode default (serve --service, PPID 1) |
denied |
That difference is the whole bug. It also explains why the failure looks like a runtime networking problem: the denial is applied per process, so every socket from that process fails, whichever HTTP client or model runtime opens it.
Reproduction
- On macOS 26.x, configure a remote MCP server or a provider
baseURLpointing at a LAN host, e.g.http://192.168.1.47:8000/mcp. - Confirm the host is reachable:
curl http://192.168.1.47:8000/healthreturns 200. - Run
opencodenormally and invoke the provider/MCP. It fails withFailedToOpenSocket/EHOSTUNREACH. - Run
opencode --standalonefrom Terminal.app with the same config. It connects.
Environment used for the report: macOS 26.7.1 (25G241), OpenCode 2.1.2, remote MCP over plain HTTP on the LAN, no VPN in the failing path.
Proposed fix: ship a minimal signed .app bundle
Give the service a bundle identity and let launchd associate the job with it.
OpenCode.app/
Contents/
Info.plist
MacOS/opencode # the existing CLI binary
Resources/
Contents/Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key> <string>ai.opencode.cli</string>
<key>CFBundleExecutable</key> <string>opencode</string>
<key>CFBundleName</key> <string>OpenCode</string>
<key>CFBundlePackageType</key> <string>APPL</string>
<key>CFBundleShortVersionString</key> <string>2.1.2</string>
<key>CFBundleVersion</key> <string>2.1.2</string>
<key>LSBackgroundOnly</key> <true/>
<key>NSLocalNetworkUsageDescription</key>
<string>OpenCode connects to model servers, MCP servers, and other services on your local network.</string>
</dict>
</plist>The service registration must point inside the bundle and associate the job with the bundle ID. Two options:
SMAppService (macOS 13+), with the agent plist at Contents/Library/LaunchAgents/<label>.plist. This is the supported path and registers the association automatically.
Plain LaunchAgent, with the association declared explicitly:
<key>ProgramArguments</key>
<array>
<string>/Applications/OpenCode.app/Contents/MacOS/opencode</string>
<string>serve</string>
<string>--service</string>
</array>
<key>AssociatedBundleIdentifiers</key>
<array>
<string>ai.opencode.cli</string>
</array>Sign the assembled bundle, not just the executable, so the Info.plist is covered by the signature:
codesign --force --options runtime --timestamp \
--sign "Developer ID Application: Anomaly Innovations, Inc. (5NZ4Q7NXJ4)" \
OpenCode.appKeep the bundle identifier and team stable across releases. The LNP decision is keyed to the designated requirement, so a stable Developer ID signature means the user approves once and keeps the grant through updates.
The desktop app needs the same treatment: NSLocalNetworkUsageDescription in its Info.plist, and the CLI sidecar spawned from inside the bundle so it inherits the app's identity rather than running as an unrelated bare binary.
Why this has to ship upstream
Adding bundle metadata to an already-signed binary breaks its signature:
codesign --verify --deep --strict OpenCode.app
code has no resources but signature indicates they must be present
A user-side wrapper therefore has to be re-signed, and ad-hoc signing replaces the Developer ID with a cdhash-based designated requirement. That requirement changes with every build, so the grant is lost on update and the user is denied again with no prompt. Only you can ship a wrapper that keeps the existing Developer ID identity.
Verification on a real machine
I tested the mechanism locally before filing this. A minimal .app containing a copy of the 2.1.2 binary, ad-hoc signed, with CFBundleIdentifier and NSLocalNetworkUsageDescription, launched by a LaunchAgent carrying AssociatedBundleIdentifiers:
- First LAN connect failed with
errno=65twice, then macOS presented the local network prompt. - After Allow, the same binary connected, and the LAN MCP endpoint worked with no SSH tunnel and no
HTTP_PROXY. - The grant survived a restart of the service and a reboot.
The same service at PPID 1 without the bundle was denied every time. So the mechanism is confirmed on macOS 26.7.1; the missing piece upstream is only that it must be signed with your Developer ID to be durable.
Workarounds until this ships
-
opencode --standalonefrom Terminal.app or over SSH. The server stays a child of the terminal, so the exemption applies. Sessions do not persist after the terminal closes. -
Point at a VPN address instead of a LAN address. LNP covers broadcast-capable interfaces (Wi-Fi, Ethernet) and does not gate tunnelled traffic, so a Tailscale or WireGuard address works.
-
Loopback forward, e.g.
ssh -N -L 127.0.0.1:8000:127.0.0.1:8000 user@host. Traffic stays on the LAN and/usr/bin/sshis Apple-signed. -
Admin-level subnet exemption, documented in TN3179 since macOS 15.5. It is machine-wide, not per-app, and requires a reboot:
sudo defaults write com.apple.network.local-network AllowedEthernetLocalNetworkAddresses -array "192.168.1.0/24" sudo defaults write com.apple.network.local-network AllowedWiFiLocalNetworkAddresses -array "192.168.1.0/24" sudo reboot
Related issues
- Desktop app cannot reach LAN IP addresses - EHOSTUNREACH on all
192.168.x.xconnections #25908: desktop app cannot reach LAN IPs,EHOSTUNREACH. Closed by the stale bot; still reported on 1.18.16. - OpenCode cannot connect to LAN-hosted Ollama on macOS while curl works #38854: cannot reach LAN-hosted Ollama on macOS. Closed in the 2.0 triage; still reported on 2.0.18.
- macOS: Bun runtime gets ECONNREFUSED to LAN gateway IPs (custom provider baseURL) while Node/curl work; HTTP_PROXY works around it #37432: embedded Bun gets
ECONNREFUSEDto LAN gateway IPs. Closed by the stale bot. - @ai-sdk/openai-compatible provider fails to connect to LAN addresses — FailedToOpenSocket errno:0 #28418, macOS: EHOSTUNREACH / FailedToOpenSocket when VPN Network Extension leaves orphaned virtual interfaces #26807: earlier reports of the same failure.
Acceptance criteria
- On a clean macOS profile, the first LAN connection from the background service prompts, and the prompt is attributed to OpenCode.
- After Allow, a provider
baseURL, a remote MCP server, and a child process spawned by a tool can each reach an RFC1918 host with no tunnel and no proxy environment variable. - After Don't Allow, the error says local network permission is required instead of suggesting the URL or port is wrong.
- The grant survives a service restart, a reboot, and an OpenCode update.
- Loopback and public-internet traffic are unaffected in both cases.
Activity
opencode-agent commentedon Oct 22, 2026
Thanks for the detailed report and for testing the bundle approach locally. I couldn't reproduce this here: the problem depends on macOS Local Network Privacy, and the test environment I have is Linux, which has nothing similar. A maintainer with a Mac will need to check it, by comparing the default
opencode(which runsserve --service) withopencode --standalone, using a providerbaseURLor remote MCP server on a LAN host.The code does match what you describe. The background service is started as a separate process with no link back to the terminal, so it ends up with parent PID 1. OpenCode also ships no macOS bundle metadata (
NSLocalNetworkUsageDescription,AssociatedBundleIdentifiers), so there is nothing for macOS to show a prompt for.Related reports, most relevant first:
192.168.x.xconnections #25908, Desktop app cannot reach local network Ollama/LLM servers (Electron network sandbox) #33758: earlier reports of the same failure on v1.Until this is looked at, the workarounds you listed still apply:
--standalonefrom Terminal, an SSH loopback forward, a VPN address, or the TN3179 subnet exemption.Dante-dan commentedon Oct 22, 2026
I traced the current
devservice startup and found one distinction that matters for choosing the fix:ServiceConfig.optionspassesserve --servicetospawnServiceContender, which uses detached child-process spawning andunref(). It does not install or start a LaunchAgent throughlaunchctl. PPID 1 alone therefore doesn't establish which code macOS holds responsible for the network access.Your bundle experiment is useful evidence, but it changes both app identity and launch mechanism. TN3179 describes responsible-code attribution, but does not provide a direct query for it. The missing observable details are whether the failing service was originally spawned by Terminal, the desktop app, or an existing user LaunchAgent; whether Local Network settings show an entry and its name; and whether allowing that entry changes the same service’s next connection attempt. Could you share whichever of those are available? The existing standalone result and Developer ID verification don't need repeating. The release workflow already signs the macOS CLI with Developer ID, so this needs to distinguish attribution from executable signing.
That would let us target the current startup path, or propose an associated app/helper lifecycle with an explicit CLI-versus-desktop design. I have only checked the source paths; I haven't reproduced the LAN failure or verified a packaging fix.
professoruss commentedon Oct 24, 2026
This has been driving me insane since I started using opencode-cli. it even seems as if sometimes macOS ignores the
sudo defaults write com.apple.network.local-network AllowedEthernetLocalNetworkAddressescommands randomly (set multiple reboots ago, values still present, restart terminal/herdr/opencode). leaving ssh sessions tunnels open as a workaround is pretty ridiculousbelgaied2 commentedon Oct 27, 2026
So, orginally I only ran
opencodein the terminal. I use usually iTerm2, sometimesGhosttyand for troubleshooting purposesTerminal.app(the original MacOS terminal app, because it is signed by Apple and wouldn't need any changes to privacy settings). When the agent requests resources from the local network, it fails as if a firewall was in place. Also, acurlperformed by the agent would fail, whereas running the/exitcommand and then curl in the same terminal succeeds. That's what put me on the direction that theopencodewould be usinglaunchctl.So, to answer your question, it is definitely happening when I run
opencodein the terminal.vjm commentedon Oct 30, 2026
I encountered this with the macOS desktop app on v2.2.4 when connecting to a self-hosted OpenCode server on my LAN.
Symptoms:
curlon the affected Mac successfully connected, validated the TLS certificate, and returned HTTP 200.What fixed it for me:
Afterward, OpenCode appeared in the Local Network permission list, and direct LAN access worked with WireGuard disconnected, including after fully quitting and reopening OpenCode.
I can’t confirm which step established the permission or changed the app attribution, but the downgrade/upgrade sequence resolved it on this machine.
guruchill commentedon Nov 23, 2026
Reproduced on macOS 27.2.1 (26B131), OpenCode Desktop 2.4.1 (Apple Silicon), with an OpenAI-compatible provider
baseURLathttp://192.168.1.190:8080/v1./usr/bin/curlfrom the same machine returns 200. The provider fails withEHOSTUNREACHand retries indefinitely (Attempt 4 – retrying in 6s).webfetchand the in-app browser also fail for the same LAN host.~/Library/Application Support/ai.opencode.desktop/cli/2.4.1-arm64/opencode-cli serve --service, reparented to PID 1./Applications/OpenCode.app/Contents/Info.plisthas noNSLocalNetworkUsageDescription.192.168.1.1) and internet traffic are unaffected.The available workarounds are a machine-wide subnet exemption, a tunnel, or giving up the desktop app for
--standalone. None of these is acceptable for a desktop app, which should be able to ask for Local Network permission like any other Mac app. Please give the service a bundle identity the desktop app's permission covers, and addNSLocalNetworkUsageDescription. Until then, please report a Local Network denial as such rather than "check the network connection / typo in the url".sumkire commentedon Nov 26, 2026
Additional reproduction: restarting the service from a terminal restores LAN access
Adding a data point relevant to the responsible-process attribution question.
~/.opencode/bin/opencode serve --servicebaseURL: http://192.168.31.133:40040/v1/usr/bin/curl http://192.168.31.133:40040/v1/modelsfrom the same machine returned 200.EHOSTUNREACH/ "Was there a typo in the url or port?"opencode --standalonefrom the terminal worked.opencode api get /api/providershowed the correctbaseURL.PPID 1.opencode service restartfrom the terminal, the new service hadPPID 5187(not 1) and the same config worked.opencode.logcontained 0EHOSTUNREACHlines at INFO level.This distinguishes a fresh service started from a terminal (LAN access works) from the detached/reparented service (LAN access fails), which points to Local Network Privacy attribution rather than provider or URL configuration.
jabbas commentedon Nov 27, 2026
Another data point from the desktop app's own connection path, not the background service. Desktop 2.4.1 (also 2.3.2), macOS 26, adding an OpenCode server on another LAN machine via "Add server" (pairing link or password) fails with "Can't connect to http://:4096. Check that this device can access the server, and try again."
opencode --server http://<host>:4096, fromcurl, and from the Android app. CORS is fine, and app and server are on the same version.tccutil reset All ai.opencode.desktopplus a full restart does not bring up a Local Network prompt. OpenCode is not listed under Privacy & Security → Local Network.OpenCode.app/Contents/Info.plist(2.4.1) hasNSAppTransportSecurity/NSAllowsLocalNetworking, but noNSLocalNetworkUsageDescriptionand noNSBonjourServices.127.0.0.1on the Mac, or the web UI in a browser.So the missing
NSLocalNetworkUsageDescriptionalso blocks the desktop app itself from reaching LAN OpenCode servers, not only the spawned service. Adding it to the macOS Info.plist (electron-buildermac.extendInfo) is needed in addition to the UUID and bundle-identity fixes discussed here.liftoff1968 commentedon Nov 28, 2026
Related macOS 27 issue: empty ARP table even in standalone mode
I would like to add a potentially related but distinct reproduction.
Environment:
Observed behavior:
/usr/sbin/arp -anreturns numerous entries in the normal macOS Terminal.opencode --standalonedoes not resolve the issue.Code signing information:
Info.plist=not boundPotential cause:
The OpenCode executable does not have the following entitlement:
com.apple.developer.networking.topology-observationUnlike the LAN connectivity problem described in this issue, the ARP-table problem persists in standalone mode.
This may be related to the network topology observation restrictions introduced in macOS 27 rather than ordinary Local Network Privacy.
Could the maintainers investigate whether this entitlement is required for network diagnostic commands executed by OpenCode?
Should this be tracked as a separate issue?
Thanks!