launchdarkly-flag-cleanup

작성자: launchdarkly

프로덕션 동작을 유지하면서 코드에서 기능 플래그를 안전하게 제거합니다. 사용자가 코드에서 플래그를 제거하거나

npx skills add https://github.com/launchdarkly/agent-skills --skill launchdarkly-flag-cleanup

LaunchDarkly Flag Cleanup

You're using a skill that will guide you through safely removing a feature flag from a codebase while preserving production behavior. Your job is to explore the codebase to understand how the flag is used, query LaunchDarkly to determine the correct forward value, remove the flag code cleanly, and verify the result.

If you haven't already identified which flag to clean up, use the flag discovery skill first to audit the landscape and find candidates.

Prerequisites

This skill requires the remotely hosted LaunchDarkly MCP server to be configured in your environment.

Required MCP tools:

  • check-removal-readiness: detailed safety check (orchestrates flag config, cross-env status, dependencies, code references, and expiring targets in parallel)
  • get-flag: fetch flag configuration for a specific environment

Optional MCP tools:

  • archive-flag: archive the flag in LaunchDarkly after code removal
  • delete-flag: permanently delete the flag (irreversible, prefer archive)

Core Principles

  1. Safety First: Always preserve current production behavior.
  2. LaunchDarkly as Source of Truth: Never guess the forward value. Query the actual configuration.
  3. Follow Conventions: Respect existing code style and structure.
  4. Minimal Change: Only remove flag-related code. No unrelated refactors.

Workflow

Step 1: Explore the Codebase

Before touching LaunchDarkly or removing code, understand how this flag is used in the codebase.

  1. Find all references to the flag key. Search for the flag key string (e.g., new-checkout-flow) across the codebase. Check for:

    • Direct SDK evaluation calls (variation(), boolVariation(), useFlags(), etc.)
    • Constants/enums that reference the key
    • Wrapper/service patterns that abstract the SDK
    • Configuration files, tests, and documentation
    • See SDK Patterns for the full list of patterns by language
  2. Understand the branching. For each reference, identify:

    • What code runs when the flag is true (or variation A)?
    • What code runs when the flag is false (or variation B)?
    • Are there side effects, early returns, or nested conditions?
  3. Note the scope. How many files, components, or modules does this flag touch? A flag used in one if block is simpler than one threaded through multiple layers.

Step 2: Run the Removal Readiness Check

Use check-removal-readiness to get a detailed safety assessment. This single tool call orchestrates multiple checks in parallel:

  • Flag configuration and targeting state
  • Cross-environment status
  • Dependent flags (prerequisites)
  • Expiring targets
  • Code reference statistics

The tool returns a readiness verdict:

safe: No blockers or warnings. Proceed with removal.

caution: No hard blockers but warnings exist (e.g., code references in other repos, expiring targets scheduled, flag marked as permanent). Present warnings and let the user decide.

blocked: Hard blockers prevent safe removal (e.g., dependent flags, actively receiving requests, targeting is on with active rules). Present blockers: the user must resolve them first.

Step 3: Determine the Forward Value

Use get-flag to fetch the flag configuration in each critical environment. The forward value is the variation that replaces the flag in code.

ScenarioForward Value
All critical envs ON, same fallthrough, no rules/targetsUse fallthrough.variation
All critical envs OFF, same offVariationUse offVariation
Critical envs differ in ON/OFF stateNOT SAFE: stop and inform the user
Critical envs serve different variationsNOT SAFE: stop and inform the user

Step 4: Present the Cleanup Plan

