Skip to main content

Claude Code Prompt to Implement a Feature Flag System

Generate a complete feature flag system from one prompt: rollout service, targeting rules, kill switch, per-variant metrics, tests, and a cleanup policy.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt turns Claude Code into a feature-flag engineer that builds the whole system end to end, not just the on/off check. You hand it a feature name, your framework, and a backend, and it scaffolds the flag service, writes the flag definition with targeting rules, instruments the integration points you name, and wires a kill switch for instant disable — the ten numbered deliverables run from the service layer all the way to unit tests for both flag states, including the admin UI or API you'll use to manage flags once they're live.

It works because it forces the parts teams usually skip. Most flag code rots: a flag ships, the rollout hits 100%, and the dead if/else lives forever. By baking in a cleanup checklist, a lifecycle policy with a max_age, a naming convention, and a documentation template, the prompt treats every flag as temporary by default. Demanding per-variant metrics and tests for both states also keeps Claude from generating the happy-path-only instrumentation that makes flags impossible to measure or safely remove.

When to use it

  • Shipping a risky feature behind a progressive rollout, starting at a low initial_rollout% and ramping with a kill switch ready.
  • Running an A/B test where you need clean per-variant metric tracking, not just a boolean toggle.
  • Adding flags to a codebase that has none, and you want a convention and lifecycle policy from day one.
  • Decoupling deploy from release so you can merge to main without exposing unfinished work.
  • Targeting a specific user segment first — internal staff, beta cohort, a single region — before going wide.
  • Auditing flag debt: generate the cleanup checklist for flags that have outlived their max_age.

Example output

src/featureflags/FlagService.php   # LaunchDarkly-backed provider, getVariant(flag, user)
flags/checkout_v2_redesign.yaml    # boolean, 10% rollout, segment: [internal, beta-eu]
  → instrumented: CheckoutController@show, cart.blade.php, OrderObserver

Kill switch:  flag('checkout_v2_redesign')->disable()   // bypasses cache, instant
Metrics:      conversion_rate, p95_latency  tracked per variant → StatsD
Management:   GET/PATCH /admin/flags  (toggle, rollout %, segments)

Cleanup checklist (max_age: 30d, created 2026-06-19):
  [ ] Remove 3 code paths in CheckoutController, OrderObserver
  [ ] Delete flag definition + tests
Tests: FlagOnTest, FlagOffTest, SegmentTargetingTest  (PASS)

Pro tips

  • Set initial_rollout to 0%, not 5%. Ship the flag fully off, verify the kill switch and metrics fire in production, then ramp. A flag you can't turn off safely is worse than no flag.
  • Match flag_backend to your real constraints: a config/DB backend is fine for kill switches, but percentage rollouts and segments need a backend with consistent hashing (same user → same variant), so name LaunchDarkly, Unleash, or Flagsmith explicitly.
  • Make metrics a guardrail metric plus a goal metric (e.g. p95_latency and conversion_rate). One number can't tell you if the new variant won without quietly breaking something else.
  • Treat max_age as a hard expiry, not a suggestion — pair this prompt with a scheduled "expired flags" report so the cleanup checklist actually gets executed instead of bookmarked.
  • Pin a strict flag_naming_convention (e.g. team_feature_purpose) up front; once you have 50 flags, an inconsistent namespace makes targeting rules and cleanup a guessing game.

Frequently Asked Questions

Does this prompt depend on a specific flag platform like LaunchDarkly?
No. The backend is the [flag_backend] variable, so you can target LaunchDarkly, Unleash, Flagsmith, a database table, or a config file. That said, name a real backend — percentage rollouts and segment targeting need consistent hashing so a given user always gets the same variant, which a naive config toggle won't give you.
Will it remove the old code after a flag is fully rolled out?
It generates the cleanup checklist and a lifecycle policy with a [max_age], and lists exactly which code paths and tests to delete — but it produces the plan, it doesn't auto-delete on a timer. Run the prompt again pointing at the rolled-out flag, or feed the checklist back to Claude Code to execute the removal in a separate, reviewable pass.
Why does it insist on unit tests for both flag states?
A flag has two live code paths and both ship to production, so testing only the enabled variant leaves the fallback untested — exactly the path your kill switch drops users onto during an incident. Testing both states is also what makes later cleanup safe: you can prove the surviving branch still behaves correctly before you delete the other.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Claude Code Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support