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

export const HowToSchema = ({name, description, steps = []}) => {
  const schema = {
    "@context": "https://schema.org",
    "@type": "HowTo",
    name,
    description
  };
  if (steps.length > 0) {
    schema.step = steps.map((s, i) => ({
      "@type": "HowToStep",
      position: i + 1,
      name: typeof s === "string" ? s : s.name,
      text: typeof s === "string" ? s : s.text || s.name
    }));
  }
  return <script type="application/ld+json" dangerouslySetInnerHTML={{
    __html: JSON.stringify(schema)
  }} />;
};

<HowToSchema
  name="Clean Up Flags"
  description="Learn how to run flag cleanup scans to find and remove stale flags."
  steps={[
{
  name: "Go to Flag Cleanup",
  text: "Select Flags > Cleanup in the sidebar.",
},
{
  name: "Run a scan",
  text: "Click Run scan. The scan analyzes your flags and connected repositories for inactive flags, archived flags still referenced in code, and single variant flags.",
},
{
  name: "Review the results",
  text: "Each detected flag shows the signal type and any code references. Review the list and decide what to do with each flag.",
},
]}
/>

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.
</Note>

## Run a Manual Scan

<Steps>
  <Step title="Go to Flag Cleanup">
    Select **Flags > Cleanup** in the sidebar.
  </Step>

  <Step title="Click Run scan">
    The scan analyzes your flags and any connected repositories. Results appear
    when the scan completes.
  </Step>

  <Step title="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.
  </Step>
</Steps>

## Set a Scan Schedule

<Steps>
  <Step title="Go to Flag Cleanup">
    Select **Flags > Cleanup** in the sidebar.
  </Step>

  <Step title="Open Schedule settings">
    Click **Schedule** in the top right.
  </Step>

  <Step title="Set the frequency">
    Choose how often the scan runs—daily, weekly, or monthly—and click
    **Save**.
  </Step>
</Steps>

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.

<Steps>
  <Step title="Go to Flag Cleanup">
    Select **Flags > Cleanup** in the sidebar.
  </Step>

  <Step title="Open settings">
    Click **Settings** in the top right.
  </Step>

  <Step title="Turn on auto archive">
    Enable **Auto archive inactive flags** and click **Save**.
  </Step>
</Steps>

<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.
</Note>

## 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="Archive a flag" href="/docs/capabilities/flags/archive-flag">
    Manually archive a flag that's no longer needed
  </Card>

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