Skip to main content
skill CX Codex

adding-feature-flags — Claude Code skill: what it does, how to install

Adds feature toggles for gradual rollouts and A/B tests using PostHog or local environment variables.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add spencerpauly/awesome-cursor-skills --skill adding-feature-flags -a claude-code
Open on GitHub

What adding-feature-flags does

This skill guides the agent in adding feature flags to frontend and backend code. It provides two options: an integration with PostHog or a lightweight local setup using an environment config file in lib/feature-flags.ts.

Server-side evaluations with posthog-node require a POSTHOG_API_KEY. Cache these evaluations to prevent per-request network calls. For client-side React code, it sets up the useFeatureFlagEnabled hook from posthog-js/react.

What it helps with

  • roll out new features gradually to users
  • run frontend A/B tests with PostHog
  • set up local feature toggles using environment variables
  • add kill switches to disable unstable code paths

Example prompts for the agent

  • Add a feature flag for the new checkout flow using PostHog
  • Set up local feature flags in lib/feature-flags.ts
  • Implement server-side flag evaluation for API routes

How to install adding-feature-flags

1Skills CLI (Vercel)

npx skills add spencerpauly/awesome-cursor-skills --skill adding-feature-flags -a claude-code

2Manually: put the files in place

~/.claude/skills/adding-feature-flags/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/adding-feature-flags/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about adding-feature-flags

How do I install adding-feature-flags in Claude Code?

Run npx skills add spencerpauly/awesome-cursor-skills --skill adding-feature-flags -a claude-code.

What does adding-feature-flags do?

It provides instructions for adding feature flags, kill switches, and rollout toggles via PostHog or local environment variables.

What is required for server-side PostHog flag checks?

You need the posthog-node package and a valid POSTHOG_API_KEY set in your environment variables.

Source text

SKILL.md · CC0-1.0
---
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`.

© spencerpauly · CC0-1.0 · spencerpauly/awesome-cursor-skills

Similar skills

Everything for Frontend and UI →

From the same set59

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor