feature-flags-and-toggles
Skill10 starsChanged 6 months agoMITView on GitHub
Use when adding feature flags, gradual rollouts, beta features, kill switches, or per-user/per-org feature toggles. Not for plan-based gating (use pricing-and-billing) unless flags wrap plan checks too.
In this repository56 other files it gives its agents.
- accessibility-passSkill
- analytics-eventsSkill
- api-error-handlingSkill
- audit-logging-backendSkill
- background-jobs-and-cronSkill
- dark-mode-and-themingSkill
- dashboard-charts-rechartsSkill
- edge-functions-and-webhooksSkill
- email-and-notificationsSkill
- error-states-and-empty-uiSkill
- file-upload-storageSkill
- i18n-multi-languageSkill
- lovable-prompting-playbookSkill
- lovable-ship-checklistSkill
- migration-playbookSkill
- multi-tenant-backendSkill
- onboarding-copySkill
- optimistic-updatesSkill
- payment-failed-and-recoverySkill
- payment-webhook-idempotencySkill
- payment-webhook-testingSkill
- performance-budgetSkill
- pg-cron-recipesSkill
- pg-cron-scheduled-jobsSkill
- pg-cron-with-pg-net-edgeSkill
- postgres-full-text-searchSkill
- postgres-triggers-and-functionsSkill
- pricing-and-billingSkill
- programmatic-seo-content-qualitySkill
- programmatic-seo-pagesSkill
- rate-limiting-edgeSkill
- realtime-and-subscriptionsSkill
- refactor-safe-diffSkill
- release-notesSkill
- seo-core-web-vitalsSkill
- seo-landing-pageSkill
- seo-meta-tags-spaSkill
- seo-sitemap-generationSkill
- seo-ssr-and-prerenderingSkill
- seo-structured-dataSkill
- server-input-validationSkill
- shadcn-patternsSkill
- soft-delete-and-archivingSkill
- stripe-one-time-payment-webhooksSkill
- stripe-payment-webhooksSkill
- supabase-auth-flowsSkill
- supabase-database-designSkill
- supabase-rls-and-authSkill
- support-replySkill
- tanstack-infinite-queriesSkill
- tanstack-mutations-and-invalidationSkill
- tanstack-prefetch-and-hydrationSkill
- tanstack-query-alternativeSkill
- tanstack-router-data-loadersSkill
- tanstack-start-server-routesSkill
- typed-api-hooks-formsSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 40
Write access via service role only (admin UI / SQL editor).
- Distinctive: line 80
Remove the old branch within 2–4 weeks of 100% rollout — flags accumulate as tech debt.
- Very specific: line 82
Document the flag key, owner, and expected removal date in code or a FLAGS.md.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Feature flags and toggles
Ship code dark, enable per user/org/percentage, kill instantly when broken.
Storage
| Option | When |
Env var (VITE_FEATURE_X) | Static, build-time toggles |
DB table feature_flags | Dynamic, per user/org, no extra vendor |
| PostHog / LaunchDarkly / Statsig | Targeting, gradual rollout, A/B |
For most Lovable apps, start with a DB table and graduate to a vendor if you need targeting.
DB-backed flags
create table public.feature_flags (
key text primary key,
enabled_globally boolean not null default false,
enabled_user_ids uuid[] not null default array[]::uuid[],
enabled_org_ids uuid[] not null default array[]::uuid[],
rollout_percent int not null default 0 check (rollout_percent between 0 and 100),
updated_at timestamptz not null default now()
);
alter table public.feature_flags enable row level security;
create policy "anyone_authenticated_can_read_flags" on public.feature_flags
for select to authenticated using (true);Write access via service role only (admin UI / SQL editor).
Resolver
export function isFlagOn(flag: FeatureFlag, ctx: { userId?: string; orgId?: string }): boolean {
if (flag.enabled_globally) return true;
if (ctx.userId && flag.enabled_user_ids.includes(ctx.userId)) return true;
if (ctx.orgId && flag.enabled_org_ids.includes(ctx.orgId)) return true;
if (flag.rollout_percent > 0 && ctx.userId) {
return hashPercent(`${flag.key}:${ctx.userId}`) < flag.rollout_percent;
}
return false;
}hashPercent should be a stable hash (e.g. djb2 mod 100) so the same user keeps the same bucket.
Hook
export function useFlag(key: string) {
const { user } = useUser();
const { flags } = useFlags();
return useMemo(
() => isFlagOn(flags[key] ?? defaultFor(key), { userId: user?.id, orgId: user?.org_id }),
[flags, key, user],
);
}Use:
{useFlag("new_dashboard") ? <NewDashboard /> : <OldDashboard />}Rules
- Default off in production; default on only after rollout finishes.
- Remove the old branch within 2–4 weeks of 100% rollout — flags accumulate as tech debt.
- Server-side gating for security-sensitive flags (don't trust the client).
- Document the flag key, owner, and expected removal date in code or a
FLAGS.md.
Kill switch
For features that can break the app (new payment flow, new auth provider), ensure the flag check happens before the risky code path so flipping the flag instantly reverts behavior.
Avoid
- Hundreds of long-lived flags — clean up after rollout.
- Different flag keys for the same concept across client and server.
- Targeting by email substring in production code.
- Flags that gate styling only — use CSS instead.
Checklist
- Flag has a default and an owner.
- Old branch removed after 100% rollout.
- Server enforces security-sensitive flags.
- Toggle works without a deploy.
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
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.

