/vercel:flags-sdkfrom vercel
Comprehensive guide for implementing feature flags and A/B tests using the Flags SDK (the `flags` npm package) and Vercel Flags (Vercel's feature flags platform, managed via dashboard or `vercel flags` CLI). Use when: (1) Creating or declaring feature flags with `flag()`, (2) Using Vercel Flags with `vercelAdapter()` or the `vercel flags` CLI (`add`, `list`, `enable`, `disable`, `inspect`, `archive`, `rm`, `sdk-keys`), (3) Setting up feature flag providers/adapters (Vercel, Statsig, LaunchDarkly, PostHog, GrowthBook, Hypertune, Edge Config, OpenFeature, Flagsmith, Reflag, Split, Optimizely, or custom adapters), (4) Implementing precompute patterns for static pages with feature flags, (5) Setting up evaluation context with `identify` and `dedupe`, (6) Integrating the Flags Explorer / Vercel Toolbar, (7) Working with feature flags in Next.js (App Router, Pages Router, Middleware) or SvelteKit, (8) Writing custom adapters, (9) Encrypting/decrypting flag values for the toolbar, (10) Any task involving the `flags`, `flags/next`, `flags/sveltekit`, `flags/react`, or `@flags-sdk/*` packages. Triggers on: feature flags, A/B testing, experimentation, flags SDK, flag adapters, precompute flags, Flags Explorer, feature gates, flag overrides, Vercel Flags, vercel flags CLI, vercel flags add, vercel flags list, vercel flags enable, vercel flags disable.
Trending skills
7-day visitors to each skill page
Ships in vercel. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
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.
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();
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.
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(),
});
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.
Check the project state to decide which steps you can skip:
flags in package.json? → Skip install (step 1).vercel/ directory exist? → Project is linked, skip vercel link in step 2.env.local contain FLAGS=? → Env vars already pulled, skip step 3flags.ts (or lib/flags.ts, src/flags.ts) exist? → Add to it rather than creating from scratch (step 4)app/.well-known/vercel/flags/route.ts exist? → Flags Explorer already set up, skip step 6Install 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 .vercel directory in the project root. If it doesn't exist, run vercel link first.
Pull environment variables: Run vercel env pull to write FLAGS and FLAGS_SECRET to .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) using vercelAdapter():
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 Flags Explorer (if not already present): Create app/.well-known/vercel/flags/route.ts — see the Flags Explorer setup section below.
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.
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.
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; },
});
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);
},
});
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 references/providers.md for all supported adapters.
| Parameter | Type | Description |
|---|---|---|
key | string | Unique flag identifier |
decide | function | Resolves the flag value |
defaultValue | any | Fallback if decide returns undefined or throws |
description | string | Shown in Flags Explorer |
origin | string | URL to manage the flag in provider dashboard |
options | { label?: string, value: any }[] | Possible values, used for precompute + Flags Explorer |
adapter | Adapter | Provider adapter implementing decide and origin |
identify | function | Returns evaluation context (entities) for decide |
Wrap shared functions (especially identify) in dedupe to run them once per request:
import { dedupe } from 'flags/next';
const identify = dedupe(({ cookies }) => {
return { user: { id: cookies.get('uid')?.value } };
});
Note: dedupe is not available in Pages Router.
// app/.well-known/vercel/flags/route.ts
import { getProviderData, createFlagsDiscoveryEndpoint } from 'flags/next';
import * as flags from '../../../../flags';
export const GET = createFlagsDiscoveryEndpoint(async () => {
return getProviderData(flags);
});
When using a third-party provider alongside Vercel Flags, combine their data with mergeProviderData. Each provider adapter exports its own getProviderData — see the provider-specific examples in references/providers.md.
// src/hooks.server.ts
import { createHandle } from 'flags/sveltekit';
import { FLAGS_SECRET } from '$env/static/private';
import * as flags from '$lib/flags';
export const handle = createHandle({ secret: FLAGS_SECRET, flags });
Required for precompute and Flags Explorer. Must be 32 random bytes, base64-encoded:
node -e "console.log(crypto.randomBytes(32).toString('base64url'))"
Store as FLAGS_SECRET env var. On Vercel: vc env add FLAGS_SECRET then vc env pull.
Use precompute to keep pages static while using feature flags. Middleware evaluates flags and encodes results into the URL via rewrite. The page reads precomputed values instead of re-evaluating.
High-level flow:
precompute(flagGroup) in middleware, get a code string/${code}/original-pathcode: await myFlag(code, flagGroup)For full implementation details, see framework-specific references:
Create an adapter factory that returns an object with origin and decide. For the full pattern (including default adapter and singleton client examples), see references/providers.md.
For keeping flag data confidential in the browser (used by Flags Explorer):
| Function | Purpose |
|---|---|
encryptFlagValues | Encrypt resolved flag values |
decryptFlagValues | Decrypt flag values |
encryptFlagDefinitions | Encrypt flag definitions/metadata |
decryptFlagDefinitions | Decrypt flag definitions |
encryptOverrides | Encrypt toolbar overrides |
decryptOverrides | Decrypt toolbar overrides |
All use FLAGS_SECRET by default. Example:
import { encryptFlagValues } from 'flags';
import { FlagValues } from 'flags/react';
async function ConfidentialFlags({ values }) {
const encrypted = await encryptFlagValues(values);
return <FlagValues values={encrypted} />;
}
import { FlagValues, FlagDefinitions } from 'flags/react';
// Renders script tag with flag values for Flags Explorer
<FlagValues values={{ myFlag: true }} />
// Renders script tag with flag definitions for Flags Explorer
<FlagDefinitions definitions={{ myFlag: { options: [...], description: '...' } }} />
Detailed framework and provider guides are in separate files to keep context lean:
flags, flags/react, flags/next, and flags/sveltekitWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ulpi-io/plugin-marketplace --plugin vercel24 skills in this plugin
/add-provider-packageGuide for adding new AI provider packages to the AI SDK. Use when creating a new @ai-sdk/<provider> package to integrate an AI service into the SDK./ai-elementsBuild AI chat interfaces using ai-elements components — conversations, messages, tool displays, prompt inputs, and more. Use when the user wants to build a chatbot, AI assistant UI, or any AI-powered chat interface./ai-sdkAnswer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like generateText, streamText, ToolLoopAgent, embed, or tools, (2) Want to build AI agents, chatbots, RAG systems, or text generation features, (3) Have questions about AI providers (OpenAI, Anthropic, Google, etc.), streaming, tool calling, structured output, or embeddings, (4) Use React hooks like useChat or useCompletion. Triggers on: "AI SDK", "Vercel AI SDK", "generateText", "streamText", "add AI to my app", "build an agent", "tool calling", "structured output", "useChat"./authoring-skillsHow to create and maintain agent skills in .agents/skills/. Use when creating a new SKILL.md, writing skill descriptions, choosing frontmatter fields, or deciding what content belongs in a skill vs AGENTS.md. Covers the supported spec fields, description writing, naming conventions, and the relationship between always-loaded AGENTS.md and on-demand skills.
/building-componentsGuide for building modern, accessible, and composable UI components. Use when building new components, implementing accessibility, creating composable APIs, setting up design tokens, publishing to npm/registry, or writing component documentation./capture-api-response-test-fixtureCapture API response test fixture.