HTTPS_PROXY env not working in v2, but works in v1
Description
HTTPS_PROXY env not working in v2, but works in v1
Plugins
No response
OpenCode version
v2.0.12
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
I can reproduce a concrete v2 breakage here. With HTTPS_PROXY set and no NO_PROXY, localhost TUI-to-service API calls are sent through the proxy and fail (verified locally with a fake proxy: proxied 502 without the bypass, direct 200 with NO_PROXY=localhost,127.0.0.1). The v2 SDK client uses global fetch so proxy env applies to local calls, and unlike desktop (which upserts loopback into NO_PROXY at startup in packages/desktop/src/main/sidecar.ts), the CLI has no equivalent — v1 was immune because its TUI used an in-process transport. I'd like to work on this: plan is porting the loopback NO_PROXY upsert to CLI startup with a unit test.
Update: opened #52951 with a fix for one concrete failure mode — with HTTPS_PROXY set and no NO_PROXY, localhost TUI-to-service calls get routed through the proxy and fail. I verified this locally with a fake proxy (proxied 502 without the bypass, direct 200 with it). The change ports desktop's loopback NO_PROXY upsert to CLI startup.
One small caveat: your report has no repro details, so I can't confirm this matches what you hit. If your symptom was provider-egress traffic failing rather than the local API, that's a separate path — could you share your OS, what exactly failed, and whether NO_PROXY=localhost,127.0.0.1 changes anything on your end? This is unlikely tho.
Confirming the provider-egress path you asked about — NO_PROXY does not change anything here.
- OpenCode v2.0.26 (Bun 1.4.2), Debian 13.
- Network: the provider host is only reachable through an HTTP proxy (
192.168.1.83:1080). Direct requests toopenrouter.aiare answered by the network filter with403 Access denied by security policy. - v1 with the same env works; v2 fails on every
openrouter/<model>call.
Minimal repro — the dead-proxy case shows the variable is never read (no "connection refused"):
# A: real proxy
HTTPS_PROXY=http://192.168.1.83:1080 HTTP_PROXY=http://192.168.1.83:1080 \
opencode run --model openrouter/deepseek/deepseek-v4.1-flash "ping"
Error: Access denied by security policy.
# B: DEAD proxy (127.0.0.1:9) — same 403, not a connect error
HTTPS_PROXY=http://127.0.0.1:9 HTTP_PROXY=http://127.0.0.1:9 \
opencode run --model openrouter/deepseek/deepseek-v4.1-flash "ping"
Error: Access denied by security policy.
# C: no proxy at all — identical
opencode run --model openrouter/deepseek/deepseek-v4.1-flash "ping"
Error: Access denied by security policy.
NO_PROXY=localhost,127.0.0.1,::1 makes no difference (the failing host is openrouter.ai, not loopback). strace -f -e trace=connect confirms a direct :443 connection to the provider IP.
Control: Bun's own fetch in the same shell does honor the env (dead proxy → connect error), so the runtime reads it — the v2 provider request path just doesn't use it:
HTTPS_PROXY=http://127.0.0.1:9 bun -e 'await fetch("https://openrouter.ai/api/v1/models")'
# Unable to connect. Is the computer able to access the url?
Workaround in use: providers.openrouter.settings.baseURL points at a local loopback relay that performs the CONNECT to the upstream proxy. Works, but every user behind a proxy would need it.
This looks separate from the loopback/NO_PROXY fix in #52951 — it's outbound provider traffic being dialed directly.
Thanks for the report, @zaaack! The docs say OpenCode respects HTTPS_PROXY/HTTP_PROXY, so this should work in v2. To reproduce it, could you share:
- What goes wrong: which requests skip the proxy (model/provider requests,
opencode auth login, loading the model list, something else), and the provider and model you use. - The exact error or behaviour you see, e.g. a timeout, connection refused or a TLS error. Logs help too: running with
--print-logs --log-level DEBUGshould show them. - Your proxy setup: the values of
HTTPS_PROXY/HTTP_PROXY/NO_PROXYwith any credentials removed, especially whether the proxy URL starts withhttp://orhttps://and whether it needs authentication. - Your OS and how you installed OpenCode (npm
@opencode/cli, install script, Homebrew, etc.).
You can reply here with the details or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know you're done.
We haven't heard back, so I'm closing this for now. To look into HTTPS_PROXY being ignored in v2, we'd need to know:
- which requests skip the proxy
- the exact error
- your proxy setup (with any credentials removed)
- your OS and how you installed OpenCode
If you're still seeing this, please reply with those details or open a new issue that includes them, and we'll take it from there. Thanks!
I met similar problem ..
With host proxy enabled, Opencode service cannot start or restart
env | grep -i proxy
no_proxy=localhost,127.0.0.1,::1,brg.loc,.brg.loc
ftp_proxy=http://vs-proxy-gsa01.brg.loc:3128
https_proxy=http://vs-proxy-gsa01.brg.loc:3128
NO_PROXY=localhost,127.0.0.1,::1,brg.loc,.brg.loc
HTTPS_PROXY=http://vs-proxy-gsa01.brg.loc:3128
HTTP_PROXY=http://vs-proxy-gsa01.brg.loc:3128
http_proxy=http://vs-proxy-gsa01.brg.loc:3128
opencode service restart
Error: Server process exited with code 1
Error: Managed service port 19474 on 0.0.0.0 is already in use by PID 544162 (/home/vp/.opencode/bin/opencode serve --service). Configure another port with `opencode service set port <port>` and start the service again.
at <anonymous> (/$bunfs/root/chunk-aj9ke0jq.js:3:7551) {
[cause]: ServeError:
at F (/$bunfs/root/chunk-7559ejtv.js:52:10000)
at applyHandlers (node:events:64:20)
at emitError (node:events:44:27)
at emitListenErrorNextTick (node:_http_server:166:12)
at processTicksAndRejections (native:7:39) {
[cause]: Error: Failed to start server. Is port 19474 in use?
at serve (unknown)
at <anonymous> (node:_http_server:438:35)
at <anonymous> (node:_http_server:410:33)
at <anonymous> (/$bunfs/root/chunk-7559ejtv.js:52:10038)
}
}
at map (native:1:11)
at reap (/$bunfs/root/chunk-zfhcvzvb.js:2:1159)
at <anonymous> (/$bunfs/root/chunk-zfhcvzvb.js:3:6704)
at service.ensure (/$bunfs/root/chunk-4tf8ahgq.js:2:900)
at service.ensure (definition) (/$bunfs/root/chunk-zfhcvzvb.js:3:5516)
at cli.service.restart (/$bunfs/root/chunk-zw8xxtvj.js:7:23383)
at cli.service.restart (definition) (/$bunfs/root/chunk-4tf8ahgq.js:2:809)
If I unset variables, the problem gone.
env | grep -i proxy
✘-1 ~ [master L|…49]
20:39 $ env | grep -i proxy
✘-1 ~ [master L|…49]
20:39 $ opencode service restart
http://0.0.0.0:19474
✔ ~ [master L|…49]
20:39 $ opencode service start
http://0.0.0.0:19474
opencode --version
opencode v2.3.0
cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.5 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo