-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathprivacyLevel.ts
More file actions
55 lines (50 loc) · 1.84 KB
/
Copy pathprivacyLevel.ts
File metadata and controls
55 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Privacy level controls how much nonessential network traffic and telemetry
* Claude Code generates.
*
* Levels are ordered by restrictiveness:
* default < no-telemetry < essential-traffic
*
* - default: Everything enabled.
* - no-telemetry: Analytics/telemetry disabled (Datadog, 1P events, feedback survey).
* - essential-traffic: ALL nonessential network traffic disabled
* (telemetry + auto-updates, grove, release notes, model capabilities, etc.).
*
* The resolved level is the most restrictive signal from:
* CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC → essential-traffic
* DISABLE_TELEMETRY → no-telemetry
*/
type PrivacyLevel = 'default' | 'no-telemetry' | 'essential-traffic'
export function getPrivacyLevel(): PrivacyLevel {
if (process.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC) {
return 'essential-traffic'
}
if (process.env.DISABLE_TELEMETRY) {
return 'no-telemetry'
}
return 'default'
}
/**
* True when all nonessential network traffic should be suppressed.
* Equivalent to the old `process.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` check.
*/
export function isEssentialTrafficOnly(): boolean {
return getPrivacyLevel() === 'essential-traffic'
}
/**
* True when telemetry/analytics should be suppressed.
* True at both `no-telemetry` and `essential-traffic` levels.
*/
export function isTelemetryDisabled(): boolean {
return getPrivacyLevel() !== 'default'
}
/**
* Returns the env var name responsible for the current essential-traffic restriction,
* or null if unrestricted. Used for user-facing "unset X to re-enable" messages.
*/
export function getEssentialTrafficOnlyReason(): string | null {
if (process.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC) {
return 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC'
}
return null
}