macOS Local Network Privacy blocks the background service from LAN hosts; fix by shipping a signed .app bundle
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.app
Keep 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
- #25908: desktop app cannot reach LAN IPs,
EHOSTUNREACH. Closed by the stale bot; still reported on 1.18.16. - #38854: cannot reach LAN-hosted Ollama on macOS. Closed in the 2.0 triage; still reported on 2.0.18.
- #37432: embedded Bun gets
ECONNREFUSEDto LAN gateway IPs. Closed by the stale bot. - #28418, #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.
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 runs serve --service) with opencode --standalone, using a provider baseURL or 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:
- #38854: LAN-hosted Ollama unreachable while curl works. Comments there say it also happens on 2.0.4 and 2.0.18 with the background service.
- #51513: the same symptom on 2.0.18.
- #37432, #28418, #25908, #33758: earlier reports of the same failure on v1.
Until this is looked at, the workarounds you listed still apply: --standalone from Terminal, an SSH loopback forward, a VPN address, or the TN3179 subnet exemption.
I traced the current dev service startup and found one distinction that matters for choosing the fix: ServiceConfig.options passes serve --service to spawnServiceContender, which uses detached child-process spawning and unref(). It does not install or start a LaunchAgent through launchctl. 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.
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 AllowedEthernetLocalNetworkAddresses commands randomly (set multiple reboots ago, values still present, restart terminal/herdr/opencode). leaving ssh sessions tunnels open as a workaround is pretty ridiculous
Your bundle experiment is useful evidence, but it changes both app identity and launch mechanism. [TN3179](https://developer.apple.com/documentation/technotes/tn3179-understanding-local-network-privacy) 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](https://github.com/anomalyco/opencode/blob/f7d5b6ffc48223e654b20043a500d315e4bc8053/.github/workflows/publish.yml#L139-L180), 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.
So, orginally I only ran opencode in the terminal. I use usually iTerm2, sometimes Ghostty and for troubleshooting purposes Terminal.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, a curl performed by the agent would fail, whereas running the /exit command and then curl in the same terminal succeeds. That's what put me on the direction that the opencode would be using launchctl.
So, to answer your question, it is definitely happening when I run opencode in the terminal.
I encountered this with the macOS desktop app on v2.2.4 when connecting to a self-hosted OpenCode server on my LAN.
Symptoms:
- The desktop app showed “Could not connect to server.”
- The same server and credentials worked in the browser and on another Mac.
curlon the affected Mac successfully connected, validated the TLS certificate, and returned HTTP 200.- OpenCode was missing from System Settings → Privacy & Security → Local Network on the affected Mac. It was listed on the working Mac.
- Connecting through WireGuard worked, but did not create a Local Network permission entry.
What fixed it for me:
- Downgrade the desktop app to v1.
- Try to connect to local network to trigger the permission request
- Then upgrade back to v2.2.4. 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.
I have a similar symptom but the log shows macOS is not blocking OpenCode here.
On macOS 15.8.2 / OpenCode 2.2.5, the unified log repeatedly prints:
nehelper: [com.apple.networkextension:] Local network allowed by preference for OpenCode (ai.opencode.desktop)
And I see no deny network* or Local Network violations for any opencode process.
The pattern I get is specifically tied to the stale background service:
- First launch after boot: works fine, reaches
192.168.31.82:8788. - After quitting (fully exiting, not minimizing): the next launch fails with
EHOSTUNREACH: Was there a typo in the url or port?. - Running
opencode service stoporpkill -9 -f opencodebefore launching: works again.
I tested both clients:
- TUI (terminal): same pattern.
- Desktop app: same pattern.
Other things that do not fix it:
- Disabling Clash Verge completely.
- Forcing
NO_PROXYwith the LAN subnet.
So in my case the OS is allowing LAN access, and the first launch works. The failure appears only when a leftover serve --service process from the previous session is still running. Killing it restores functionality.
Is this related to the bundle/signing fix here, or is it a separate issue where the reused serve --service process fails to handle LAN connections after the client reconnects?
Reproduced on macOS 27.2.1 (26B131), OpenCode Desktop 2.4.1 (Apple Silicon), with an OpenAI-compatible provider baseURL at http://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.- The server is
~/Library/Application Support/ai.opencode.desktop/cli/2.4.1-arm64/opencode-cli serve --service, reparented to PID 1. - OpenCode never appears in System Settings → Privacy & Security → Local Network, and no prompt is ever shown.
/Applications/OpenCode.app/Contents/Info.plisthas noNSLocalNetworkUsageDescription. - Quitting the desktop app leaves the service running. Killing it so a fresh service is spawned by the relaunched app does not help, so this isn't the stale-service case described above.
- Router (
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 add NSLocalNetworkUsageDescription. Until then, please report a Local Network denial as such rather than "check the network connection / typo in the url".
Additional reproduction: restarting the service from a terminal restores LAN access
Adding a data point relevant to the responsible-process attribution question.
- opencode: v2.4.2,
~/.opencode/bin/opencode serve --service - OS: macOS 27.2.1 (Darwin 27.2.0, arm64), zsh, TERM_PROGRAM=rex
- Provider: custom OpenAI-compatible,
baseURL: http://192.168.31.133:40040/v1 - While the old service was failing:
/usr/bin/curl http://192.168.31.133:40040/v1/modelsfrom the same machine returned 200.- A new session through the shared service still failed with
EHOSTUNREACH/ "Was there a typo in the url or port?" opencode --standalonefrom the terminal worked.opencode api get /api/providershowed the correctbaseURL.
- The failing service had
PPID 1. - After
opencode service restartfrom the terminal, the new service hadPPID 5187(not 1) and the same config worked. - OpenCode never appeared in System Settings → Privacy & Security → Local Network.
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.
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://
- The same server works from Chrome on the same Mac, from
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.- Workaround: an SSH tunnel to
127.0.0.1on the Mac, or the web UI in a browser.
So the missing NSLocalNetworkUsageDescription also blocks the desktop app itself from reaching LAN OpenCode servers, not only the spawned service. Adding it to the macOS Info.plist (electron-builder mac.extendInfo) is needed in addition to the UUID and bundle-identity fixes discussed here.
Related macOS 27 issue: empty ARP table even in standalone mode
I would like to add a potentially related but distinct reproduction.
Environment:
- macOS 27.x
- Apple Silicon
- OpenCode 2.4.2
- Installed via Homebrew
Observed behavior:
/usr/sbin/arp -anreturns numerous entries in the normal macOS Terminal.- The same command returns an empty ARP table when executed through OpenCode.
opencode --standalonedoes not resolve the issue.- The macOS Local Network permission dialog does not allow selecting the OpenCode CLI binary.
Code signing information:
- Valid Developer ID Application signature: Anomaly Innovations, Inc.
- Hardened Runtime enabled.
Info.plist=not bound
Potential cause:
The OpenCode executable does not have the following entitlement:
com.apple.developer.networking.topology-observation
Unlike 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!