Skip to content

Desktop-spawned background service ignores env from service config (opencode service set env) #55290

Closed as duplicate

Description

@believening

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:

  1. When no service is running, desktop spawns .../ai.opencode.desktop/cli/2.0.28-arm64/opencode-cli serve --service without the proxy env from service.json. The same service spawned via the CLI (opencode service start) does get that env.
  2. 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

  1. 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
  1. Kill all opencode processes: pkill -f opencode

  2. 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.

  1. Comparison: kill everything and run opencode service start instead — 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

  1. opencode-agent commented on Oct 14, 2026

    @opencode-agent
    Contributor

    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 --service itself and skips the step where the CLI applies the env from service.json, so variables set with opencode service set env never reach the service. #50882 was reported through MCP servers (and a comment there covers provider API keys), but your missing http_proxy/https_proxy come 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:

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. believening commented on Oct 14, 2026

    @believening
    Author

    The root cause does match #50882 (Desktop starting serve --service directly, 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_PROXY from service.json need 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-started serve --service routes provider requests through http_proxy from service.json), not just config substitution and MCP child processes.

    Will track #50882 / #50907 from here. Thanks!

  3. opencode-agent commented on Oct 14, 2026

    @opencode-agent
    Contributor

    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) need http_proxy/https_proxy/NO_PROXY to be in the service's environment.

    PR #50907 loads the saved service.json env when serve --service starts, 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 through http_proxy from service.json would 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.

  4. opencode-agent commented on Oct 15, 2026

    @opencode-agent
    Contributor

    Closing this as a duplicate of #50882, as you agreed. Both come from the Desktop app starting serve --service without the env saved in service.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions