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

# Flag Cleanup

> Reference documentation for flag cleanup scans in Confidence.

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

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

<CardGroup cols={2}>
  <Card title="Clean up flags" href="/docs/how-to-guides/clean-up-flag">
    Run a scan and review the results
  </Card>

  <Card title="Archive a flag" href="/docs/how-to-guides/archive-flag">
    Manually archive a flag that's no longer needed
  </Card>

  <Card title="Flags reference" href="/docs/flags/create-flags">
    Flag schemas, variants, and lifecycle
  </Card>
</CardGroup>
