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

```bash
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080

opencode
```

`HTTP_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.

## Service

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.

```bash
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 start
```

Changing 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`:

```bash
opencode service unset env HTTPS_PROXY
```

## Authentication

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

```bash
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.

```bash
opencode service set env HTTPS_PROXY 'http://user:p%40ssword@proxy.example.com:8080'
```

## Certificates

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.

```bash
export NODE_EXTRA_CA_CERTS=/etc/company/ca.pem
opencode --standalone
```

Persist the file path for the background service, then restart it:

```bash
opencode service set env NODE_EXTRA_CA_CERTS /etc/company/ca.pem
opencode service start
```

## Antivirus and HTTPS inspection

Antivirus "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:

```text
self signed certificate in certificate chain
SELF_SIGNED_CERT_IN_CHAIN
CERT_NOT_YET_VALID
CERT_SIGNATURE_FAILURE
```

Fix it in one of two ways:

- Exclude `opencode.ai` and `*.opencode.ai` from HTTPS scanning in the antivirus settings. Add your provider's API host
  too, such as `api.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](#certificates).

## Client 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.

```jsonc title="opencode.jsonc"
{
  "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}",
        },
      },
    },
  },
}
```

- `cert` and `key` are PEM text. Use `{file:...}` to read them from files. A file that can't be read leaves `tls` unset.
- `passphrase` is 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.

## Foreground

`--standalone` and `serve` use the environment of their own process. `opencode service set env` does not configure these
processes.

```bash
HTTP_PROXY=http://proxy.example.com:8080 \
HTTPS_PROXY=http://proxy.example.com:8080 \
opencode --standalone
```

Apply the same pattern to a foreground server:

```bash
HTTPS_PROXY=http://proxy.example.com:8080 \
opencode serve
```

## Verify

Check that the CLI can reach the background service after applying the settings:

```bash
opencode api get /api/info
```

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