Delete old file versions in SharePoint Online to reclaim storage.
SharePoint keeps every version of every file, and on busy libraries the history ends up taking more space than the files themselves. This web app (Streamlit) walks the sites, libraries, folders or files you paste and deletes the versions that match a filter. It can also move the site recycle bin to the second stage, which frees space while items stay recoverable for the rest of the 93-day retention window.
Warning: deleting versions is usually permanent in SharePoint Online. Try it first on a test site or a single file.
- Docker with Docker Compose.
- A Microsoft Entra ID App Registration with permissions on your SharePoint sites. Creating it requires a tenant administrator.
The app uses Microsoft Entra ID app-only authentication with a client certificate. The legacy ACS model (client id + client secret) was retired by Microsoft on 2 April 2026 and no longer works.
-
Generate a self-signed certificate:
openssl req -x509 -newkey rsa:2048 -nodes -days 730 \ -keyout cert.pem -out cert.cer -subj "/CN=sharepoint-version-cleaner" -
In Entra ID, create an App Registration.
-
Under API permissions, add the SharePoint application permission
Sites.FullControl.All(orSites.Selectedto limit it to specific sites) and grant admin consent. -
Under Certificates & secrets, upload
cert.cerand copy its thumbprint. -
Keep
cert.pem(the private key) at the project root. It is mounted into the container at/usr/src/app/cert.pemand ignored by git. -
Create the configuration file and fill in
TENANT_ID,CLIENT_ID,CERT_THUMBPRINTandCERT_PATH:cp env.example .env
docker compose upOpen http://localhost:8501, paste the URLs (one per line), choose a filter and press Clean.
- Delete all old versions: keeps only the current version.
- Delete versions older than a date: removes the versions created before the chosen day.
- Keep N versions: keeps the N most recent versions, current one included.
| URL | Scope |
|---|---|
https://contoso.sharepoint.com/sites/Site |
Every document library in the site |
https://contoso.sharepoint.com/sites/Site/Shared%20Documents/Forms/AllItems.aspx |
The whole library |
.../Forms/AllItems.aspx?id=/sites/Site/Shared%20Documents/Folder |
That folder, recursively |
https://contoso.sharepoint.com/sites/Site/Shared%20Documents/Folder/file.docx |
That file |
https://contoso.sharepoint.com/:f:/r/sites/Site/... |
Sharing link with a resource path |
Sites under /teams/ and the root site collection are supported too. Tokenized sharing links (/:f:/s/...) are not: open the item in the browser and copy the URL from the address bar.
When Move the site recycle bin to the second stage is enabled, the app moves the first-stage recycle bin of every processed site to the second stage once cleaning is done. You can limit it to items deleted before a date. Moved items are not purged: they can still be restored from the second-stage recycle bin until their retention period ends.
GPLv3. See the LICENSE file.
