2.2 Three-Layer Feature Gate System

Chapter goal: Understand how Claude Code uses a three-layer mechanism to control feature visibility, and the engineering considerations behind this design.


Why Is a Gate System Needed?

Claude Code has many internal features that are not publicly exposed. Anthropic needs to solve several problems:

  1. Safe rollout: new features cannot be exposed to all users immediately; progressive rollout is required
  2. Code isolation: external builds should not contain internal debugging tool code
  3. Fast response: if a feature fails, it must be remotely disabled immediately
  4. A/B testing: different feature configurations must be testable across user groups

The three-layer gate system is designed for these four needs:

Layer 1: compile time → solves code isolation
Layer 2: runtime → solves user-type differentiation  
Layer 3: remote config → solves progressive rollout and emergency shutdown

Layer 1: Compile-Time Switch feature()

Mechanism: dead code elimination (DCE) during Bun build

// source form

const coordinatorModule = feature('COORDINATOR_MODE')
  ? require('./coordinator/coordinatorMode.js')
  : null

When building the external edition, feature('COORDINATOR_MODE') is replaced with false:

// after build
const coordinatorModule = false
  ? require('./coordinator/coordinatorMode.js')  // ← this line is removed entirely
  : null

The bundler sees that this code path is unreachable and removes it from output directly. Coordinator-related code literally does not exist in the external binary.

Full Classification of 50 Compile Switches

CategorySwitch names
Core featuresBUDDY, KAIROS, KAIROS_BRIEF, KAIROS_CHANNELS, KAIROS_GITHUB_WEBHOOKS, ULTRAPLAN, COORDINATOR_MODE, BRIDGE_MODE, VOICE_MODE, PROACTIVE, FORK_SUBAGENT, DAEMON
InfrastructureUDS_INBOX, WORKFLOW_SCRIPTS, TORCH, MONITOR_TOOL, HISTORY_SNIP, BG_SESSIONS, CCR_REMOTE_SETUP, CHICAGO_MCP, HARD_FAIL
Context optimizationCACHED_MICROCOMPACT, CONTEXT_COLLAPSE, REACTIVE_COMPACT, QUICK_SEARCH, TOKEN_BUDGET, STREAMLINED_OUTPUT
Security & complianceANTI_DISTILLATION_CC, BASH_CLASSIFIER, NATIVE_CLIENT_ATTESTATION, TRANSCRIPT_CLASSIFIER, UNATTENDED_RETRY
Data & telemetryEXTRACT_MEMORIES, MEMORY_SHAPE_TELEMETRY, COWORKER_TYPE_TELEMETRY, SLOW_OPERATION_LOGGING, COMMIT_ATTRIBUTION
ExperimentalEXPERIMENTAL_SKILL_SEARCH, MCP_SKILLS, LODESTONE, TEMPLATES, TEAMMEM
User settings syncDOWNLOAD_USER_SETTINGS, UPLOAD_USER_SETTINGS, FILE_PERSISTENCE

Layer 2: User Type USER_TYPE

Mechanism: runtime environment variable checks

// real code from src/tools.ts
const REPLTool =
  process.env.USER_TYPE === 'ant'
    ? require('./tools/REPLTool/REPLTool.js').REPLTool
    : null

Two user types:

TypeDescriptionImpact
antAnthropic internal employeeunlocks full features, 20-minute GrowthBook refresh, 200+ internal debug checks
externalexternal usertrimmed feature set, 6-hour GrowthBook refresh

Internal-Only Tools (USER_TYPE === 'ant')


Layer 3: GrowthBook Remote A/B Testing

Mechanism: fetch feature flags from GrowthBook service at runtime

// actual call style seen in source

// example: check whether KAIROS is enabled
const isKairosEnabled = getFeatureValue_CACHED_MAY_BE_STALE('tengu_kairos')

// example: check Coordinator Scratchpad feature
const scratchpadEnabled = checkStatsigFeatureGate_CACHED_MAY_BE_STALE('tengu_scratch')

Notice _CACHED_MAY_BE_STALE in the function names—this is intentional:

Key GrowthBook Switches (tengu_ prefix)

Switch nameControls
tengu_kairosglobal switch for KAIROS assistant mode
tengu_onyx_ploverauto Dream trigger threshold (interval/session count)
tengu_cobalt_frostspeech recognition (Nova 3 model)
tengu_ultraplan_modelmodel used by Ultraplan
tengu_ccr_bridgeglobal Bridge remote control switch
tengu_bridge_repl_v2Bridge v2 transport protocol switch
tengu_max_version_configauto-update kill switch
tengu_session_memorysession memory feature
tengu_scratchCoordinator Scratchpad directory
tengu_sm_configsession memory config parameters
tengu_frond_boricdata receiver kill switch

Three-Layer Composition Example: KAIROS Activation Flow

A real feature activation must pass all layers:

To activate KAIROS assistant mode:

1. Compile time: feature('KAIROS') = true         ← external build cannot pass
        ↓
2. Runtime: settings.json assistant: true         ← user enables manually
        ↓
3. Directory trust: directory is trusted by user  ← security check
        ↓
4. GrowthBook: tengu_kairos = true                ← Anthropic remote switch
        ↓
5. Global state: setKairosActive(true)            ← final activation

If any layer fails, KAIROS will not activate.


Engineering Value of This Design

Kill Switch Principle

GrowthBook ensures any feature can be globally disabled within seconds:

// suppose a feature has a serious issue
// Anthropic only needs to set tengu_some_feature = false in the GrowthBook console
// all users will read the new value on next refresh (at most 6 hours) and disable it

Essential Difference: Internal vs External Build

External build (npm package):
  feature('KAIROS') → false → KAIROS code is 100% absent from binary

Internal build (run by Anthropic employees):
  feature('KAIROS') → true → KAIROS code exists + GrowthBook remote switch

This is not "hidden functionality"; it is a release-controlled difference between code at different productization levels.


Next