This topic explains how to clean up flags you no longer need. LaunchDarkly helps you identify flags that you can remove from your code, then prompts you to archive these flags. Archiving a flag removes it from your Flags list in LaunchDarkly, without deleting it.
Cleaning up your flags is an important part of the flag lifecycle, and critical to helping reduce the technical debt that you may accumulate as you use flags throughout your organization.
When a flag is no longer being served to customers, and it is not a prerequisite for other flags, it may be time to archive it. Archiving a flag retires it from LaunchDarkly without deleting it. You can restore an archived flag if you need to, or find it to reference its configuration later.
LaunchDarkly recommends archiving a flag when all of the following are true:
These criteria are similar to the staleness definition in Flag health, but archiving uses additional archive checks to confirm a flag is safe to remove.
LaunchDarkly will not let you archive a flag that is a prerequisite for other flags.
When you archive a flag in LaunchDarkly, you should also remove the flag from your code. If your application evaluates an archived flag, LaunchDarkly serves the flag’s fallback value. This means it is crucial to remove all references to a flag from your code before you archive the flag. LaunchDarkly’s code references feature can help you quickly identify all the places a flag is referenced in your code. To learn more, read Code references.
When you are sure a flag is no longer needed, you can permanently remove it. Delete an archived flag from the Flags list. To learn more, read Deleting flags.
You can also use the REST API: Delete feature flag API
All flags exist in every environment for a project, but often only a few environments matter for your organization’s production processes. LaunchDarkly recommends archiving all flags that are ready to archive in your critical environments. However, archiving a flag will remove it from every environment in the project. Be certain you can archive a flag without any unintended impact.
LaunchDarkly uses archive checks to determine if a flag is ready to archive. The checks confirm whether the flag has code references, has been requested recently, is serving multiple variations, and whether it is a prerequisite for other flags. These checks run across all of your critical environments.
You can view flags that are ready to archive from the Flags list.
Here’s how:

The flag is archived and removed from the Flags list. You can find it in the archived Flags list. To learn more, read View and restore flags.
You can also customize the Cleanup shortcut. For example, you could update it to include only flags that are ready to archive and are also maintained by you or your team. To learn more about shortcuts, read Save shortcuts to filtered flags lists.
One of the archive checks confirms whether a flag has code references. To filter for flags that are ready for code removal, navigate to the Flags list, open the Filter menu, and use the Lifecycle filter Needs code removal. To learn more about code references, read Code references.
You can also find flags that are ready to archive on the Flags list:

You can also archive a flag from the flag’s settings page.
Here’s how to archive a flag from the flag’s settings page:
Navigate to the Flags list.
Hover on the flag you wish to archive, then click its three-dot overflow menu.
Click Manage flag settings. The flag’s Settings tab appears.
In the “Archive flag” section, click Archive. The “Archive this flag?” panel appears.

To learn how to resolve flag dependencies, read Resolve dependencies.
Choose the environments your team or customers depend on to confirm you can archive the flag from those environments without unintended consequences. Verify that the flag is not in use by reviewing its states in the flag archive fields:

The flag is archived and removed from the Flags list. You can find it in the archived Flags list. To learn more, read View and restore flags.
If end users request a flag after you archive it, the flag value that returns is the fallback value you defined in code.
There are three types of flag dependencies. These align with the archive checks LaunchDarkly runs to confirm whether a flag is ready to archive:
You cannot archive a flag that is a prerequisite for other flags. You must remove the flag as a prerequisite before you can archive it. Even if the flag’s dependent flags themselves are archived, the dependency will still block you from archiving the prerequisite flag. If you attempt to archive a prerequisite flag, LaunchDarkly prevents you from doing so.
The other two dependencies will not stop you from archiving a flag, but we recommend resolving them before you archive it.
To learn more about archive checks, read Description of checks.
Here is a screenshot of the “Archive this flag?” panel:

By default, the Flags list shows live flags only.
To view archived flags, click Filters from the Flags list and select “Archived” or “Deprecated” under “Lifecycle”:

To restore an archived flag:
When you restore a flag, it returns to evaluation like any other flag. Confirm that restoring it will not have any unintended impact.
If a flag is archived and no longer in use, you can permanently delete it from the Flags list.
You can also use the REST API: Delete feature flag API
Deleting a flag is permanent, so make sure your application no longer references it before you delete it.