Cursor Skill

adding-feature-flags

Add feature flags to an application for gradual rollouts, A/B testing, and kill switches using PostHog, LaunchDarkly, or a simple local implementation.

LLM Mart · 0 points · 26 views 0 listing impressions 0 install-command copies
Virus-scanned Reviewed automatically before listing.

Full trust report

Download spencerpauly-awesome-cursor-skills-resources_adding-feature-flags-99cd265.zip · 1 KB
Part of spencerpauly/awesome-cursor-skills — 65 skills

Install

skills CLI npx skills add https://github.com/spencerpauly/awesome-cursor-skills/tree/main/resources/adding-feature-flags
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install spencerpauly-awesome-cursor-skills@llmmart
Git git clone https://github.com/spencerpauly/awesome-cursor-skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole spencerpauly/awesome-cursor-skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Add Feature Flags

Use this skill when the user asks to add feature flags, feature toggles, gradual rollouts, or A/B testing.

Option A: PostHog Feature Flags (Recommended)

  1. Install PostHog if not already present:

    npm install posthog-js
    
  2. Use feature flags in code:

    import { useFeatureFlagEnabled } from "posthog-js/react";
    
    function MyComponent() {
      const showNewFeature = useFeatureFlagEnabled("new-checkout-flow");
      if (showNewFeature) return <NewCheckout />;
      return <OldCheckout />;
    }
    
  3. Server-side evaluation — for server components or API routes:

    import { PostHog } from "posthog-node";
    
    const posthog = new PostHog(process.env.POSTHOG_API_KEY!);
    const isEnabled = await posthog.isFeatureEnabled("new-checkout-flow", userId);
    
  4. Create flags in the PostHog dashboard — set up targeting rules based on user properties, percentage rollouts, or cohorts.

Option B: Simple Local Feature Flags

For projects that don't need a third-party service:

  1. Create a flags configlib/feature-flags.ts:

    export const FLAGS = {
      NEW_CHECKOUT: process.env.NEXT_PUBLIC_FF_NEW_CHECKOUT === "true",
      DARK_MODE: process.env.NEXT_PUBLIC_FF_DARK_MODE === "true",
    } as const;
    
  2. Use in components:

    import { FLAGS } from "@/lib/feature-flags";
    
    function App() {
      return FLAGS.NEW_CHECKOUT ? <NewCheckout /> : <OldCheckout />;
    }
    
  3. Add env vars — add flags to .env and .env.example:

    NEXT_PUBLIC_FF_NEW_CHECKOUT=false
    NEXT_PUBLIC_FF_DARK_MODE=true
    

Notes

  • Use feature flags for all user-facing changes during rollout, not just experiments.
  • Clean up stale flags — remove the flag and the old code path once a feature is fully rolled out.
  • For server-side flags, cache the evaluation result to avoid per-request API calls.
  • Name flags descriptively: new-checkout-flow not flag-1.
Files (awesome-cursor-skills)
  • SKILL.md 2.2 KB
    ---
    name: adding-feature-flags
    description: Add feature flags to an application for gradual rollouts, A/B testing, and kill switches using PostHog, LaunchDarkly, or a simple local implementation.
    ---
    
    # Add Feature Flags
    
    Use this skill when the user asks to add feature flags, feature toggles, gradual rollouts, or A/B testing.
    
    ## Option A: PostHog Feature Flags (Recommended)
    
    1. **Install PostHog** if not already present:
    
       ```bash
       npm install posthog-js
       ```
    
    2. **Use feature flags in code**:
    
       ```tsx
       import { useFeatureFlagEnabled } from "posthog-js/react";
    
       function MyComponent() {
         const showNewFeature = useFeatureFlagEnabled("new-checkout-flow");
         if (showNewFeature) return <NewCheckout />;
         return <OldCheckout />;
       }
       ```
    
    3. **Server-side evaluation** — for server components or API routes:
    
       ```ts
       import { PostHog } from "posthog-node";
    
       const posthog = new PostHog(process.env.POSTHOG_API_KEY!);
       const isEnabled = await posthog.isFeatureEnabled("new-checkout-flow", userId);
       ```
    
    4. **Create flags in the PostHog dashboard** — set up targeting rules based on user properties, percentage rollouts, or cohorts.
    
    ## Option B: Simple Local Feature Flags
    
    For projects that don't need a third-party service:
    
    1. **Create a flags config** — `lib/feature-flags.ts`:
    
       ```ts
       export const FLAGS = {
         NEW_CHECKOUT: process.env.NEXT_PUBLIC_FF_NEW_CHECKOUT === "true",
         DARK_MODE: process.env.NEXT_PUBLIC_FF_DARK_MODE === "true",
       } as const;
       ```
    
    2. **Use in components**:
    
       ```tsx
       import { FLAGS } from "@/lib/feature-flags";
    
       function App() {
         return FLAGS.NEW_CHECKOUT ? <NewCheckout /> : <OldCheckout />;
       }
       ```
    
    3. **Add env vars** — add flags to `.env` and `.env.example`:
    
       ```
       NEXT_PUBLIC_FF_NEW_CHECKOUT=false
       NEXT_PUBLIC_FF_DARK_MODE=true
       ```
    
    ## Notes
    
    - Use feature flags for all user-facing changes during rollout, not just experiments.
    - Clean up stale flags — remove the flag and the old code path once a feature is fully rolled out.
    - For server-side flags, cache the evaluation result to avoid per-request API calls.
    - Name flags descriptively: `new-checkout-flow` not `flag-1`.
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.

Related