$npx -y skills add rshankras/claude-code-apple-skills --skill feature-flagsGenerate feature flag infrastructure with local defaults, remote configuration, SwiftUI integration, and debug menu. Use when adding feature flags or A/B testing to iOS/macOS apps.
| 1 | # Feature Flags Generator |
| 2 | |
| 3 | Generate a complete feature flag infrastructure with typed flag definitions, protocol-based providers (local, remote, composite), SwiftUI environment integration, an `@Observable` manager, and a debug menu for toggling flags at runtime. |
| 4 | |
| 5 | ## When This Skill Activates |
| 6 | |
| 7 | Use this skill when the user: |
| 8 | - Asks to "add feature flags" or "add feature toggles" |
| 9 | - Mentions A/B testing or gradual rollouts |
| 10 | - Asks about Firebase Remote Config or similar remote configuration |
| 11 | - Wants to disable features without shipping an app update |
| 12 | - Mentions "kill switches" or "feature gates" |
| 13 | - Wants to control features remotely for a subset of users |
| 14 | - Asks for a debug menu to toggle features during development |
| 15 | |
| 16 | ## Pre-Generation Checks |
| 17 | |
| 18 | ### 1. Project Context Detection |
| 19 | - [ ] Check for existing feature flag implementations |
| 20 | - [ ] Check for Firebase Remote Config or third-party flag SDKs |
| 21 | - [ ] Identify source file locations (Sources/, App/, or root) |
| 22 | - [ ] Verify minimum deployment target (iOS 17+ / macOS 14+ for @Observable) |
| 23 | |
| 24 | ### 2. Conflict Detection |
| 25 | |
| 26 | Search for existing feature flag code: |
| 27 | ``` |
| 28 | Glob: **/*FeatureFlag*.swift, **/*FeatureToggle*.swift, **/*RemoteConfig*.swift |
| 29 | Grep: "FeatureFlag" or "FeatureToggle" or "RemoteConfig" or "isFeatureEnabled" |
| 30 | ``` |
| 31 | |
| 32 | If existing feature flag code is found: |
| 33 | - Ask whether to replace or extend the existing implementation |
| 34 | - Check for flag names or enum cases that could conflict |
| 35 | |
| 36 | If a third-party SDK (Firebase, LaunchDarkly, etc.) is detected: |
| 37 | - Ask if the user wants a standalone implementation or a wrapper around the SDK |
| 38 | |
| 39 | ### 3. Required Capabilities |
| 40 | |
| 41 | **Feature flags require:** |
| 42 | - iOS 17+ / macOS 14+ deployment target (for @Observable manager) |
| 43 | - Network access entitlement if using remote flags |
| 44 | - No special Info.plist entries needed |
| 45 | |
| 46 | ## Configuration Questions |
| 47 | |
| 48 | Ask user via AskUserQuestion: |
| 49 | |
| 50 | 1. **What features do you want to flag?** (freeform) |
| 51 | - Examples: new onboarding, premium paywall, experimental UI, dark mode v2 |
| 52 | - This determines the flag enum cases and their default values |
| 53 | |
| 54 | 2. **What flag value types do you need?** |
| 55 | - Boolean only (feature on/off) |
| 56 | - Boolean + String (on/off plus string configuration) |
| 57 | - Boolean + String + Integer (full typed support) |
| 58 | - Boolean + String + Integer + JSON (for complex configurations) |
| 59 | |
| 60 | 3. **What provider architecture?** |
| 61 | - **Local only** -- UserDefaults-based with compile-time defaults |
| 62 | - **Remote only** -- JSON endpoint with local caching |
| 63 | - **Composite (recommended)** -- Local defaults with remote override; remote wins when available |
| 64 | |
| 65 | 4. **Include debug menu?** |
| 66 | - Yes -- SwiftUI view for toggling flags at runtime (DEBUG builds only) |
| 67 | - No -- Skip the debug view |
| 68 | |
| 69 | 5. **Include SwiftUI environment integration?** |
| 70 | - Yes (recommended) -- Inject the flag manager via SwiftUI Environment |
| 71 | - No -- Use the manager directly |
| 72 | |
| 73 | ## Generation Process |
| 74 | |
| 75 | ### Step 1: Determine File Locations |
| 76 | |
| 77 | Check project structure: |
| 78 | - If `Sources/` exists --> `Sources/FeatureFlags/` |
| 79 | - If `App/` exists --> `App/FeatureFlags/` |
| 80 | - Otherwise --> `FeatureFlags/` |
| 81 | |
| 82 | ### Step 2: Create Core Files |
| 83 | |
| 84 | Generate these files based on configuration answers: |
| 85 | |
| 86 | 1. **`FeatureFlag.swift`** -- Flag enum with typed default values |
| 87 | 2. **`FeatureFlagService.swift`** -- Protocol defining provider interface |
| 88 | 3. **`LocalFeatureFlagProvider.swift`** -- UserDefaults-based provider with debug overrides |
| 89 | 4. **`RemoteFeatureFlagProvider.swift`** -- URL-based provider with disk caching (if remote or composite) |
| 90 | 5. **`CompositeFeatureFlagProvider.swift`** -- Combines local + remote; remote overrides local (if composite) |
| 91 | 6. **`FeatureFlagManager.swift`** -- @Observable manager for SwiftUI |
| 92 | 7. **`FeatureFlagEnvironmentKey.swift`** -- SwiftUI Environment integration (if requested) |
| 93 | 8. **`FeatureFlagDebugView.swift`** -- Debug toggle view (if requested) |
| 94 | |
| 95 | ### Step 3: Generate Code from Templates |
| 96 | |
| 97 | Use the templates in **templates.md** and customize based on user answers: |
| 98 | - Replace placeholder flag cases with real feature names |
| 99 | - Set appropriate default values per flag |
| 100 | - Include or exclude remote/composite providers based on architecture choice |
| 101 | - Include or exclude typed value methods (string, int, JSON) based on type selection |
| 102 | - Include or exclude environment key and debug view |
| 103 | |
| 104 | ## Output Format |
| 105 | |
| 106 | After generation, provide: |
| 107 | |
| 108 | ### Files Created |
| 109 | |
| 110 | ``` |
| 111 | Sources/FeatureFlags/ |
| 112 | ├── FeatureFlag.swift # Flag enum with typed defaults |
| 113 | ├── FeatureFlagService.swift # Provider protocol |
| 114 | ├── LocalFeatureFlagProvider.swift # UserDefaults-based provider |
| 115 | ├── RemoteFeatureFlagProvider.swift # URL-based provider (i |