> ## 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

<View title="Developer" />

<View title="Federal docs">
  <Danger>
    **Vega is not available in federal environments**

    To learn more, read <a href="/docs/home/infrastructure/federal">LaunchDarkly in federal environments</a>.
  </Danger>
</View>

<View title="EU docs">
  <Danger>
    **Vega is not available in the LaunchDarkly European Union (EU) instance**

    To learn more, read <a href="/docs/home/infrastructure/eu">LaunchDarkly in the European Union (EU)</a>.
  </Danger>
</View>

<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](/docs/home/getting-started/vega-github).
</Warning>

Vega is the LaunchDarkly AI-powered agent. To use Vega, your role requires the [Vega actions](/docs/home/account/roles/role-actions#vega-actions). To learn more about Vega, including eligibility, pricing, and permissions, read [Vega](/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**.

<Frame caption="The three-dot overflow menu on a flag, with the Vega cleanup option.">
  <img src="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" alt="The three-dot overflow menu on a flag, with the Vega cleanup option." width="1916" height="620" data-path="images/tutorials/vega-flag-cleanup/open-dialog-list.png" />
</Frame>

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

<Frame caption="The Vega Cleanup Status section on a flag's detail page, with the Start cleanup link.">
  <img src="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" alt="The Vega Cleanup Status section on a flag's detail page, with the Start cleanup link." width="1940" height="1980" data-path="images/tutorials/vega-flag-cleanup/open-dialog-individual.png" />
</Frame>

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

<Frame caption="The Flag cleanup modal, showing staleness analysis and the Start cleanup button.">
  <img src="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" alt="The Flag cleanup modal, showing staleness analysis and the Start cleanup button." width="2502" height="2306" data-path="images/tutorials/vega-flag-cleanup/flag-cleanup-modal.png" />
</Frame>

Once started:

1. The cleanup job appears under the **Flag Cleanup** tab.
2. Vega checks that the flag has only a single variation being evaluated across all [critical environments](/docs/home/account/environment#critical-environments). If multiple variations are still active, Vega won't proceed with the cleanup task.
3. If the check passes, Vega 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 notifies you. You can still tell Vega to clean up the flag if you'd like to proceed anyway.

## Tracking cleanup status

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

<Frame caption="The Vega Cleanup Status section on a flag's detail page.">
  <img src="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" alt="The Vega Cleanup Status section on a flag's detail page." width="2198" height="1930" data-path="images/tutorials/vega-flag-cleanup/flag-cleanup-status.png" />
</Frame>

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

<Frame caption="A completed Vega flag cleanup, showing the PR history and Vega's summary.">
  <img src="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" alt="A completed Vega flag cleanup, showing the PR history and Vega's summary." width="3402" height="2634" data-path="images/tutorials/vega-flag-cleanup/flag-cleanup-complete.png" />
</Frame>

Vega tags flags during the cleanup process. You can filter by these tags in the **Flags** list to track progress:

<table>
  <thead>
    <tr>
      <th>Tag</th>
      <th>Meaning</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>vega-pr-in-progress</code></td>
      <td>Cleanup is underway for this flag.</td>
    </tr>

    <tr>
      <td><code>vega-pr-filed</code></td>
      <td>A pull request has been created for this flag's cleanup.</td>
    </tr>

    <tr>
      <td><code>vega-pr-attempted</code></td>
      <td>Vega attempted cleanup but did not file a pull request. This can happen if Vega's pre-cleanup checks determine the flag isn't stale, if Vega cannot find any reference to the flag in the repositories it has access to, or due to a transient error such as a change in GitHub permissions.</td>
    </tr>
  </tbody>
</table>

If Vega determines the flag is still active (multiple variations in use across critical environments), it will notify you and stop. If Vega cannot find the flag in your code repositories, it will also notify you.

## Identify Vega pull requests

Vega uses the following conventions to identify the pull requests it creates, so you can find and monitor them in GitHub:

* The pull request title begins with the `[Vega]` prefix.
* The pull request includes the `vega-pr` label.

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:vega-pr
```

You can also use the `vega-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, so you can trace related pull requests back to the same cleanup.

## Automated flag cleanup

In addition to starting cleanups manually, you can configure Vega to automatically clean up flags on a recurring schedule. When enabled, Vega periodically scans for flags that are ready for code removal and runs cleanup jobs for them.

To configure automated flag cleanup:

1. Go to **Project settings**, then select **Lifecycle settings**.

2. In the "Automated flag cleanup" section, check **Enable automated flag cleanups**.

3. Configure the following settings:

   * **Schedule frequency**: Choose how often Vega runs automated cleanups. The options are **1 day**, **7 days** (the default), or **30 days**.
   * **Max cleanup jobs per run**: The maximum number of flags Vega will clean up in a single scheduled run (1–20).
   * **Retry unsuccessful cleanups**: When checked, Vega will re-attempt cleanup on flags where a previous attempt was unsuccessful. This option is off by default.
   * **GitHub repositories**: Select one or more connected GitHub repositories that Vega should target for code removal. You must select at least one repository to save your settings.
   * **Additional context** (optional): Provide extra instructions for the cleanup agent. For example, you can specify where flags are defined in your codebase. Vega also follows instructions in your repository's `AGENTS.md` file, if available.

4. Click **Save**.

<Frame caption="The Automated flag cleanup settings card on the Lifecycle settings page.">
  <img src="https://mintcdn.com/launchdarkly/-b7nPh0oyigf6iW7/images/auto/automated-flag-cleanup-settings.auto.png?fit=max&auto=format&n=-b7nPh0oyigf6iW7&q=85&s=fdb43874a27238cd0008daf0ce852bba" alt="The Automated flag cleanup settings card on the Lifecycle settings page." width="1980" height="862" data-path="images/auto/automated-flag-cleanup-settings.auto.png" />
</Frame>

After you save, Vega runs cleanups automatically based on your schedule. Each run processes up to the configured maximum number of flags. You can track the progress of automated cleanups the same way as manual cleanups, using the `vega-pr-in-progress`, `vega-pr-filed`, and `vega-pr-attempted` tags in the **Flags** list.

The settings card shows a "Last configured by" indicator with the member who saved the current configuration. Automated cleanup jobs run using this member's permissions, so Vega can only access the repositories and flags that member has access to. If that member's permissions change or their account is deactivated, you should update the settings with a different member to ensure cleanups continue to run.

## Supported version control

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

## Related resources

* [Vega](/docs/home/getting-started/vega) for general information about Vega, including eligibility and pricing.
* [Customizing Vega with repository instructions](/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](/docs/home/getting-started/github-copilot-agent) for an alternative approach that uses GitHub Copilot to clean up flags.
