Edit icon Edit This Page

Retention Policies

A retention policy deletes old versions of the packages in one repository on a schedule, so the repository does not grow without bound. It works for Maven, npm, PyPI, NuGet, Cargo, Go, Helm and Ruby repositories. Docker repositories have their own cleanup policy instead.

A new repository has a policy that is disabled. Nothing is deleted until a user who manages the repository enables it.

Retention policies are part of the paid plans. On the Free plan you can read the policy, its runs and a preview, and you can disable it, but changing the rules, enabling it and Run now are refused with the error code planUpgradeRequired. See the pricing page for the plans.

A deleted version is gone. Clients that pin it, for example in a lock file, can no longer download it. Use the preview before you enable a policy or change its rules.

Setting Up a Policy

Open the repository, go to Settings and find the Retention Policy section.

Edit the rules

Click Edit and fill in the rules described below.

Preview

Click Preview. The panel lists the versions the next run would delete, oldest first, and their total size. Some formats (npm, PyPI, NuGet, Ruby, Go and Cargo) do not record the size of a version, so the total only counts the versions whose size is known.

Save and enable

Click Save, then turn the Enabled toggle on. The first run starts within a minute; after that the policy runs on its schedule. Saving a new schedule moves the next run to it.

The Rules

FieldDefaultWhat it does
Run retentionEvery weekHow often the policy runs: every day, week, two weeks, month or quarter.
Keep the most recent10The number of newest versions of each package that are always kept, 1 to 1000.
Delete versions older than30 daysOnly versions older than this are deleted, 0 to 3650 days. 0 deletes by count alone.
Apply to packages matching.*A regular expression that the whole package name must match. Other packages are left alone.
Never delete versions matchingemptyA regular expression; versions whose whole name matches are never deleted, for example .*-lts|1\.0\..*.
Delete prereleases onlyoffWhen on, only prereleases (and Maven SNAPSHOT builds) are deleted.

A version is deleted only when all of these hold:

  • its package matches Apply to packages matching,
  • it is not one of the Keep the most recent newest versions of its package,
  • it is older than Delete versions older than,
  • it does not match Never delete versions matching,
  • it is a prerelease, if Delete prereleases only is on,
  • and its format does not protect it (see below).

Package names are matched as the panel shows them: group:artifact for Maven, @scope/name for a scoped npm package, the normalized name for PyPI and the module path for Go. The regular expressions use the RE2 syntax, which has no backreferences or lookarounds, and are at most 255 characters long.

What Counts as a Prerelease

FormatPrerelease
npm, Cargo, HelmA SemVer prerelease: a hyphen in the version, as in 1.0.0-beta.1.
GoA SemVer prerelease after the leading v, which includes pseudo-versions such as v0.0.0-20240101120000-abcdef123456.
PyPIA PEP 440 pre or development release, such as 2.0rc1 or 1.0.dev3.
NuGetA version the package marks as a prerelease.
RubyA version that contains a letter, such as 1.0.0.pre or 2.0.0.rc1.
MavenThe timestamped builds of a -SNAPSHOT version.

What Is Never Deleted

  • The newest version of every package. Each package keeps at least one version, whatever Keep the most recent says.
  • npm dist-tags. A version that a dist-tag points to, latest included, is never deleted; deleting it would leave the tag pointing nowhere.
  • The Maven release. The version that an artifact’s <release> names in maven-metadata.xml is kept while it is the artifact’s only release version.
  • The newest SNAPSHOT build. The newest timestamped build of each SNAPSHOT version is kept, so the snapshot always resolves.

Format Notes

  • Maven. Release versions are deleted as whole versions, which keeps maven-metadata.xml up to date. A SNAPSHOT version is never deleted as a whole; its timestamped builds are pruned instead, and Keep the most recent counts the builds of each SNAPSHOT version on their own. Turn on Delete prereleases only to prune only SNAPSHOT builds.
  • Cargo. A deleted crate version is removed from the index and storage; it is not yanked. A Cargo.lock that pins it no longer resolves.
  • Go. A deleted module version is gone. Builds whose go.sum pins it no longer resolve.
  • Helm. A version pushed with helm push to the OCI endpoint is deleted with its OCI manifests, and index.yaml no longer lists it.
  • Ruby. Each platform of a gem version is a version of its own (1.0.0, 1.0.0-java), and a yanked version is deleted like any other.

Run Now and Recent Runs

While the policy is enabled, Run now starts a run at once, without waiting for the schedule.

Recent runs lists the last runs: when they started, whether they were scheduled or started by a user, their status, how many versions they deleted and how much space they freed. Click a run to see the versions it deleted. Refresh loads the list again.

StatusMeaning
RUNNINGThe run is still deleting.
SUCCEEDEDEvery selected version was deleted.
PARTIALSome versions could not be deleted; the run shows how many. The next run tries them again.
FAILEDThe run stopped with an error, which the run shows.

One run deletes at most a fixed number of versions, the oldest first; the next run goes on where it stopped.

The space a run frees is taken off the disk usage of the repository’s owner, the same as when you delete the versions by hand.

Retention Policy and Docker Cleanup Policy

Docker repositories do not have a retention policy. Their Container Registry Cleanup Policy, in the same place in the settings, deletes old tags instead. Both share the layout of the settings section, Run now and Recent runs.

Retention policyDocker cleanup policy
FormatsMaven, npm, PyPI, NuGet, Cargo, Go, Helm, RubyDocker
DeletesPackage versionsImage tags, then the manifests and layers no tag uses any more
KeepsThe newest N versions of each package, and versions younger than N daysThe newest N tags of each image, and tags younger than N days
SelectsPackages by a name pattern; protects versions by a patternTags by a name pattern; protects tags by a pattern
PreviewYesNo

From the Command Line and AI Agents

The rp command line client manages the policy with rp repo retention: get, set, enable, disable, preview, run and runs. For example, to keep the five newest versions and delete the rest after 90 days:

rp repo retention set <repo-name> --keep-last 5 --keep-days 90
rp repo retention preview <repo-name>
rp repo retention enable <repo-name>

rp mcp gives AI agents the tools get_retention_policy, preview_retention and list_retention_runs (read), and set_retention_policy, set_retention_status and run_retention (write, need the repo:manage scope). See MCP Tools.

Found a problem with this page?