Feature Flags
Claude Code uses a two-layer feature gating system: build-time flags for compile-time tree-shaking and environment variables for runtime behavior.
Build-Time Flags
Build-time flags use feature() from bun:bundle, which evaluates to a boolean constant at compile time. The bundler eliminates unreachable branches entirely, so gated code never appears in the output binary.
import { feature } from 'bun:bundle'
if (feature('COORDINATOR_MODE')) {
// This entire block is removed from external builds
const module = require('./coordinator/coordinatorMode.js')
}Because feature() resolves at compile time, the gated code path must use require() (not static import) to prevent the bundler from including the module in the dependency graph when the flag is off.
Flag List
| Flag | Purpose |
|---|---|
COORDINATOR_MODE | Multi-agent coordinator that dispatches work to sub-agents |
KAIROS | Assistant/teammate mode for persistent background agents |
KAIROS_BRIEF | Brief/summary panel for Kairos sessions |
KAIROS_GITHUB_WEBHOOKS | GitHub PR subscription for Kairos agents |
KAIROS_PUSH_NOTIFICATION | Push notifications for Kairos events |
VOICE_MODE | Speech-to-text and text-to-speech voice input |
WORKFLOW_SCRIPTS | Reusable workflow script execution |
MONITOR_TOOL | System monitoring tool for agent health |
UDS_INBOX | Unix domain socket peer discovery |
HISTORY_SNIP | Manual transcript snipping tool |
TRANSCRIPT_CLASSIFIER | ML-based permission classifier using transcript analysis |
BASH_CLASSIFIER | ML-based bash command risk classifier |
CACHED_MICROCOMPACT | Cached micro-compaction for efficient context management |
PROMPT_CACHE_BREAK_DETECTION | Detect and handle prompt cache invalidation |
BREAK_CACHE_COMMAND | Force cache break via command injection |
CONNECTOR_TEXT | Connector text blocks in API responses |
QUICK_SEARCH | Global file search and quick-open commands |
TERMINAL_PANEL | Embedded terminal panel toggle |
MESSAGE_ACTIONS | Message action menu on shift+up |
PROACTIVE | Proactive agent suggestions |
COMMIT_ATTRIBUTION | Git commit co-author attribution tracking |
TEAMMEM | Team memory synchronization |
CONTEXT_COLLAPSE | Context window collapse optimization |
NATIVE_CLIENT_ATTESTATION | Native client attestation headers |
ANTI_DISTILLATION_CC | Anti-distillation protections |
EXPERIMENTAL_SKILL_SEARCH | Skill search during compaction |
COWORKER_TYPE_TELEMETRY | Coworker type in analytics metadata |
How Flags Affect Tool Availability
Feature flags control which tools are registered at startup:
// tools.ts
const MonitorTool = feature('MONITOR_TOOL')
? require('./tools/MonitorTool.js') : null
const SnipTool = feature('HISTORY_SNIP')
? require('./tools/SnipTool.js') : null
const ListPeersTool = feature('UDS_INBOX')
? require('./tools/ListPeersTool.js') : null
const WorkflowTool = feature('WORKFLOW_SCRIPTS')
? require('./tools/WorkflowTool.js') : nullCoordinator mode conditionally adds delegation tools:
if (feature('COORDINATOR_MODE') && coordinatorModeModule?.isCoordinatorMode()) {
// Add CoordinatorTool, WorkerDoneTool, etc.
}How Flags Affect Command Registration
Similarly, slash commands are conditionally registered:
// commands.ts
const voiceCommand = feature('VOICE_MODE')
? require('./commands/voice.js') : null
const forceSnip = feature('HISTORY_SNIP')
? require('./commands/snip.js') : null
const workflowsCmd = feature('WORKFLOW_SCRIPTS')
? require('./commands/workflows.js') : null
const peersCmd = feature('UDS_INBOX')
? require('./commands/peers.js') : nullEnvironment Variables
Runtime environment variables provide a second layer of feature gating that does not require rebuilding:
Activates bare/simple mode. Disables skills in prompts, memory directory, file edit previews, and agent directory loading. Set automatically by --bare flag and in coordinator worker sub-processes.
Enables coordinator mode at runtime (requires the COORDINATOR_MODE build flag). The coordinator spawns worker agents and dispatches tasks.
Disables extended thinking/reasoning in API calls. When set, the API is called without thinking parameters regardless of user preferences.
Disables automatic memory extraction and storage.
Disables background task processing.
Disables interleaved thinking blocks in API responses.
Disables conversation compaction entirely.
Disables automatic compaction triggers while allowing manual /compact.
Boolean environment variables are checked with isEnvTruthy(), which treats "1", "true", and "yes" as truthy. The variables listed above are cleared from the environment at CLI entry (entrypoints/cli.tsx) to prevent accidental inheritance by child processes.
Two-Layer Interaction
Build-time and runtime flags often work together. For example, coordinator mode requires both layers:
// Build-time: include the coordinator module
const coordinatorModeModule = feature('COORDINATOR_MODE')
? require('./coordinator/coordinatorMode.js')
: null
// Runtime: check if coordinator mode is active
if (feature('COORDINATOR_MODE') &&
isEnvTruthy(process.env.CLAUDE_CODE_COORDINATOR_MODE)) {
coordinatorModeModule.enableCoordinatorMode()
}The build-time flag controls whether the code exists in the binary. The environment variable controls whether it activates at runtime. This two-layer approach ensures that:
- External builds have no coordinator code at all (smaller binary, no leakage)
- Internal builds can toggle the feature without recompiling
- Worker sub-processes can opt into simplified mode via environment variables