Skip to content

Feature: auto-detect Windows system proxy with smart fallback ("proxy": "auto") #1525

Description

@fantuan812

Area

Proxy and routing

What are you trying to accomplish?

I run opencodex as a Windows background service and switch VPN/proxy tools frequently. Today every proxy change (new port, proxy restart, rule change) silently breaks all upstream requests with 502 Provider unreachable until I manually edit ~/.opencodex/config.json and restart the service. I need opencodex to follow the Windows system proxy automatically — including falling back to direct when the proxy is down — so outbound routing keeps working with zero manual maintenance.

What prevents this today?

config.proxy accepts only a static URL (or ${ENV_VAR} reference) that is mirrored into HTTP_PROXY/HTTPS_PROXY once at process start (applyProxyEnv). There is no way to express "use whatever the system proxy is right now":

  • a hardcoded URL goes stale the moment the proxy tool changes ports or restarts;
  • service-managed instances (Task Scheduler / launchd / systemd) never inherit shell-level HTTP_PROXY exports;
  • on my network OpenAI endpoints (chatgpt.com) are only reachable through the proxy, while opencode.ai is only reliably reachable via a different route — so "always proxy" and "never proxy" are both wrong as static choices;
  • the only current workaround is an external watchdog script that rewrites config and restarts the service, which races with the running proxy's in-memory config and only works for interactive installs.

What should OpenCodex do?

When config.proxy is the special value "auto", opencodex should:

  1. Read the Windows system proxy (HKCU\...\Internet Settings ProxyEnable/ProxyServer) at startup and apply it immediately, so the first outbound request already works;
  2. verify the candidate proxy against upstream targets (e.g. chatgpt.com, opencode.ai) — any HTTP status < 500 counts as reachable;
  3. fall back to direct connection when the proxy is unreachable, and keep the last known proxy when both routes fail, with a clear log line in each case;
  4. re-check every ~60 seconds and apply changes live, without a restart (Bun re-reads HTTP_PROXY/HTTPS_PROXY per request).

Existing behavior must stay backward compatible: static proxy URLs and ${ENV_VAR} references keep working, user-set HTTP_PROXY/HTTPS_PROXY env vars still win, and NO_PROXY loopback defaults remain appended. On non-Windows platforms auto mode should degrade to direct.

Example usage or interface

{
  "proxy": "auto"
}


Before/after: with "proxy": "http://127.0.0.1:7890" and the proxy tool switched to port 7893, every request fails with 502 Provider unreachable. With "proxy": "auto", the service picks up 7893 from the registry within 60 seconds (or falls back to direct) and requests succeed again — no config edits, no restarts.

### Alternatives or workarounds

_No response_

### Additional context

_No response_

### Checks

- [x] I searched existing issues and documentation.
- [x] This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
- [x] I removed secrets and personal data.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestplatformOS/service/tray/ACL (Windows-heavy, not Windows-only)proxyHTTP proxy, routing, reverse-proxy / management auth

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions