Get started
Back to blog

Useful Cursor prompts for managing feature flags

Cursor understands your codebase. When you give it context about your feature flag setup, it can create flag checks, wire up targeting, and even clean up stale flags — all from a prompt.

This post is a collection of prompts we use daily with Flagify. Copy them, adapt them, save the ones you use most as .cursorrules snippets.

Setup: give Cursor context

Before the prompts work well, Cursor needs to know your flag setup. Create a .cursorrules file in your project root:

# Flagify Feature Flags

This project uses Flagify (@flagify/node, @flagify/react) for feature management.

## SDK Patterns

- Import from '@flagify/node' for server code, '@flagify/react' for client
- Use isEnabled() for boolean flags
- Use getValue<T>() for typed values (string, number, JSON)
- In React, use useFlag(), useVariant(), useFlagValue() hooks
- In NestJS, inject FlagifyService or use @FeatureFlag decorator
- Flag names use kebab-case: 'new-checkout-flow'
- Always provide a fallback value
- Always handle both enabled and disabled states

Or generate it automatically:

npx flagify ai-setup --tool cursor

Now the prompts.


Creating flags

Wrap a feature in a flag

Prompt: “Wrap the new recommendations section in ProductPage.tsx behind a feature flag called product-recommendations. Show a placeholder when the flag is off.”

Cursor will import useFlag, add the conditional rendering, and handle both states. Because .cursorrules tells it to use @flagify/react, it picks the right import.

Add a multivariate flag

Prompt: “Add a feature flag pricing-layout with variants ‘stacked’, ‘grid’, and ‘comparison’. Render a different PricingCard layout for each variant. Default to ‘stacked’.”

This generates a useVariant call with a switch statement covering all variants plus a sensible default.

Add a remote config value

Prompt: “Use a feature flag search-results-limit to control how many results SearchPage shows. Default to 20. Use the typed value hook.”

Cursor will use useFlagValue with the correct fallback type.


Server-side flags (Node / NestJS)

Gate an API endpoint

Prompt: “Gate the POST /api/exports endpoint behind a csv-export feature flag. Return 403 with a message when the flag is off.”

For a NestJS project, Cursor will use @RequireFlag and FeatureFlagGuard. For plain Express, it will add a middleware check with flagify.isEnabled().

Add user-targeted evaluation

Prompt: “Evaluate the premium-features flag with the current user’s context (id, email, plan) from the request. Return the evaluation result and reason.”

This generates a flagify.evaluate() call with the user object extracted from the request.

Add a flag to a NestJS handler as a parameter

Prompt: “Inject the max-upload-size flag as a number parameter in the UploadController.upload() handler. Default to 10.”

Cursor will add the @FeatureFlag({ key: 'max-upload-size', fallback: 10 }) decorator.


Cleanup and refactoring

Remove a stale flag

Prompt: “The old-navigation flag has been fully rolled out. Remove all references to it across the codebase. Keep the enabled code path and delete the disabled path.”

This is one of the most useful prompts. Cursor finds every useFlag('old-navigation'), isEnabled('old-navigation'), and conditional branch, then removes the flag while preserving the active code path.

Find all flags in the codebase

Prompt: “List every feature flag used in this project. Search for useFlag, useVariant, useFlagValue, isEnabled, getValue, getVariant, @FeatureFlag, and @RequireFlag calls. Show the flag key, file, and line number.”

A quick audit to find flags that might be candidates for cleanup.

Replace hardcoded values with flags

Prompt: “The retry count in ApiClient.ts is hardcoded to 3. Replace it with a feature flag api-retry-count that defaults to 3, so we can change it without a deploy.”

Cursor will add a getValue call with the existing hardcoded value as the fallback — zero behavior change by default.


Testing

Generate tests for a flagged feature

Prompt: “Write tests for DashboardController.getDashboard(). Test both states of the new-dashboard flag. Use FlagifyTestingModule.withFlags() to set flag values.”

Cursor will scaffold a test file with two cases — flag on and flag off — using the NestJS testing module.

Test a React component with different flag values

Prompt: “Write tests for ProductPage. Test that the recommendations section renders when product-recommendations is enabled, and that it does not render when disabled. Mock the useFlag hook.”


Rollouts and targeting

Add percentage rollout logic

Prompt: “Add a gradual rollout for new-search-engine. Start at 10% of users. Add a comment explaining how to increase the percentage from the Flagify dashboard.”

Cursor will add the flag check and a comment pointing to the dashboard for percentage changes — since rollout percentages are configured in the UI, not in code.

Add plan-based targeting

Prompt: “Gate the analytics dashboard behind the advanced-analytics flag. This should only be available to users on the ‘pro’ or ‘enterprise’ plan. Add the targeting context.”

For server-side code, Cursor will pass the user’s plan as an attribute in the evaluation context.


Tips for better results

  1. Be specific about the flag name. Cursor follows your naming convention better when you give it the exact key.

  2. Mention the SDK. Saying “use the React hook” or “use the NestJS decorator” removes ambiguity about which import to use.

  3. State the default behavior. “Default to 20” or “show a placeholder when off” tells Cursor what the fallback should be.

  4. Reference existing patterns. “Follow the same pattern as the useFlag call in SettingsPage.tsx” helps Cursor match your project’s style.

  5. Use .cursorrules for recurring context. Anything you repeat in prompts should go in the rules file instead.


Save your best prompts

If you find yourself using the same prompts repeatedly, add them as Cursor prompt files in .cursor/prompts/:

<!-- .cursor/prompts/add-feature-flag.md -->
Wrap the specified component or section behind a Flagify feature flag.

- Use useFlag() from @flagify/react for client components
- Use FlagifyService.isEnabled() for server code
- Always handle both enabled and disabled states
- Use kebab-case for flag names
- Add a fallback value

These show up in Cursor’s prompt picker, so your team can reuse them without memorizing the exact wording.

For more on setting up Flagify with AI tools, read the AI Tools documentation.