Killing feature flags that outlived their purpose — AI Code Toolkit

Killing feature flags that outlived their purpose

843 flags. The opinion piece: sunset is engineering, not cleanup. Every flag has cognitive + testing + latency + reasoning cost that compounds at scale. Flag typology matters — not all should die. The cleanup approach that worked (2 months, 843 → 218 flags). The ongoing discipline that prevents regrowth. Two near-incidents from removals we thought were trivial. What Claude Code changed.

By
Published Feb 23, 2027
11 min read

We had 843 feature flags. Nobody had asked for that number specifically; it's what happens when you don't have discipline. This is the opinion piece I would have written when we started the cleanup, if I'd had the perspective: sunset is engineering, not cleanup. Kill switches deserve care. Zombie flags aren't neutral. And the cost of leaving a flag isn't zero even when it's set to 100%.

How we got here

Feature flags feel free at creation time. You want to ship a risky feature; you gate it behind a flag; you roll out gradually; you monitor; you succeed. Ship the next feature. Move on. The flag stays because removing it feels like unnecessary work: it's set to 100%, it doesn't do anything, why touch it?

Multiply by every feature launched over 3 years. 12 experiments a quarter. 40 team members who each have shipped features behind flags. Nobody removed anything because it never felt urgent. And then one day: 843 flags. A pull request that touches auth logic has to reason about 6 flags. Onboarding new engineers takes a week just to explain the flag landscape.

The moment we noticed: someone shipped a bug because they misread which flag was current and which was legacy. The bug was small. But the lesson was: flag count wasn't neutral.

The argument I would make now

Every flag has a cost. Not much per-flag; cumulative significant.

Cognitive cost. Engineers reading code have to reason about which flags apply. More flags = more mental overhead per PR. Onboarding harder. Refactors more expensive.

Testing cost. Flag combinations grow combinatorially. Not every combination worth testing; but every code path touched by any flag has to be aware of the flag state during testing.

Latency cost. Flag evaluation isn't free; SDK evaluation adds microseconds per call. Times 843 flags in high-traffic code path: measurable.

Reasoning cost during incidents. Bug in production. Flag involved? Which one? At what percentage? Investigation slower with flag sprawl.

Deletion cost grows over time. Fresh flag deletion: quick PR. 3-year-old flag with unclear ownership: requires archaeology. Delay makes it worse.

The cost is small enough to ignore per-flag; large enough to matter at scale. Discipline compounds; neglect compounds harder.

Not all flags should die

Sunset discipline isn't “remove all flags.” Flag typology matters. Five common types:

Release toggle: gates unreleased code. Remove after 100% rollout + stability confirmed. Typical lifetime: days to weeks. Absolutely should die.

Experiment flag: A/B test. Remove after decision made + winning variant deployed. Typical lifetime: weeks. Should die.

Ops toggle / kill switch: emergency disable. Live for the lifetime of the feature. Should not die but should be periodically tested (does it still work?).

Permission toggle: user segmentation. Effectively product configuration. Long-lived; consider whether it belongs in a config system rather than flag system.

Circuit breaker flag: automatic disable when downstream fails. Long-lived; part of resilience discipline.

The sunset discipline applies to release + experiment flags primarily. Ops + permission + circuit breaker flags stay but should be reviewed for continued relevance annually.

Common mistake in sunset programs: aggressive deletion of ops toggles because “they're at 100%.” That's the point of an ops toggle. Not the same category.

The cleanup approach that worked

Two months, four engineers rotating.

Phase 1 (2 weeks): categorize. Query LaunchDarkly for all flags. Manual classification by type. About 60% release toggles, 15% experiments, 10% permissions, 8% ops toggles, 7% miscellaneous (some hard to classify).

Phase 2 (3 weeks): identify zombies. Release + experiment flags at 100% rollout + no recent evaluation change. About 320 candidate zombies. Cross-reference with code (does the flag still appear in code?). ~280 confirmed zombies (still in code but always at 100%, safe to remove).

