/ utils / agentSwarmsEnabled.ts
agentSwarmsEnabled.ts
 1  import { getFeatureValue_CACHED_MAY_BE_STALE } from '../services/analytics/growthbook.js'
 2  import { isEnvTruthy } from './envUtils.js'
 3  
 4  /**
 5   * Check if --agent-teams flag is provided via CLI.
 6   * Checks process.argv directly to avoid import cycles with bootstrap/state.
 7   * Note: The flag is only shown in help for ant users, but if external users
 8   * pass it anyway, it will work (subject to the killswitch).
 9   */
10  function isAgentTeamsFlagSet(): boolean {
11    return process.argv.includes('--agent-teams')
12  }
13  
14  /**
15   * Centralized runtime check for agent teams/teammate features.
16   * This is the single gate that should be checked everywhere teammates
17   * are referenced (prompts, code, tools isEnabled, UI, etc.).
18   *
19   * Ant builds: always enabled.
20   * External builds require both:
21   * 1. Opt-in via CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS env var OR --agent-teams flag
22   * 2. GrowthBook gate 'tengu_amber_flint' enabled (killswitch)
23   */
24  export function isAgentSwarmsEnabled(): boolean {
25    // Ant: always on
26    if (process.env.USER_TYPE === 'ant') {
27      return true
28    }
29  
30    // External: require opt-in via env var or --agent-teams flag
31    if (
32      !isEnvTruthy(process.env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS) &&
33      !isAgentTeamsFlagSet()
34    ) {
35      return false
36    }
37  
38    // Killswitch — always respected for external users
39    if (!getFeatureValue_CACHED_MAY_BE_STALE('tengu_amber_flint', true)) {
40      return false
41    }
42  
43    return true
44  }