musistudio/claude-code-router · error · Error
Invalid proxy endpoint: ${endpoint}
Error message
Invalid proxy endpoint: ${endpoint} What it means
The system-proxy module could not parse a previously persisted managed proxy endpoint string (from its state file/restore data). The value must be a valid URL with a hostname and integer port between 1 and 65535; otherwise restore()/managedEndpoint() throws.
Source
Thrown at packages/core/src/proxy/system-proxy.ts:322
}
export async function readCurrentSystemUpstreamProxy(managedEndpointUrl: string): Promise<UpstreamProxyConfig | undefined> {
if (process.platform !== "darwin" && process.platform !== "win32") {
return undefined;
}
const managedEndpoint = parseManagedEndpoint(managedEndpointUrl);
const snapshot = process.platform === "win32"
? await captureWindowsSystemProxySnapshot(managedEndpoint)
: await captureMacSystemProxySnapshot(managedEndpoint);
return readSnapshotUpstreamProxy(snapshot, managedEndpoint);
}
function parseManagedEndpoint(endpoint: string): ManagedProxyEndpoint {
const parsed = new URL(endpoint);
const port = Number(parsed.port || (parsed.protocol === "https:" ? 443 : 80));
if (!parsed.hostname || !Number.isInteger(port) || port < 1 || port > 65535) {
throw new Error(`Invalid proxy endpoint: ${endpoint}`);
}
return {
host: parsed.hostname,
port,
url: `http://${formatProxyHost(parsed.hostname)}:${port}`
};
}
function normalizeCustomProxyServer(server: string): string {
const trimmed = server.trim();
if (!trimmed) {
return "";
}
try {
const parsed = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`);
return parsed.hostname;
} catch {View on GitHub (pinned to 99f24806c6)
Solutions
- Delete/reset the persisted proxy state file so a fresh endpoint is created
- Inspect the stored endpoint string and fix or regenerate it via the module's API instead of editing state by hand
- Catch the error during restore and fall back to a clean managed endpoint setup
Example fix
// before
await systemProxy.restore(); // throws on corrupt state
// after
try {
await systemProxy.restore();
} catch {
await systemProxy.clearState(); // or delete the state file
await systemProxy.restore();
} Defensive patterns
Strategy: try-catch
Validate before calling
function isValidEndpoint(endpoint: string): boolean {
try { const u = new URL(endpoint); const p = Number(u.port || 80); return !!u.hostname && Number.isInteger(p) && p >= 1 && p <= 65535; } catch { return false; }
} Type guard
function isManagedEndpointValue(v: unknown): v is string { return typeof v === "string" && isValidEndpoint(v); } Try / catch
try { await systemProxy.restore(); } catch (e) { if (e.message.startsWith("Invalid proxy endpoint")) { await systemProxy.reset(); await systemProxy.restore(); return; } throw e; } Prevention
- Never hand-edit persisted proxy state
- Validate state file contents before restore
- Keep a recovery path that resets state on parse failure
When it happens
Trigger: Calling restore() or reading the managed endpoint when the saved endpoint string is corrupt — e.g. 'http://:0', 'not a url', a port of NaN, or a hand-edited state file.
Common situations: Corrupted or manually edited proxy state file after a crash; version changes that altered the endpoint format; leftover state from a different tool; empty-string endpoint persisted by an older buggy version.
Related errors
- No Bot Gateway conversationRef is available for media respon
- ToolHub resolver requires TOOLHUB_OPENAI_API_KEY and TOOLHUB
- Video fallback model ${selector} uses ${target.protocol}, bu
- A media model must be selected.
- Media model is not configured by a provider: ${normalizedSel
AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27).
Data as JSON: /api/errors/aaa235ccd1063520.
Report an issue: GitHub.