cleanup_flag
Remove feature flags from code while preserving the desired path, with step-by-step guidance for complete cleanup and testing.
Instructions
Remove a feature flag from the codebase while preserving the desired code path.
This tool provides comprehensive step-by-step instructions for safely removing feature flag code. It guides you through:
Finding all flag occurrences using Grep
Identifying different flag usage patterns (if-else, ternary, guards, etc.)
Removing flag checks while preserving the correct code path
Cleaning up unused imports and dead code
Verifying and testing the changes
When to use this tool:
After a feature flag has been rolled out to 100% and is no longer needed
When deprecating an experimental feature (preserve disabled path)
When cleaning up technical debt from old flags
After a kill switch is no longer necessary
Preserve Path Options:
"enabled": Keep code that runs when flag is true (most common for successful feature rollouts)
"disabled": Keep code that runs when flag is false (for removed experiments or kill switches)
If not provided: You will be instructed to ask the user which path to preserve
Workflow:
Call this tool with the flag name (optionally specify which path to preserve)
If preservePath not provided, you'll be instructed to ask the user via AskUserQuestion tool
Follow the returned instructions to search and remove flag code
Clean up imports and test the changes
Report summary of changes
Safety Features:
Comprehensive pattern identification (handles if-else, ternary, guards, etc.)
Language-agnostic guidance
Post-cleanup verification steps
Test execution reminders
Import cleanup guidance
This tool is inspired by the Unleash AI flag cleanup workflow used in production. See: https://github.com/Unleash/unleash/blob/main/.github/workflows/ai-flag-cleanup-pr.yml
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| flagName | Yes | Name of the feature flag to remove (e.g., "new-checkout-flow") | |
| preservePath | No | Optional: Which code path to preserve: "enabled" = keep code that runs when flag is true (typical for rollouts), "disabled" = keep code that runs when flag is false (for removed features). If not provided, you will be instructed to ask the user. | |
| files | No | Optional: Specific files to clean up. If not provided, searches entire codebase. Useful for partial cleanup or when you already know which files contain the flag. | |
| language | No | Optional: Programming language for specialized guidance (e.g., "typescript", "python", "go"). Auto-detected from files if not provided. |