vercel/vercel-plugin/flags-sdk
Claude Code and agent skill by vercel/vercel-plugin
- vendor
Checking that the SKILL.md file is still in the repository.
Implement feature flags in Next.js or SvelteKit code with the Flags SDK (`flags` npm package). Use when installing or configuring the SDK, declaring flags with `flag()`, wiring a provider adapter (`@flags-sdk/vercel`, Statsig, LaunchDarkly, PostHog, GrowthBook, Global Config, OpenFeature, and others), using `identify`, `dedupe`, or `evaluate`, keeping pages static with precompute, setting up Flags Explorer, or encrypting flag values. For planning a flag, Vercel Flags rollouts and experiments, t…
Install
npx vskill@latest install vercel/vercel-plugin/flags-sdkSKILL.md
The same SKILL.md was published earlier as vercel/vercel-plugin/flags-sdk.
Set up and use the 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; its adapter is @flags-sdk/vercel.
- Docs: https://flags-sdk.dev
- Repo: https://github.com/vercel/flags
This skill covers the code. Planning a flag, choosing between the Flags SDK, @vercel/flags-core, and OpenFeature, and managing flags in the dashboard or with the vercel flags CLI belong to the vercel-flags skill. Archiving a flag, deleting it, or removing a variant requires the checks in that skill (remove the code first, confirm no evaluations over the Skew Protection window, archive before rm); do not run those commands without it. If it is not available, suggest npx skills add vercel/flags@vercel-flags (do not auto-install) and run vercel flags <cmd> --help in the meantime. For a project on another framework, @vercel/flags-core replaces this SDK (Core SDK).
When the user asks to install, configure, or set up the SDK, follow Set up the SDK (including vercel env pull when .env.local is missing). When they ask to add a flag to the code, follow Create a flag or Add a flag that already exists on Vercel. Inside an app repository, treat an ambiguous request as the full flow. Do not leave CLI steps as "next steps" for the user; execute them yourself.
Core concepts
Flags as code
Each flag is declared as a function. No string keys at call sites:
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.
Version note: The SDK is published asflags(renamed from@vercel/flags; that old name still appears in changelog history).flags4.2.0+ accepts the adapter factory by reference (adapter: vercelAdapter) and resolves it once per declaration. Older versions require calling it (adapter: vercelAdapter()). The called form still works on new versions, so prefer the shorthand unless you're targetingflags< 4.2.0.
Set up the SDK
One-time project setup. Run this when the Flags SDK is not installed yet, or when Toolbar / Flags Explorer / .env.local are missing. Skip any step that is already done.
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) - Is the project linked? → Skip
vercel linkin step 2 - Does
.env.localcontainVERCEL_OIDC_TOKEN=(or aFLAGS=SDK key)? → Env vars already pulled, skip step 3 - Is
@vercel/toolbarinpackage.json? → Skip toolbar setup (step 4) - Does
flags.ts(orlib/flags.ts,src/flags.ts) exist? → Skip creating it (step 5) - Does
app/.well-known/vercel/flags/route.tsexist? → Flags Explorer already set up, skip step 6
Steps
- Install packages (if not already in
package.json):
``bash pnpm i flags @flags-sdk/vercel ``
- Link the project to Vercel (required for
vercel env pulland local OIDC token refresh):
> Prerequisite: The Vercel CLI must be installed and authenticated. If it is not installed, run pnpm i -g vercel. For authentication or linking issues, follow the vercel-cli skill if it's already available. If it isn't, suggest the user install it with npx skills add vercel/vercel@vercel-cli (don't auto-install it) and rely on vercel <command> --help in the meantime.
Verify the link with vercel project inspect --non-interactive and check the reported owner and project name; a .vercel/ directory alone does not prove a link. If it reports link_required, run vercel link. If the user named a project or team and the output differs, stop and ask instead of relinking.
- Pull environment variables: If
.env.locallacksVERCEL_OIDC_TOKEN=, follow Pull environment variables.
- 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.
- Ensure `flags.ts` exists: If missing, create
flags.ts(orlib/flags.ts/src/flags.tsto match the project) withexport {}so TypeScript treats it as a module. Flags Explorer imports this file — create it before the discovery route.
- Set up Flags Explorer (if not already present): Create
app/.well-known/vercel/flags/route.ts— see Flags Explorer setup. Do this only afterflags.tsexists. Point the import at the real flags file path (the snippet assumes rootflags.ts).
Pull environment variables
vercel env pull writes the Development credentials to .env.local: the Vercel OIDC token that vercelAdapter uses locally (deployments receive it automatically, Getting started) and the Development FLAGS_SECRET for Flags Explorer and overrides. Run it when:
.env.locallacksVERCEL_OIDC_TOKEN=(or aFLAGS=SDK key)- you created the project's first flag; activating Vercel Flags creates a
FLAGS_SECRETper environment - local evaluation fails with an authentication error; the SDK refreshes an expired token through the linked project, re-pulling is the fallback
Use SDK keys (FLAGS) for apps outside Vercel or to select an environment explicitly (SDK Keys). To read another same-team project's flags on Vercel, use Project Connections with your project's OIDC token. If FLAGS_SECRET is still missing after the pull, generate it per FLAGS_SECRET.
Create a flag
When a user asks you to create or add a feature flag that does not exist on Vercel yet, follow these steps in order. If the flag was already created in the dashboard (the prompt says so, or vercel flags create reports the key exists), follow Add a flag that already exists on Vercel instead.
Before you start
- Complete Set up the SDK first if packages, Vercel link,
.env.local, Toolbar,flags.ts, or Flags Explorer are missing. Skip steps that are already done. - Does
.env.localcontainVERCEL_OIDC_TOKEN=? → Env vars already pulled; see Pull environment variables if local evaluation fails with an authentication error. - Does
flags.ts(orlib/flags.ts,src/flags.ts) exist? → Add to it rather than creating from scratch.
Steps
- Ensure the SDK is set up: Follow Set up the SDK if needed, then continue.
- Register the flag with Vercel: Run
vercel flags create <flag-key> --kind boolean --description "<description>"against the linked project, or pass--project <name-or-id>and--scope <team>. Pick the kind to match the flag's type parameter; it cannot be changed later.
- Pull environment variables: If this is the project's first flag, follow Pull environment variables again; activation created the
FLAGS_SECRET.
- Declare the flag in code: Add it to
flags.ts(or create the file if it doesn't exist) usingvercelAdapter:
```ts 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:
```tsx import { myFlag } from '../flags';
export default async function Page() { const enabled = await myFlag(); return <div>{enabled ? 'Feature on' : 'Feature off'}</div>; } ```
Add a flag that already exists on Vercel
Use this flow when the flag was created in the dashboard or by someone else, for example when the prompt says the flag "has already been created" or asks you to run vercel flags inspect. Do not run vercel flags create for an existing key.
- Ensure the SDK is set up: Follow Set up the SDK if needed.
- Read the definition: Run
vercel flags inspect <flag-key>. Note the kind, the variants (value and label), the description, and what each environment serves. - Pull environment variables: If
.env.locallacksVERCEL_OIDC_TOKEN=, follow Pull environment variables. - Declare the flag: Add it to
flags.tswithvercelAdapter. Map theinspectoutput:
key: the flag key exactly as printed- kind → type parameter:
boolean→flag<boolean>,string→flag<string>,number→flag<number>,json→flag<YourType> description: copy frominspectdefaultValue: the value to serve when the flag is archived or evaluation fails (usually what production serves today)options: optional; mirror the variants when you use precompute or want them listed in Flags Exploreridentify: add or reuse one when the flag has targeting, using the entity attributes configured in the dashboard (see Flag with evaluation context)
``ts export const welcomeMessage = flag<string>({ key: 'welcome-message', description: 'Copy shown on the landing page', defaultValue: 'control', adapter: vercelAdapter, }); ``
- Use the flag as in Create a flag step 5.
Vercel Flags adapter
@flags-sdk/vercel connects flag() declarations to Vercel Flags. vercelAdapter authenticates with the project's Vercel OIDC token and evaluates the configuration of the current environment. Use @flags-sdk/vercel version 1.6.0 or later and createVercelAdapter({ projectId }) for a connected same-team project's flags; see Project Connections. SDK keys (FLAGS) are for manual authentication, such as apps outside Vercel or selecting an environment explicitly. Activating Vercel Flags creates a FLAGS_SECRET per environment for Flags Explorer.
For user targeting, attribute types, custom adapter configuration, sharing a @vercel/flags-core client, and the Flags Explorer endpoint, see references/providers.md — Vercel.
Changing what a flag serves (enable, set, split, rollout, rules, archive) happens in the dashboard or with vercel flags, not in code. The vercel-flags skill covers those flows; vercel flags <cmd> --help lists the options.
Declaring flags
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 1 Nov 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/flags-sdk/SKILL.md
Popularity
- Repository stars
- 288
- Repository forks
- 60
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/vercel/vercel-plugin/flags-sdk)