Repository navigation
Description
Desktop-spawned background service ignores env from service config (opencode service set env)
Description
The desktop app spawns the shared background service itself, but unlike the CLI it does not apply the env configured via opencode service set env (stored in ~/.config/opencode/service.json). The spawned opencode-cli serve --service runs with a sanitized environment — it even injects its own NO_PROXY=127.0.0.1,localhost,::1 — so setups that require a proxy for provider traffic (e.g. OpenCode Zen behind a local proxy) break whenever the service is started by the desktop app.
Two behaviors observed on macOS:
- When no service is running, desktop spawns
.../ai.opencode.desktop/cli/2.0.28-arm64/opencode-cli serve --servicewithout the proxy env from service.json. The same service spawned via the CLI (opencode service start) does get that env. - When a service is already running with correct env, desktop kills and replaces it with its own env-less instance if the running version differs from its bundled CLI version. So keeping a correctly configured service alive requires CLI and desktop versions to match exactly.
Steps to reproduce
- Configure proxy env for the shared service:
opencode service set env http_proxy http://127.0.0.1:13659
opencode service set env https_proxy http://127.0.0.1:13659
opencode service set env NO_PROXY localhost,127.0.0.1,::1
-
Kill all opencode processes:
pkill -f opencode -
Start OpenCode Desktop. It spawns the service itself:
$ pgrep -fl 'serve --service'
/Users/me/Library/Application Support/ai.opencode.desktop/cli/2.0.28-arm64/opencode-cli serve --service
$ ps eww <pid> | tr ' ' '\n' | grep -i proxy
NO_PROXY=127.0.0.1,localhost,::1
no_proxy=127.0.0.1,localhost,::1
http_proxy/https_proxy from service.json are missing → provider requests (OpenCode Zen) bypass the proxy and fail.
- Comparison: kill everything and run
opencode service startinstead — the service process has the full proxy env from service.json.
Workaround
Keep the CLI at the exact same version as the desktop's bundled CLI, start the service from the CLI first (opencode service start), then launch desktop — it reuses the running service. If versions differ, desktop replaces it with an env-less instance. opencode service restart from the CLI restores a correct service and the running desktop reconnects to it automatically.
Suggested fix
When desktop spawns serve --service, apply the env map from the service configuration (~/.config/opencode/service.json), same as the CLI's opencode service start code path.
Environment
- OpenCode version: CLI 2.0.28, Desktop 2.0.28 (also reproduced with CLI 2.0.27 + Desktop 2.0.28)
- OS: macOS 15.2 (Apple silicon)
- Plugins: none
Activity
opencode-agent commentedon Oct 14, 2026
Thanks for the detailed report and the workaround. I think this is a duplicate of #50882. That issue has the same root cause: the Desktop app starts
opencode-cli serve --serviceitself and skips the step where the CLI applies theenvfromservice.json, so variables set withopencode service set envnever reach the service. #50882 was reported through MCP servers (and a comment there covers provider API keys), but your missinghttp_proxy/https_proxycome from the same gap. Desktop replacing a service with a different version is expected; it only causes trouble here because the new service starts without that env.Possible duplicates and related issues, ordered by likelihood:
serve --servicestarts)service set envvalue not present in the running server, possibly the same Desktop-launched serviceHTTPS_PROXYnot respected in v2The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.
believening commentedon Oct 14, 2026
The root cause does match #50882 (Desktop starting
serve --servicedirectly, skipping the CLI's env injection step), so closing this as a duplicate is fine by me. One note to make sure the fix also covers this report's symptom:Unlike the MCP
{env:...}and provider-key cases, what broke for us is the service process's own outbound HTTP:http_proxy/https_proxy/NO_PROXYfromservice.jsonneed to land in the service process env before the outbound HTTP client is constructed, so provider traffic (OpenCode Zen here) is routed through the proxy. PR #50907 loads the saved env before importing the server, which sounds like it would cover this — but it may be worth adding a regression test for process-level proxy vars (e.g. a Desktop-startedserve --serviceroutes provider requests throughhttp_proxyfrom service.json), not just config substitution and MCP child processes.Will track #50882 / #50907 from here. Thanks!
opencode-agent commentedon Oct 14, 2026
Thanks for confirming, and for the note on proxies. You're right that your case is a bit different from the MCP
{env:...}and API-key cases: the service's own outbound requests (OpenCode Zen here) needhttp_proxy/https_proxy/NO_PROXYto be in the service's environment.PR #50907 loads the saved
service.jsonenv whenserve --servicestarts, before the server is imported, so the proxy variables should be in place for those requests. I haven't tested this, though, and as far as I can tell the PR's tests cover config substitution, MCP child processes and provider API keys, but not proxy routing. A test where a Desktop-started service sends provider requests throughhttp_proxyfromservice.jsonwould cover your case. Commenting on #50907 is the best way to get that in front of the PR author and maintainers.This issue stays a duplicate of #50882, and the bot will close it as planned.
opencode-agent commentedon Oct 15, 2026
Closing this as a duplicate of #50882, as you agreed. Both come from the Desktop app starting
serve --servicewithout the env saved inservice.json. Please follow #50882 for the fix, and open PR #50907 for the change itself; that PR is also the place to ask for a test that the saved proxy settings work. Thanks again for the clear report and the workaround.