本文へ移動
cccskills
無料GitHub で公開

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.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md2.2 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

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 config — lib/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.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Use Cursor's browser aria snapshots to audit a page for accessibility issues — missing labels, broken tab order, contrast, and ARIA misuse.

日本語の概要は準備中です。原文の説明を表示しています。

0xAidan/polymarket-bot-test42026年9月4日 更新

Add PostHog analytics to a web application, including event tracking, page views, feature flags, and session replay.

日本語の概要は準備中です。原文の説明を表示しています。

0xAidan/polymarket-bot-test42026年9月4日 更新

Generate OpenAPI/Swagger documentation for an API, including endpoint schemas, request/response types, and interactive docs UI.

日本語の概要は準備中です。原文の説明を表示しています。

0xAidan/polymarket-bot-test42026年9月4日 更新

Add authentication to a web application using NextAuth.js (Auth.js), including OAuth providers, session management, and protected routes.

日本語の概要は準備中です。原文の説明を表示しています。

0xAidan/polymarket-bot-test42026年9月4日 更新

Dockerize an application with a production-ready Dockerfile, docker-compose setup, and .dockerignore.

日本語の概要は準備中です。原文の説明を表示しています。

0xAidan/polymarket-bot-test42026年9月4日 更新

Set up Playwright end-to-end testing in a project, including test configuration, example tests, and CI integration.

日本語の概要は準備中です。原文の説明を表示しています。

0xAidan/polymarket-bot-test42026年9月4日 更新

0xAidan のスキルをすべて見る

このスキルの問題を報告する