Skip to main content

Retention Rules

Retention rules automatically remove old or unused content from local repositories. They help control storage growth without turning cleanup into a recurring manual task.

At a glance​

  • Available for: local repositories when retention rules are enabled.
  • Targets: entire packages, individual package versions, or files.
  • Create with: the visual builder, JSON, or an AI-generated draft.
  • Safety: preview matches with a dry run before anything is deleted.

Package-version rules are the safest starting point for most repositories. Package rules delete every version in a matching package.

Use retention rules​

  1. Open a local repository and select Retention Rules from its details.
  2. Select Create Rule, then choose a package, version, or file target.
  3. Add the conditions that identify content to remove. Optionally add keep rules, such as keeping the five newest versions of every package.
  4. Run a Dry Run and review every matched item.
  5. Save the rule. Add a schedule only when you are ready for automatic cleanup.

Before you enable a rule​

An enabled retention rule permanently deletes matching content. Always test a new or changed rule with a dry run first.

Confirm the exact packages, versions, or files that match before enabling deletion.

Examples​

Choose an example to see a complete rule. The JSON contains only the rule body; select the matching target when creating the rule.

Common cleanup

Delete packages whose last recorded download was more than 90 days ago.

Target: Package

{
  "conditions": {
    "field": "lastDownloadedDay",
    "operator": "OLDER_THAN_DAYS",
    "value": 90
  }
}

Patterns and grouping

Delete packages whose names do not start with the protected prefix.

Target: Package

{
  "conditions": {
    "field": "name",
    "operator": "NOT_MATCHES",
    "value": "^protected-"
  }
}

Rule JSON reference​

conditions selects candidates for deletion. Optional keepRules sorts matching items and preserves or drops a fixed number, with optional grouping.

For keepRules, set sortBy and order (asc or desc), then set exactly one of keep or drop. Use either groupBy or groupByExtract when the limit should apply independently to each group.

Condition structure: use a leaf condition with field, operator, and value. Combine conditions recursively with and, or, or not.

FieldTypeSupported operators
idstringEQUALS, NOT_EQUALS, MATCHES, NOT_MATCHES
namestringEQUALS, NOT_EQUALS, MATCHES, NOT_MATCHES
creationDaydateEQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN, OLDER_THAN_DAYS
updatedDaydateEQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN, OLDER_THAN_DAYS
lastDownloadedDaydateEQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN, OLDER_THAN_DAYS
sizeInBytenumberEQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN
downloadsnumberEQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN
versionsCountnumberEQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN

Example rule JSON

{
  "conditions": {
    "field": "lastDownloadedDay",
    "operator": "OLDER_THAN_DAYS",
    "value": 90
  }
}

Avoid an empty rule: a rule with neither useful conditions nor keepRules can match all content for its target. File rules are especially risky because deleting a package-managed file can break a package.

API and self-hosting​

Use the API to create, update, or run retention rules.

For a self-hosted deployment, see Retention Rules Configuration for feature flags, limits, and worker concurrency.