flag-prune

Documentation - flag-prune

Replace known feature-flag values and remove the code that can no longer run. Start with a preview, inspect the diff, then write the result.

For AI tools and documentation crawlers, see llms.txt.

Start here

Goal Page
Remove one flag for the first time Getting started
Fit the tool into a full cleanup pipeline Recommended workflow
Remove flags from a specific feature flag SDK Provider guides
Express a hook, client method, imported constant, variant, or member Flag rules
Copy a complete command for a common migration Recipes
Review every command-line option CLI reference
Run in a pull request or CI pipeline CI and automation
Integrate the transform in another tool Library API
Understand what the codemod will and will not remove Safety guarantees
Diagnose a rule that did not match Troubleshooting

Mental model

Every run has three stages:

  1. Match exact configured flag reads. Matching is binding-aware and does not replace shadowed locals.
  2. Replace each matched read with its configured primitive value while preserving required evaluation.
  3. Simplify expressions and control flow repeatedly until the output reaches a fixed point.

For example:

const variant = getVariant("checkout")

if (variant === "treatment") {
  showNewCheckout()
} else {
  showCurrentCheckout()
}

With this rule:

--set 'getVariant("checkout")=treatment'

The result is:

showNewCheckout()

The now-unused variant binding and dead branch are removed as part of the same transform.

flag-prune is one deterministic step in a larger cleanup. A full pass is:

  1. Run in dry-run mode, which is the default.
  2. Review the unified diff and warnings.
  3. Rerun with --write.
  4. Run your typecheck, lint, format, and tests.
  5. Run a dead-code removal tool for unused files and exports.
  6. Optionally finish with an LLM pass for readability and scoping.
  7. Rerun the same flag-prune command. A completed migration should be a no-op.

See Recommended workflow for the full pipeline, an LLM cleanup prompt, and examples.

Reference map

Guides

Reference