agentleFS
jars-demojars-demo/jars-skills/skills/feature-flags/SKILL.md

feature-flags

Skill0 starsChanged 32 days agoMITView on GitHub

Implementing, gating, and cleaning up feature flags: picks the right flag type (boolean, percentage rollout, user-targeted), wires up a flag client (LaunchDarkly, Unleash, Flagsmith, or homegrown config), wraps new code in flag checks without coupling business logic to the flag system, tracks flag age, and removes stale flags safely. Use when you want to add a feature flag, do a gradual rollout, gate a feature for specific users, implement a kill switch, set up LaunchDarkly or Unleash, clean up an old flag, or roll back without deploying.

  • Reads credentials

20 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use observability, incident-response and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • OpenAISkill

    observability

    Vercel Observability expert guidance — Drains (logs, traces, speed insights, web analytics), Web Analytics, Speed Insights, runtime logs, custom events, OpenTelemetry integration, and monitoring dashboards. Use when instrumenting, debugging, or optimizing application performance and user experience on Vercel.

    Also in 6 projects that use this

  • AnthropicSkill

    incident-response

    Run an incident response workflow — triage, communicate, and write postmortem. Trigger with "we have an incident", "production is down", an alert that needs severity assessment, a status update mid-incident, or when writing a blameless postmortem after resolution.

    Also in 5 projects that use this

  • etewiahSkill

    e2e-testing

    Playwright E2E testing and Lighthouse performance auditing. Use when setting up E2E tests, running Playwright tests, performing Lighthouse audits, or debugging E2E test failures.

    Also in 3 projects that use this

  • 0xSeroSkill

    security

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. 0 are common, 13 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 13

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add, use, and eventually remove feature flags cleanly.

    line 8
  2. Distinctive:

    Start with the simplest type that satisfies the requirement.

    line 19
  3. Distinctive:

    Keep flags in a config file or environment variable and parse them at startup.

    line 35
  4. Distinctive:

    Never call the flag SDK directly in business logic.

    line 49
  5. Distinctive:

    Keep flag checks at the controller / handler / route level where possible.

    line 123
  6. Distinctive:

    Never make a flag check affect database schema or migrations — those changes must be backward-compatible on their own.

    line 124
  7. Very specific:

    Use kebab-case. Include a prefix that groups related flags.

    line 129
  8. Distinctive:

    Add a comment or description in the flag dashboard explaining: what it gates, who owns it, and the intended removal date.

    line 137
  9. Very specific:

    When you create a flag, open a ticket for its removal (e.g., "Remove new-checkout-flow flag after 100% rollout stabilises — target: 2 weeks …

    line 144
  10. Distinctive:

    Search the codebase for every reference to the flag key string.

    line 160
  11. Very specific:

    Delete the OLD code path and any types / helpers that only existed for it.

    line 162
  12. Distinctive:

    Remove the flag key from any test overrides.

    line 164
  13. Distinctive:

    Test both branches. Use the stub client, not the real SDK.

    line 174
  14. Very specific:

    Always provide a safe default (usually false / the old behaviour).

    line 196
  15. Distinctive:

    Never read flags in migrations, seed scripts, or schema definitions.

    line 198
  16. Distinctive:

    Never hard-code a user ID as the only way to enable a flag in production — use targeting rules in the dashboard.

    line 199
  17. Very specific:

    If the flag SDK is unavailable at startup, default to false and log a warning — don't crash.

    line 202
  18. Distinctive:

    Treat the flag key string as an API: once it's in production, don't rename it.

    line 203

“Common” is measured: kept by at least 6 in 10 of the 17 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

feature-flags

Add, use, and eventually remove feature flags cleanly.

1. Decide the flag type before writing any code

TypeWhen to useExample
Boolean (on/off)Kill switch, staff-only previewnew-checkout-flow
Percentage rolloutGradual exposure to reduce blast radiusRoll out to 5% → 25% → 100%
User / segment targetingBeta testers, paying customers, internal teamuser.plan === 'pro'
MultivariateA/B testing or configuration valuesbutton_color = blue|green|red

Start with the simplest type that satisfies the requirement. Over-engineering flags is a common source of long-lived flag debt.

2. Pick a flag backend

Managed service (recommended for teams):

  • LaunchDarkly — SDKs for every language, percentage rollouts, targeting rules, real-time streaming.
  • Unleash — open-source, self-hostable, strong gradual rollout support.
  • Flagsmith — open-source, supports remote config values alongside booleans.

Homegrown (fine for simple cases):

Keep flags in a config file or environment variable and parse them at startup. This works for kill switches and staff-only flags but does not support percentage rollouts or targeting without extra code.

// flags.json — simplest possible homegrown approach
{
  "new-checkout-flow": false,
  "enable-new-search":  true
}

3. Wrap the SDK in a thin abstraction

Never call the flag SDK directly in business logic. One wrapper keeps the system swappable and makes testing trivial.

// lib/flags.ts
export interface FlagClient {
  isEnabled(flagKey: string, context?: FlagContext): boolean;
  getVariant<T>(flagKey: string, defaultValue: T, context?: FlagContext): T;
}

export interface FlagContext {
  userId?: string;
  email?: string;
  plan?: string;
  [key: string]: string | undefined;
}

// LaunchDarkly implementation
import LaunchDarkly from '@launchdarkly/node-server-sdk';

const ldClient = LaunchDarkly.init(process.env.LD_SDK_KEY!);
await ldClient.waitForInitialization();

export const flags: FlagClient = {
  isEnabled(key, ctx = {}) {
    return ldClient.variation(key, { key: ctx.userId ?? 'anonymous', ...ctx }, false);
  },
  getVariant(key, defaultValue, ctx = {}) {
    return ldClient.variation(key, { key: ctx.userId ?? 'anonymous', ...ctx }, defaultValue);
  },
};
// Stub for tests — no SDK needed
export const stubFlags = (overrides: Record<string, boolean> = {}): FlagClient => ({
  isEnabled: (key) => overrides[key] ?? false,
  getVariant: (key, defaultValue) => (overrides[key] as typeof defaultValue) ?? defaultValue,
});

4. Write the flag check

Gate the new code path; always provide a fallback.

// ✅ Good — flag isolated at the call site, fallback is explicit
import { flags } from '../lib/flags';

export async function handleCheckout(req: Request, res: Response) {
  const ctx = { userId: req.user.id, plan: req.user.plan };

  if (flags.isEnabled('new-checkout-flow', ctx)) {
    return newCheckoutHandler(req, res);
  }
  return legacyCheckoutHandler(req, res);
}
// ❌ Bad — flag check buried inside business logic, hard to find and remove later
export function calculateTotal(items: Item[], userId: string) {
  const base = items.reduce((s, i) => s + i.price, 0);
  if (ldClient.variation('discount-rounding-fix', { key: userId }, false)) {
    return Math.round(base * 100) / 100;   // hidden deep in a helper
  }
  return base;
}

5. Avoid coupling business logic to the flag system

  • Pass the evaluated boolean into functions; don't call flags.isEnabled from inside pure functions or domain models.
  • Keep flag checks at the controller / handler / route level where possible.
  • Never make a flag check affect database schema or migrations — those changes must be backward-compatible on their own.

6. Name flags consistently

Use kebab-case. Include a prefix that groups related flags.

checkout-new-flow          ✅
enable_new_checkout_FLOW   ❌  inconsistent case
flag123                    ❌  meaningless

Add a comment or description in the flag dashboard explaining: what it gates, who owns it, and the intended removal date.

7. Track flag age and set a removal date

Flags are temporary by design. Long-lived flags become invisible tech debt.

  • When you create a flag, open a ticket for its removal (e.g., "Remove new-checkout-flow flag after 100% rollout stabilises — target: 2 weeks after full rollout").
  • Enforce a maximum age with a lint rule or CI check:
# Simple shell check — fails CI if a flag string is older than 90 days in the codebase
# (adapt to your flag naming convention)
git log --all --diff-filter=A --format="%ai %H" -- "*.ts" \
  | grep "new-checkout-flow" \
  | awk '{ if (systime() - mktime(gensub(/-/, " ", "g", $1) " " gensub(/:/, " ", "g", $2) " 0") > 7776000) exit 1 }'

8. Remove a stale flag

Once a flag is at 100% and stable:

  1. Search the codebase for every reference to the flag key string.
  2. Replace each if (flags.isEnabled('my-flag')) { NEW } else { OLD } with just NEW.
  3. Delete the OLD code path and any types / helpers that only existed for it.
  4. Archive or delete the flag in the dashboard.
  5. Remove the flag key from any test overrides.
  6. Commit: refactor: Remove my-flag feature flag (fully rolled out).
# Find all references before you start
grep -r "new-checkout-flow" src/

9. Test flag-gated code

Test both branches. Use the stub client, not the real SDK.

import { stubFlags } from '../lib/flags';

describe('handleCheckout', () => {
  it('uses new flow when flag is on', async () => {
    const handler = buildHandler(stubFlags({ 'new-checkout-flow': true }));
    const res = await handler(mockRequest());
    expect(res.body.flow).toBe('new');
  });

  it('falls back to legacy when flag is off', async () => {
    const handler = buildHandler(stubFlags({ 'new-checkout-flow': false }));
    const res = await handler(mockRequest());
    expect(res.body.flow).toBe('legacy');
  });
});

Rules

  • Always provide a safe default (usually false / the old behaviour). The flag should fail closed, not open.
  • Never read flags in migrations, seed scripts, or schema definitions.
  • Never hard-code a user ID as the only way to enable a flag in production — use targeting rules in the dashboard.
  • One flag = one decision. Don't reuse a flag for a second, unrelated feature.
  • If the flag SDK is unavailable at startup, default to false and log a warning — don't crash.
  • Treat the flag key string as an API: once it's in production, don't rename it.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.