Before modifying any code, present a summary to the user and wait for confirmation:

  1. The forward value — which variation will be hardcoded and why (based on the flag's current state).
  2. All code references found — file paths and line numbers from Step 1.
  3. Planned changes — for each reference, describe what will be removed and what will be kept.
  4. Readiness verdict — the result from check-removal-readiness (safe, caution, or blocked) and any warnings.
  5. LaunchDarkly action — confirm the flag will be archived after code changes are complete.

Do not proceed with code changes until the user explicitly confirms.

Step 5: Remove the Flag from Code

Now execute the removal using what you learned in Step 1.

  1. Replace flag evaluations with the forward value.

    • Preserve the code branch matching the forward value
    • Remove the dead branch entirely
    • If the flag value was assigned to a variable, replace the variable with the literal value or inline it
  2. Clean up dead code.

    • Remove imports, constants, and type definitions that only existed for the flag
    • Remove functions, components, or files that only existed for the dead branch
    • Check for orphaned exports, hooks, helpers, styles, and test files
    • If the repo uses an unused-export tool (Knip, ts-prune, lint rules), run it and remove any flag-related orphans
  3. Don't over-clean.

    • Only remove code directly related to the flag
    • Don't refactor, optimize, or "improve" surrounding code
    • Don't change formatting or style of untouched code

Example transformation (boolean flag, forward value = true):

// Before
const showNewCheckout = await ldClient.variation('new-checkout-flow', user, false);
if (showNewCheckout) {
  return renderNewCheckout();
} else {
  return renderOldCheckout();
}

// After
return renderNewCheckout();

Step 6: Create Pull Request

Use the template in references/pr-template.md for a structured PR description. The PR should clearly communicate:

  • What flag was removed and why
  • What the forward value is and why it's correct
  • The readiness assessment results (from check-removal-readiness)
  • What code was removed and what behavior is preserved
  • Whether other repos still reference this flag

Step 7: Verify

Before considering the job done:

  1. Code compiles and lints. Run the project's build and lint steps.
  2. Tests pass. If the flag was used in tests, the tests should be updated to reflect the hardcoded behavior.
  3. No remaining references. Search the codebase one more time for the flag key to make sure nothing was missed.
  4. PR is complete. The description covers the readiness assessment, forward value rationale, and any cross-repo coordination needed.

Edge Cases

SituationAction
Flag not found in LaunchDarklyInform user, check for typos in the key
Flag already archivedAsk if code cleanup is still needed (flag is gone from LD but code may still reference it)
Multiple SDK patterns in codebaseSearch all patterns: variation(), boolVariation(), variationDetail(), allFlags(), useFlags(), plus any wrappers
Dynamic flag keys (flag-${id})Warn that automated removal may be incomplete: manual review required
Different default values in code vs LDFlag as inconsistency in the PR description
Orphaned exports/files remain after removalRun unused-export checks and remove dead files

What NOT to Do

  • Don't change code unrelated to flag cleanup.
  • Don't refactor or optimize beyond flag removal.
  • Don't remove flags still being actively rolled out.
  • Don't guess the forward value: always query LaunchDarkly.

After Cleanup

Once the PR is merged and deployed:

  1. Archive the flag in LaunchDarkly using archive-flag. Archival is reversible; deletion is not. Always archive first.
  2. Notify other teams if check-removal-readiness reported code references in other repositories.
  3. If the flag had targeting changes pending, they can be ignored: the flag is being removed.

References

launchdarkly의 다른 스킬

aiconfig-agent-graphs
launchdarkly
에이전트 그래프를 생성하고 관리합니다 — 핸드오프 로직이 있는 엣지로 연결된 AI 구성의 방향 그래프입니다. 구성이 포함된 다중 에이전트 워크플로우를 구축할 때 사용합니다.
official
aiconfig-ai-metrics
launchdarkly
기존 코드베이스에 LaunchDarkly AI Config 추적을 계측합니다. 4단계 사다리(관리형 러너 → 제공자 패키지 → 사용자 정의 추출기 +…)를 따라 진행됩니다.
official
aiconfig-create
launchdarkly
LaunchDarkly에서 AI Config를 생성하고 구성합니다. 에이전트 모드와 완료 모드 중 선택하고, config를 생성하며, 모델과 프롬프트가 포함된 변형을 추가하는 데 도움을 줍니다.
official
aiconfig-custom-metrics
launchdarkly
AI Configs에 대한 맞춤형 비즈니스 메트릭을 생성, 추적, 검색, 업데이트 및 삭제합니다. 전체 수명 주기를 다룹니다: API를 통해 메트릭 종류를 정의하고, SDK를 통해 이벤트를 전송하며,…
official
aiconfig-migrate
launchdarkly
하드코딩된 LLM 프롬프트가 포함된 애플리케이션을 완전한 LaunchDarkly AI Configs 구현체로 마이그레이션하는 다섯 단계: 코드 감사, 호출 래핑, 이동…
official
aiconfig-online-evals
launchdarkly
AI Config 변형에 판정기를 연결하여 자동 LLM-as-a-judge 평가를 수행합니다. 맞춤형 판정기를 생성하고, 샘플링 비율을 구성하며, 품질 점수를 모니터링할 수 있습니다.
official
aiconfig-projects
launchdarkly
코드베이스에서 LaunchDarkly 프로젝트를 설정하기 위한 가이드입니다. 스택을 평가하고, 적절한 접근 방식을 선택하며, 프로젝트 관리를 통합하는 데 도움을 줍니다…
official
aiconfig-snippets
launchdarkly
프롬프트 스니펫을 생성하고 관리합니다 — AI Config 변형 프롬프트 내에서 참조되는 재사용 가능한 텍스트 블록입니다. 일반적인 지침, 페르소나, 가드레일을 유지합니다…
official