Phase 3 (3 weeks): remove zombies. PR per team, batched. Remove flag references in code + delete flag in LaunchDarkly, same PR. Test in staging + canary rollout to production. About 60 PRs over 3 weeks; some remained in review longer.

Phase 4 (2 weeks): review remaining. About 40 flags neither clearly zombie nor clearly current. Team-by-team review; decision on each. Some kept + tagged with rationale + TTL; some deleted; some refactored (moved from flag to config).

Net result: 843 flags → 218 flags. Ongoing hygiene process to prevent regrowth.

The ongoing discipline

Cleanup was one-time; hygiene is forever.

Naming convention with domain prefix. billing_new_pricing_model, not new_pricing. Findable by domain; searchable in code; obvious ownership.

Mandatory ownership at creation. LaunchDarkly UI requires team tag. No untagged flags.

TTL by type. Release toggle: 30-day TTL default. Experiment: tied to experiment. Ops toggle: no TTL but annual review. LaunchDarkly custom field; monthly report of flags past TTL.

Automated stale detection. Weekly job: flags at 100% for >30 days with no code references + no negative evaluations = candidate for deletion. Report to owning team.

Sunset in the definition of done. Feature complete = feature shipped to 100% + flag removed. Not shipped 100%. This is the discipline that prevents regrowth.

Flag review in code review. Reviewer question: “how does this flag get removed?” Answer required. Not accepted: “we might need it later.”

What we almost broke doing this

Two near-incidents during cleanup:

Near-incident 1: we removed a flag that was set to 100% but had a targeting rule for admin users. Removing the flag removed the targeting rule; admin users started seeing the non-admin experience. Caught in canary; rolled back; investigated. Lesson: check targeting rules, not just rollout percentage.

Near-incident 2: we removed a flag that was “always on” but the code path checked the flag with a fail-safe default of “off.” SDK errors were rare but real; when they happened, our fail-safe served the wrong experience because the flag was gone. Caught in load test; changed the fail-safe to “on” before deletion.

These both fell into the category of “removing this flag isn't as trivial as it looks.” Sunset discipline includes reading the removal PR carefully.

What Claude Code changed

Cleanup happened before deep Claude Code adoption. Some pieces would have been faster today.

feature-flag-strategist subagent encodes the typology + sunset discipline. Teams starting today can inherit the framework; save the 6-month learning curve we went through.

launchdarkly MCP makes zombie identification queryable. Where we manually cross-referenced 843 flags, an MCP-driven prompt could produce the candidate list in minutes.

Removal PR generation. Once we knew a flag was zombie, the PR was mechanical: remove flag references + delete platform config. Claude Code drafts these; humans review. Would have compressed the 3-week Phase 3 significantly.

feature-flag-lint hook catches new hygiene violations at PR time (flag without owner, flag without TTL). Would have prevented the sprawl if we'd had it years ago.

What to do with this

Count your active flags. If under 100 with clear hygiene, you're fine. If between 100 and 300, review your hygiene discipline. If over 300, consider whether you have a sprawl problem.

Distinguish flag types before any cleanup. Sunset discipline for release + experiment flags; different treatment for ops + permission flags. Aggressive cleanup of ops toggles is a mistake.

If you're cleaning up: shadow-mode. Test removals in staging; canary in production; watch metrics. Removing flags isn't always trivial.

If you're preventing regrowth: sunset in definition of done. This is the discipline. Shipped is 100% + removed.

Combined with the feature-flag-strategist subagent and the Feature Flag Discipline Guide, this is what feature flag hygiene looks like when treated as engineering rather than cleanup. It takes discipline; it's worth it.

FAQ

Frequently asked

Not unusual:

  • Depends on scale.
  • Hygiene matters more.

Not all safe:

  • Ops toggles.
  • Targeting rules.

~4 engineer-weeks:

  • Rotating engineers.
  • Surfaced other cleanup.

Cultural issue:

  • Ship results.
  • Remove flag.
  • Decision written.

Culture + visibility:

  • DoD includes removal.
  • Automated stale detection.

Recreate:

  • Fresh flag cheap.
  • Stale flag expensive.

Net positive:

  • Surfaced pending experiments.
  • New experiments easier.