> ## Documentation Index
> Fetch the complete documentation index at: https://confidence-auth-testing.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Flag Cleanup

> Reference documentation for flag cleanup scans in Confidence.

**Clean Up Flags**

Learn how to run flag cleanup scans to find and remove stale flags.

Flag cleanup scans your flags and connected repositories to find flags that are no longer pulling their weight. Each scan produces a list of stale flags and takes action on them—archiving them in Confidence, opening cleanup pull requests in your repositories, or both.

## Scans

A scan is a single analysis run. You can trigger scans manually or configure a schedule so they run automatically.

**Manual scans** let you run cleanup on demand—for example, after a feature ships or at the end of a sprint.

**Scheduled scans** run on a recurring interval without manual intervention. Use scheduled scans to keep flag debt from accumulating.

## Signal Types

Each scan looks for three signals:

### Inactive Flags

Flags that haven't seen any apply or resolve call in the last 30 days. Because no client is using them, they're safe to remove from code and archive.

### Archived Flags in Code

Flags you've already archived in Confidence. Clients can no longer resolve them, but their references can remain in your codebase as dead code. A scan finds those lingering references so you can remove them.

### Single Variant Flags

Flags that have returned only one variant to clients over the last 7 days. Because they're no longer splitting traffic, they behave like a constant—you can replace each reference with the value the flag has been serving.

## What Happens to Detected Flags

Cleanup behavior depends on whether the flag appears in your connected repositories.

### Automatic Archive

If an inactive flag has no references in your connected repositories, there's nothing to remove from code. With **Auto archive** enabled, Confidence archives the flag for you automatically.

Automatic archiving only applies to inactive flags with no code references. It does not archive flags that are still referenced, or single variant flags.

### Cleanup Pull Request

If a stale flag is still referenced in code, a coding agent opens a pull request that removes the flag and replaces each reference with the appropriate constant value:

* **Single variant flag**: replaced with the variant's value
* **Inactive or archived flag**: replaced with the call-site default

> [!NOTE]
>
> The Confidence home page also shows a **Clean up your workspace** card when
> any of your flags haven't been applied in over a week. It's a quick way to
> archive individual flags without running a full scan.

## Run a Manual Scan

**1. Go to Flag Cleanup**

Select **Flags > Cleanup** in the sidebar.

**2. Click Run scan**

The scan analyzes your flags and any connected repositories. Results appear
when the scan completes.

**3. Review the results**

Each row shows the flag name, the signal type (inactive, archived in code,
or single variant), and any code references found.

* For flags without code references, click **Archive** to archive the flag
  directly, or **Dismiss** to skip it.
* For flags with code references, click **Open PR** to have a coding agent
  open a cleanup pull request in the affected repository.

## Set a Scan Schedule

**1. Go to Flag Cleanup**

Select **Flags > Cleanup** in the sidebar.

**2. Open Schedule settings**

Click **Schedule** in the top right.

**3. Set the frequency**

Choose how often the scan runs—daily, weekly, or monthly—and click
**Save**.

Scheduled scans run automatically at the configured interval. You can still run a manual scan at any time.

## Enable Auto Archive

With auto archive enabled, Confidence automatically archives inactive flags that have no references in your connected repositories. You don't need to review and manually archive each one.

**1. Go to Flag Cleanup**

Select **Flags > Cleanup** in the sidebar.

**2. Open settings**

Click **Settings** in the top right.

**3. Turn on auto archive**

Enable **Auto archive inactive flags** and click **Save**.

> [!NOTE]
>
> Auto archive only applies to inactive flags with no code references. Flags
> that are still referenced in code are never archived automatically—they appear
> in scan results for you to review.

## Integrations

Scans work without any integrations. Without a GitHub connection, Confidence detects stale flags and—with automatic archiving enabled—archives inactive ones automatically.

Connecting a GitHub repository adds code analysis, so scans can find references in your source code and trigger cleanup pull requests. Opening those pull requests requires a coding agent.

## Related Resources

> **[Archive a flag](/docs/capabilities/flags/archive-flag.md)**
>
> Manually archive a flag that's no longer needed

> **[Flags reference](/docs/capabilities/flags/create-flags.md)**
>
> Flag schemas, variants, and lifecycle
