Network
Set the standard proxy variables. OpenCode uses local HTTP connections between the CLI and its background service, and the CLI automatically excludes loopback addresses from proxying.
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
opencodeHTTP_PROXY handles HTTP destinations and HTTPS_PROXY handles HTTPS destinations. The proxy URL itself can use http://
for both variables. The CLI adds 127.0.0.1, localhost, and ::1 to both NO_PROXY and no_proxy on startup. Use
NO_PROXY as a comma-separated list for other hosts that must connect directly.
Shell exports affect a background service only when that service starts from the shell. Persist the variables in the managed service configuration so later service starts use the same network settings.
opencode service set env HTTP_PROXY http://proxy.example.com:8080
opencode service set env HTTPS_PROXY http://proxy.example.com:8080
opencode service set env NO_PROXY llm.company.example
opencode service startChanging a managed environment variable stops the running service. service start starts it again with the new environment.
The CLI shell needs its own proxy variables, because managed service variables apply to the server process, not the CLI
process. Loopback exclusions are added automatically on both sides.
Remove a persisted variable with service unset env:
opencode service unset env HTTPS_PROXYFor a proxy that accepts URL credentials, include the username and password in each proxy URL that needs authentication.
Percent-encode characters such as @, :, and / inside either credential.
export HTTPS_PROXY='http://user:p%40ssword@proxy.example.com:8080'For the background service, persist the complete URL. The value is stored in the private service configuration and is
shown by opencode service get env, so do not share that output.
opencode service set env HTTPS_PROXY 'http://user:p%40ssword@proxy.example.com:8080'Set NODE_EXTRA_CA_CERTS to a PEM file when the proxy or destination uses a certificate signed by a private certificate
authority. The extra authorities are added to the runtime trust store when the process starts.
export NODE_EXTRA_CA_CERTS=/etc/company/ca.pem
opencode --standalonePersist the file path for the background service, then restart it:
opencode service set env NODE_EXTRA_CA_CERTS /etc/company/ca.pem
opencode service startAntivirus “HTTPS scanning” or “encrypted connection scanning” (Kaspersky, Avast, ESET and others) and corporate SSL-inspection proxies replace the server’s certificate with their own. OpenCode rejects it and requests fail with errors such as:
self signed certificate in certificate chain
SELF_SIGNED_CERT_IN_CHAIN
CERT_NOT_YET_VALID
CERT_SIGNATURE_FAILUREFix it in one of two ways:
- Exclude
opencode.aiand*.opencode.aifrom HTTPS scanning in the antivirus settings. Add your provider’s API host too, such asapi.anthropic.com, if you connect to a provider directly. - Export the inspection certificate authority as a PEM file and trust it with
NODE_EXTRA_CA_CERTS, as shown in Certificates.
Set settings.tls on a provider whose gateway requires mutual TLS. Its model requests present the certificate, and the
TLS handshake only sends it to servers that ask for one.
{
"providers": {
"company": {
"package": "@opencode/ai/providers/openai-compatible",
"settings": {
"baseURL": "https://llm.company.example/v1",
"tls": {
"cert": "{file:/etc/company/client.pem}",
"key": "{file:/etc/company/client.key}",
"passphrase": "{env:CLIENT_KEY_PASSPHRASE}",
},
},
},
},
}certandkeyare PEM text. Use{file:...}to read them from files. A file that can’t be read leavestlsunset.passphraseis only needed for an encrypted key.- Works on the Bun and Node builds. A server on Cloudflare Workers can’t present a client certificate through
fetch. - Requests with a client certificate don’t follow redirects, so the certificate isn’t presented to another host.
Every model request of that provider presents the certificate: chat, compaction, image and decision models. A provider
with tls uses HTTP instead of WebSockets. Tools such as webfetch, remote MCP servers and plugin installs don’t present
it.
--standalone and serve use the environment of their own process. opencode service set env does not configure these
processes.
HTTP_PROXY=http://proxy.example.com:8080 \
HTTPS_PROXY=http://proxy.example.com:8080 \
opencode --standaloneApply the same pattern to a foreground server:
HTTPS_PROXY=http://proxy.example.com:8080 \
opencode serveCheck that the CLI can reach the background service after applying the settings:
opencode api get /api/infoA successful health response verifies the local client-to-service connection. Run a normal provider request to verify the service’s outbound proxy and certificate path.