> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Vega for flag cleanup

> This topic explains how to use Vega to identify and remove stale feature flags from your codebase, including automated scheduled cleanup.

**Developer**

**Federal docs**

> [!CAUTION]
>
> **Vega is not available in federal environments**
>
> To learn more, read [LaunchDarkly in federal environments](https://launchdarkly.com/docs/home/infrastructure/federal).

**EU docs**

> [!CAUTION]
>
> **Vega is not available in the LaunchDarkly European Union (EU) instance**
>
> To learn more, read [LaunchDarkly in the European Union (EU)](https://launchdarkly.com/docs/home/infrastructure/eu.md).

> [!WARNING]
>
> **GitHub account required**
>
> Vega for flag cleanup requires a connected GitHub account to create pull requests. To learn how to connect GitHub, read [Connecting Vega to GitHub](https://launchdarkly.com/docs/home/getting-started/vega-github.md).

Vega is the LaunchDarkly AI-powered agent. To use Vega, your role requires the [Vega actions](https://launchdarkly.com/docs/home/account/roles/role-actions.md#vega-actions). To learn more about Vega, including eligibility, pricing, and permissions, read [Vega](https://launchdarkly.com/docs/home/getting-started/vega).

Vega can help you identify and remove stale feature flags from your codebase. Stale flags accumulate technical debt, and most teams don't clean them up because the process is manual and error-prone. Vega automates safety checks and code changes, removing the main barriers to keeping flag counts manageable.

## How it works

To start a flag cleanup, you can either:

* Go to the **Flags** list, click the **three-dot** overflow menu on any flag, and select **Vega cleanup**.

![The three-dot overflow menu on a flag, with the Vega cleanup option.](https://mintcdn.com/launchdarkly/-8oCBkL_upxSWriH/images/tutorials/vega-flag-cleanup/open-dialog-list.png?fit=max\&auto=format\&n=-8oCBkL_upxSWriH\&q=85\&s=cd7d5b10665747b878d94a1d24b7b63e)

The three-dot overflow menu on a flag, with the Vega cleanup option.

* Or, click a flag in the **Flags** list, and then click **Start cleanup** in the **Vega cleanup** section of the sidebar.

![The Vega cleanup section on a flag's detail page, with the Start cleanup link.](https://mintcdn.com/launchdarkly/-8oCBkL_upxSWriH/images/tutorials/vega-flag-cleanup/open-dialog-individual.png?fit=max\&auto=format\&n=-8oCBkL_upxSWriH\&q=85\&s=d79f3997d996928e66cacd7c79d7fd6c)

The Vega cleanup section on a flag's detail page, with the Start cleanup link.

Either option opens the **Flag cleanup** modal, which shows a staleness analysis and lets you start the cleanup:

![The Flag cleanup modal, showing staleness analysis and the Start cleanup button.](https://mintcdn.com/launchdarkly/-8oCBkL_upxSWriH/images/tutorials/vega-flag-cleanup/flag-cleanup-modal.png?fit=max\&auto=format\&n=-8oCBkL_upxSWriH\&q=85\&s=9b7111b78a63c1db55c8fd1adfd48271)

The Flag cleanup modal, showing staleness analysis and the Start cleanup button.

After you start the cleanup, the cleanup job appears on the **Previous cleanups** tab of the "Flag cleanup" dialog. Vega then checks whether the flag has only a single variation being evaluated across all [critical environments](https://launchdarkly.com/docs/home/account/environment#critical-environments), and creates a GitHub pull request to remove the flag from your code.

## How Vega determines if a flag is safe to clean up

Vega follows this procedure to determine whether a flag is safe to remove:

1. **Queries your critical environments**: Vega identifies all environments marked as critical for your project.
2. **Checks flag evaluations**: Vega checks the flag's evaluations in these environments to confirm that the flag is "stale," meaning it serves the same variation across all critical environments.
3. **Takes action**:
   * If the flag is stale, Vega proceeds with code cleanup and creates a pull request.
   * If the flag is not stale, Vega still proceeds with code cleanup and creates a pull request. It lists the concern as a warning in the pull request description. You decide whether to merge the pull request.

## Tracking cleanup status

You can view a flag's cleanup status in the **Vega cleanup** section on the flag's detail page sidebar:

![The Vega cleanup section on a flag's detail page.](https://mintcdn.com/launchdarkly/-8oCBkL_upxSWriH/images/tutorials/vega-flag-cleanup/flag-cleanup-status.png?fit=max\&auto=format\&n=-8oCBkL_upxSWriH\&q=85\&s=04a931cbcc187fd4d8f4ee6074f8b62e)

The Vega cleanup section on a flag's detail page.

When Vega completes a cleanup, it provides a summary including staleness analysis, code changes, and a link to the pull request:

![A completed Vega flag cleanup, showing the PR history and Vega's summary.](https://mintcdn.com/launchdarkly/-8oCBkL_upxSWriH/images/tutorials/vega-flag-cleanup/flag-cleanup-complete.png?fit=max\&auto=format\&n=-8oCBkL_upxSWriH\&q=85\&s=a45d2fbd3ac523046c620d125f14f5d6)

A completed Vega flag cleanup, showing the PR history and Vega's summary.

LaunchDarkly records each flag's cleanup status. Vega does not add tags to flags during cleanup. However, flags that Vega cleaned up in the past may still have `vega-pr-*` tags.

If Vega has concerns about removing the flag, such as the flag still serving more than one variation across your critical environments, it opens the pull request and lists each concern as a warning in the pull request description. To learn more, read [Cleanup warnings](https://launchdarkly.com/docs/home/release-autopilot/autocleanup.md#cleanup-warnings). If Vega cannot find the flag in your code repositories, it does not open a pull request.

## Identify Vega pull requests

Vega uses the following conventions to identify the pull requests it creates. You can use these to find and monitor them in GitHub:

* The pull request title begins with the `[LaunchDarkly]` prefix by default. To change the prefix, update **Pull request title prefix** in the "Pull request details" section of your project's **Automations** settings page.
* The pull request includes the `launchdarkly-pr` label. Older pull requests have the `vega-pr` label instead.
* Cleanup pull requests also include the `flag-cleanup` label, and their branch names begin with `launchdarkly/flag-cleanup-`. Older cleanup pull requests have branch names that begin with `vega/flag-cleanup-`.

Here is an example GitHub search that shows Vega pull requests in your GitHub organization:

```lines wrap theme={null}
org:your-org is:pr label:launchdarkly-pr,vega-pr
```

You can also use the `launchdarkly-pr` label with GitHub's own notification tools. For example, GitHub's Slack integration can notify a channel when pull requests are opened in a repository.

If Vega finds references to a flag in more than one repository, it opens a separate pull request in each repository. Each pull request description includes a link to the Vega conversation that created it, which means you can trace related pull requests back to the same cleanup.

## Automated flag cleanup

In addition to starting cleanups manually, you can have Vega clean up flags on a recurring schedule. Automated flag cleanup runs once a day in each project where you turn it on, starting with the oldest flags that are ready for code removal. You turn it on in the project's **Automations** settings. Automated flag cleanup requires the Release Autopilot add-on.

To learn how to turn on, review, and turn off automated flag cleanup, read [Auto-cleanup](https://launchdarkly.com/docs/home/release-autopilot/autocleanup.md).

## Supported version control

Vega currently supports GitHub only for creating pull requests. To learn how to connect GitHub, read [Connecting Vega to GitHub](https://launchdarkly.com/docs/home/getting-started/vega-github.md).

## Related resources

* [Vega](https://launchdarkly.com/docs/home/getting-started/vega) for general information about Vega, including eligibility and pricing.
* [Customizing Vega with repository instructions](https://launchdarkly.com/docs/home/getting-started/vega#customizing-vega-with-repository-instructions) to improve Vega's cleanup results by adding a `CLAUDE.md` or `AGENTS.md` file to your repository.
* [Flag cleanup custom agent for GitHub Copilot](https://launchdarkly.com/docs/home/getting-started/github-copilot-agent.md) for an alternative approach that uses GitHub Copilot to clean up flags.
