flags-sdk▌
vercel/flags · updated Apr 8, 2026
MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.
The Flags SDK (flags npm package) is a feature flags toolkit for Next.js and SvelteKit. It turns each feature flag into a callable function, works with any flag provider via adapters, and keeps pages static using the precompute pattern. Vercel Flags is the first-party provider, letting you manage flags from the Vercel dashboard or the vercel flags CLI.
Flags SDK
The Flags SDK (flags npm package) is a feature flags toolkit for Next.js and SvelteKit. It turns each feature flag into a callable function, works with any flag provider via adapters, and keeps pages static using the precompute pattern. Vercel Flags is the first-party provider, letting you manage flags from the Vercel dashboard or the vercel flags CLI.
- Docs: https://flags-sdk.dev
- Repo: https://github.com/vercel/flags
Core concepts
Flags as code
Each flag is declared as a function. No string keys at call sites:
import { flag } from 'flags/next';
export const exampleFlag = flag({
key: 'example-flag',
decide() { return false; },
});
const value = await exampleFlag();
Server-side evaluation
Flags evaluate server-side to avoid layout shift, keep pages static, and maintain confidentiality. Combine routing middleware with the precompute pattern to serve static variants from CDN.
Adapter pattern
Adapters replace decide and origin on a flag declaration, connecting your flags to a provider. Vercel Flags (@flags-sdk/vercel) is the first-party adapter. Third-party adapters are available for Statsig, LaunchDarkly, PostHog, and others.
import { flag } from 'flags/next';
import { vercelAdapter } from '@flags-sdk/vercel';
export const exampleFlag = flag({
key: 'example-flag',
adapter: vercelAdapter(),
});
Agent workflow: Creating a new flag
When a user asks you to create or add a feature flag, follow these steps in order. Do not leave CLI steps as "next steps" for the user — execute them yourself.
Before you start
Check the project state to adapt commands and decide which steps you can skip:
- Which lockfile is present (
pnpm-lock.yaml,package-lock.json,yarn.lock,bun.lockb)? → Adapt all package manager commands accordingly (pnpm add,npm install,yarn add,bun add). - Is
flagsinpackage.json? → Skip install (step 1) - Does
.vercel/directory exist? → Project is linked, skipvercel linkin step 2 - Does
.env.localcontainFLAGS=? → Env vars already pulled, skip step 3 - Does
flags.ts(orlib/flags.ts,src/flags.ts) exist? → Add to it rather than creating from scratch (step 4) - Is
@vercel/toolbarinpackage.json? → Skip toolbar setup (step 6) - Does
app/.well-known/vercel/flags/route.tsexist? → Flags Explorer already set up, skip step 7
Steps
-
Install packages (if not already in
package.json):pnpm i flags @flags-sdk/vercel -
Register the flag with Vercel: Run
vercel flags add <flag-key> --kind boolean --description "<description>".Prerequisite: The
vercel flagscommands require the Vercel CLI to be installed and authenticated. If the Vercel CLI is not installed, runpnpm i -g vercel. For authentication or linking issues, read and follow thevercel-cliskill. If it's not installed, runnpx skills add https://github.com/vercel/vercel --skill vercel-cli.Before running
vercel flags add, verify the project is linked to Vercel. Check for a.verceldirectory in the project root. If it doesn't exist, runvercel linkfirst. -
Pull environment variables: Run
vercel env pullto writeFLAGSandFLAGS_SECRETto.env.local. Without these environment variables,vercelAdapter()will not be able to evaluate flags. This step is mandatory after creating a flag. -
Declare the flag in code: Add it to
flags.ts(or create the file if it doesn't exist) usingvercelAdapter():import { flag } from 'flags/next'; import { vercelAdapter } from '@flags-sdk/vercel'; export const myFlag = flag({ key: 'my-flag', adapter: vercelAdapter(), }); -
Use the flag: Call it in your page or component and conditionally render based on the result:
import { myFlag } from '../flags'; export default async function Page() { const enabled = await myFlag(); return <div>{enabled ? 'Feature on' : 'Feature off'}</div>; } -
Set up the Vercel Toolbar (if not already present):
- Run
pnpm i @vercel/toolbar - Wrap
next.config.tswith the toolbar plugin - Render
<VercelToolbar />in the root layout See references/nextjs.md — Toolbar Setup for the full code.
- Run
-
Set up Flags Explorer (if not already present): Create
app/.well-known/vercel/flags/route.ts— see the Flags Explorer setup section below.
Vercel Flags
Vercel Flags is Vercel's feature flags platform. You create and manage flags from the Vercel dashboard or the vercel flags CLI, then connect them to your code with the @flags-sdk/vercel adapter. When you create a flag in Vercel, the FLAGS and FLAGS_SECRET environment variables are configured automatically.
To create a flag end-to-end, follow the Agent workflow above.
For the full Vercel provider reference — user targeting, vercel flags CLI subcommands, custom adapter configuration, and Flags Explorer setup — see references/providers.md.
Declaring flags
When using Vercel Flags, declare flags with vercelAdapter() as shown in the Agent workflow. For other providers, see references/providers.md. Below are the general flag() patterns.
Basic flag
import { flag } from 'flags/next'; // or 'flags/sveltekit'
export const showBanner = flag<boolean>({
key: 'show-banner',
description: 'Show promotional banner',
defaultValue: false,
options: [
{ value: false, label: 'Hide' },
{ value: true, label: 'Show' },
],
decide() { return false; },
});
Flag with evaluation context
Use identify to establish who the request is for. The returned entities are passed to decide:
import { dedupe, flag } from 'flags/next';
import type { ReadonlyRequestCookies } from 'flags';
interface Entities {
user?: { id: string };
}
const identify = dedupe(
({ cookies }: { cookies: ReadonlyRequestCookies }): Entities => {
const userId = cookies.get('user-id')?.value;
return { user: userId ? { id: userId } : undefined };
},
);
export const dashboardFlag = flag<boolean, Entities>({
key: 'new-dashboard',
identify,
decide({ entities }) {
if (!entities?.user) return false;
return ['user1', 'user2'].includes(entities.user.id);
},
});
Flag with another adapter
Adapters connect flags to third-party providers. Each adapter replaces decide and origin:
import { flag } from 'flags/next';
import { statsigAdapter } from '@flags-sdk/statsig';
export const myGate = flag({
key: 'my_gate',
adapter: statsigAdapter.featureGate((gate) => gate.value),
identify,
});
See AI-first code editor with Composer Before installing skills in Cursor, ensure your development environment meets these requirements: Execute the skills CLI command in your project's root directory to begin installation: The skills CLI fetches The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor: Confirm successful installation by checking the skill directory location: Reload or restart Cursor to activate flags-sdk. Access the skill through slash commands (e.g., We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use. Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment. Submit your Claude Code skill and start earning Create detailed user stories, acceptance criteria, and feature specs Example Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios Reduce spec writing time by 50%, ensure comprehensive coverage Research competitors, compare features, identify gaps Example Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities Complete competitive research in 2 hours instead of 2 days Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs Example Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale Make data-driven prioritization decisions faster Draft PRDs, status updates, and stakeholder presentations Example Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement Save 3-5 hours/week on communication overhead 30-60 minutes to see productivity improvements Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work. Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed. flags-sdk fits our agent workflows well — practical, well scoped, and easy to wire into existing repos. I recommend flags-sdk for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area. flags-sdk is among the better-maintained entries we tried; worth keeping pinned for repeat workflows. I recommend flags-sdk for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area. flags-sdk fits our agent workflows well — practical, well scoped, and easy to wire into existing repos. Keeps context tight: flags-sdk is the kind of skill you can hand to a new teammate without a long onboarding doc. We added flags-sdk from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront. Solid pick for teams standardizing on skills: flags-sdk is focused, and the summary matches what you get after install. flags-sdk has been reliable in day-to-day use. Documentation quality is above average for community skills. flags-sdk is among the better-maintained entries we tried; worth keeping pinned for repeat workflows. showing 1-10 of 32How to use flags-sdk on Cursor
Prerequisites
node --version)Execute installation command
flags-sdk from GitHub repository vercel/flags and configures it for Cursor.Select Cursor when prompted
Verify installation
/flags-sdk) or your agent's skill management interface.Security & Verification Notice
Additional Resources
List & Monetize Your Skill
Use Cases▌
User Story & Requirements Generation
Competitive Analysis
Roadmap Prioritization
Stakeholder Communication
Implementation Guide▌
Prerequisites
Time Estimate
Installation Steps
Common Pitfalls
Best Practices▌
✓ Do
✗ Don't
💡 Pro Tips
When to Use This▌
✓ Use When
✗ Avoid When
Learning Path▌
Discussion
Product Hunt–style comments (not star reviews)Ratings
4.6★★★★★32 reviews