Start a fresh conversation. Replace the highlighted placeholders.
Use adding-feature-flags to add a simple local feature flag named [flag name] to gate [feature], including a safe default-off configuration and both enabled and disabled application paths.
Required inputs
[flag name]
[feature]
User-approved starter prompt based on a pinned source version; check current skill requirements before running. Task evidence ↗
SKILL.md
name: adding-feature-flagsdescription: 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)
Install PostHog if not already present:
npm install posthog-js
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 />;
}
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);
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: