fix: gate preconnectAnthropicApi behind isEssentialTrafficOnly()

CC_Pure:  was the last un-gated outbound
connection — it unconditionally sent a TCP+TLS handshake to
api.anthropic.com on every startup. Now checked against the central
privacy gate (CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1) and
skipped when enabled.

Verified via strace: zero remote connections after fix.
This commit is contained in:
James Feng 2026-06-02 00:14:22 +08:00
parent 144c4f551c
commit 6ddad59d2f

View File

@ -25,6 +25,7 @@
import { getOauthConfig } from '../constants/oauth.js'
import { isEnvTruthy } from './envUtils.js'
import { isEssentialTrafficOnly } from './privacyLevel.js'
let fired = false
@ -32,6 +33,9 @@ export function preconnectAnthropicApi(): void {
if (fired) return
fired = true
// CC_Pure: skip preconnect when non-essential traffic is disabled
if (isEssentialTrafficOnly()) return
// Skip if using a cloud provider — different endpoint + auth
if (
isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK) ||