Remove a LaunchDarkly feature flag from the codebase using the MCP server.
Removes a LaunchDarkly feature flag from the codebase and archives it in LaunchDarkly.
/plugin marketplace add gravity9-tech/pandora-marketplace/plugin install launchdarkly@pandora-marketplaceRemove a LaunchDarkly feature flag from the codebase using the MCP server.
Ensure the LaunchDarkly MCP server is configured in the Claude Code settings. The MCP server provides these tools:
list_feature_flags - List all flags in a projectget_feature_flag - Get details of a specific flagupdate_feature_flag - Update flag settings (including archive)delete_feature_flag - Permanently delete a flaglist_environments - List environments in a project$FLAG_NAME - The feature flag key to remove (required)$PROJECT_KEY - The LaunchDarkly project key (default: default)$ENVIRONMENT - Target environment for analysis: dev, staging, or production (default: dev)$DRY_RUN - If "true", only report what would be removed without making changes (default: false)Use the MCP server to verify the flag exists and gather its current state:
Use the LaunchDarkly MCP tool `get_feature_flag` with:
- projectKey: $PROJECT_KEY
- featureFlagKey: $FLAG_NAME
- env: $ENVIRONMENT (to get environment-specific configuration)
Capture and display:
If the flag doesn't exist, stop and inform the user.
Use the MCP server to understand the flag's state across all environments:
Use the LaunchDarkly MCP tool `list_environments` with:
- projectKey: $PROJECT_KEY
Then for each environment, use `get_feature_flag` with:
- projectKey: $PROJECT_KEY
- featureFlagKey: $FLAG_NAME
- env: [environment_key]
Build a summary table:
| Environment | Targeting | Default Variation | Rollout % | Last Modified |
|---|---|---|---|---|
| dev | ON | true | 100% | 2024-01-15 |
| staging | ON | true | 100% | 2024-01-20 |
| production | ON | true | 100% | 2024-02-01 |
Determine the "winner" variation: The variation serving 100% in production becomes the permanent behavior.
Search for all occurrences of the flag in the codebase:
Direct flag key references: Search for "$FLAG_NAME" and '$FLAG_NAME'
SDK usage patterns (customize based on client's stack):
ldClient.variation('$FLAG_NAME'useFlags().$FLAG_NAME or flags.$FLAG_NAMEuseLDClient() followed by variation callswithLDConsumer HOC usageuseVariant('$FLAG_NAME', defaultValue)useVariant('$FLAG_NAME')useVariant(LD_KEYS.'$FLAG_NAME_CAMEL_CASE') use camelCase version of flag nameuseVariant(LD_KEYS.'$FLAG_NAME_CAMEL_CASE', defaultValue) use camelCase version of flag name<LDConsumer> with flag accessConfiguration files: Check for flag references in:
.env filesconfig/*.json or config/*.yamlTest files: Find test mocks or fixtures:
jest.mock with LD referencesUse ripgrep for efficient searching:
# Find all files referencing the flag
rg -l "$FLAG_NAME" --type-add 'code:*.{ts,tsx,js,jsx,py,java,kt,go,rb,cs}' -t code
# Find with context
rg -C 3 "$FLAG_NAME" --type-add 'code:*.{ts,tsx,js,jsx,py,java,kt,go,rb,cs}' -t code
# Check config files
rg -l "$FLAG_NAME" --type-add 'config:*.{json,yaml,yml,env,properties,toml}' -t config
# Check test files
rg -l "$FLAG_NAME" --type-add 'test:*.{test,spec}.{ts,tsx,js,jsx}' -t test
For each file found, analyze:
What is the default/fallback behavior?
useVariant() calls - this is the fallbackAre there feature-flag-specific code paths?
Dependencies:
Test coverage:
Present a summary:
## Impact Analysis for: $FLAG_NAME
### Production State
- **Serving**: true (100% of users)
- **Action**: Keep the "enabled" code path, remove "disabled" path
### Files to Modify
| File | Line(s) | Pattern | Action |
|------|---------|---------|--------|
| src/components/Checkout.tsx | 45-52 | useFlags() conditional | Remove conditional, keep enabled branch |
| src/hooks/useFeature.ts | 12 | variation() call | Remove entire hook if only used for this flag |
| src/tests/Checkout.test.tsx | 23, 45 | LD mock | Remove mock setup |
### Potential Issues
- [ ] Flag is used in 3 files
- [ ] 2 test files need updating
- [ ] No prerequisite relationships found
Based on analysis, create a detailed removal plan:
## Removal Plan for: $FLAG_NAME
### 1. Code Changes Required
#### File: src/components/Checkout.tsx
**Current code:**
```tsx
const { $FLAG_NAME } = useVariant();
if ($FLAG_NAME) {
return <NewCheckoutFlow />;
} else {
return <LegacyCheckout />;
}
After removal:
return <NewCheckoutFlow />;
### Step 6: Execute Removal (if not dry run)
If `$DRY_RUN` is not "true":
#### 6a. Create a Feature Branch
```bash
git checkout -b cleanup/remove-flag-$FLAG_NAME
For each file identified:
Example transformation patterns:
Pattern 1: Simple Boolean Check
// Before
const { myFlag } = useVariant();
return myFlag ? <NewFeature /> : <OldFeature />;
// After (if myFlag was true in production)
return <NewFeature />;
Pattern 2: Variation Call
// Before
const showFeature = useVariant('my-flag', false);
if (showFeature) {
enableFeature();
}
// After (if flag was true in production)
enableFeature();
Pattern 3: Multivariate Flag
// Before
const variant = useVariant('my-flag', 'control');
switch(variant) {
case 'treatment-a': return <TreatmentA />;
case 'treatment-b': return <TreatmentB />;
default: return <Control />;
}
// After (if 'treatment-a' won)
return <TreatmentA />;
git add -A
git commit -m "chore: remove feature flag $FLAG_NAME
- Removed flag checks from [N] files
- Kept '$WINNING_VARIATION' behavior as permanent
- Updated [N] test files
Flag was serving 100% '$WINNING_VARIATION' in production since [date].
Safe to remove as behavior is now permanent."
Output a summary report:
## Feature Flag Removal Report
### Flag Details
- **Flag Key**: $FLAG_NAME
- **Project**: $PROJECT_KEY
- **Status**: [Completed / Dry Run]
- **Date**: [current date]
### Production State (Before Removal)
- Targeting: ON
- Serving: 100% → variation '$WINNING_VARIATION'
- Last modified: [date]
### Changes Made
#### Code Changes
- **Files modified**: [count]
- **Lines removed**: [count]
- **Tests updated**: [count]
#### Files Changed
| File | Changes |
|------|---------|
| src/components/Feature.tsx | Removed conditional, kept enabled branch |
| src/tests/Feature.test.tsx | Removed LD mock |
### LaunchDarkly Status
- **Action taken**: [Archived / Deleted]
- **Timestamp**: [datetime]
### Verification Steps
- [ ] Run full test suite locally
- [ ] Create PR for code review
- [ ] Deploy to staging environment
- [ ] Verify feature works as expected
- [ ] Deploy to production
- [ ] Monitor for any issues
- [ ] If archived, delete flag after [N] days
### Rollback Plan
If issues arise:
1. The flag still exists in LaunchDarkly (if archived)
2. Revert the git commit: `git revert [commit-hash]`
3. Restore flag from archive if needed
Before any removal, verify:
Get details about a specific flag:
projectKey (required): LaunchDarkly project keyfeatureFlagKey (required): The flag key to retrieveenv (optional): Filter by environmentList all flags in a project:
projectKey (required): LaunchDarkly project keyenv (optional): Include environment-specific detailstag (optional): Filter by tagfilter (optional): Filter expressionUpdate a flag (including archive):
projectKey (required): LaunchDarkly project keyfeatureFlagKey (required): The flag key to updatepatch (required): JSON Patch or Semantic Patch operationsPermanently delete a flag:
projectKey (required): LaunchDarkly project keyfeatureFlagKey (required): The flag key to deleteList environments in a project:
projectKey (required): LaunchDarkly project key