cloudflare-bulk-delete
v1.3.0
Published
Fix Cloudflare 'too many deployments to be deleted' error. Bulk delete Pages and Workers deployments safely.
Maintainers
Readme
Fix "Your project has too many deployments to be deleted"
The fastest way to bulk delete Cloudflare Pages and Workers deployments.
When Cloudflare shows "Your project has too many deployments to be deleted, follow this guide to delete them", this tool solves it in minutes instead of hours.
The Problem
Cloudflare Pages can fail to delete projects with a large deployment history. Cloudflare documents a Wrangler-based workaround; this tool automates the same cleanup problem with filtering, dry runs, and safety controls for Pages and Workers.
Before: Hours of manual API calls After: 3 commands, done in minutes
Example: Real Solution in Action
$ cf-bulk-delete interactive
✓ API connections successfully validated
=== Cloudflare Pages Projects ===
1. my-blog-site (247 deployments)
2. portfolio-app (156 deployments)
3. docs-site (89 deployments)
? Select resource to manage: my-blog-site
✓ Found 247/247 deployments for my-blog-site
? Choose action: Bulk delete deployments
? Select protection mode: Safe Mode (Recommended)
Preview: Will delete 245 deployments (keeping latest 2, skipping production)
? Proceed with deletion? Yes
⠋ Deleting deployments... 89/245 completed
✓ Cleanup completed: 245 succeeded, 0 failed
Duration: 2.3s | Rate: 106.5/s
Problem solved! 🎉Common Error Messages This Tool Fixes
Cloudflare Dashboard Error:
❌ "Your project has too many deployments to be deleted, follow this guide to delete them: https://cfl.re/3CXesln"
Our Solution:
✅
cf-bulk-delete interactive- Delete hundreds of deployments in seconds
Quick Start
# 1. Install
npm install -g cloudflare-bulk-delete
# 2. Create a token from the pre-filled Cloudflare template:
# https://dash.cloudflare.com/profile/api-tokens?permissionGroupKeys=%5B%7B%22key%22%3A%22page%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22workers_scripts%22%2C%22type%22%3A%22edit%22%7D%5D&accountId=%2A&zoneId=all&name=Cloudflare+Bulk+Delete
# 3. Set your credentials
export CLOUDFLARE_API_TOKEN=your_token_here
export CLOUDFLARE_ACCOUNT_ID=your_account_id_here
# 4. Clean up deployments
cf-bulk-delete interactiveInstallation
# npm
npm install -g cloudflare-bulk-delete
# pnpm
pnpm add -g cloudflare-bulk-delete
# Bun
bun add -g cloudflare-bulk-deleteRequires Node.js 22.14 or newer. The repository includes npm, pnpm, and Bun lockfiles for local verification.
VS Code Extension
The VS Code extension package lives in vscode/. It has no os or cpu restriction, so one VSIX can be used across VS Code desktop and remote extension hosts that support Node-based extensions.
# Build a local VSIX from the repo root
npm run vscode:package
# Install locally for testing
code --install-extension vscode/cloudflare-bulk-delete-vscode-*.vsixPublishing is manual. There is no GitHub Actions workflow, Dependabot config, git hook, npm lifecycle publish guard, or release workflow in this repository.
Setup
Step 1: Create API Token
Use the pre-filled token template:
- Create Cloudflare Bulk Delete token
- Review the pre-filled permissions and account scope.
- Click "Continue to summary" -> "Create Token".
Or configure token permissions manually:
- Choose "Create Custom Token"
- Set Token name: e.g., "Cloudflare Bulk Delete"
- Add the following permissions:
- Account -> Pages -> Write
- Account -> Workers Scripts -> Write
- Cloudflare Dashboard may show these as Cloudflare Pages Edit and Workers Scripts Edit.
- Under Account Resources, select the specific account or "All accounts"
- Click "Continue to summary" -> "Create Token"
Save Your Token:
- ⚠️ Important: Copy the token immediately - it won't be shown again!
- Store it securely
Step 2: Find Your Account ID
- From Cloudflare Dashboard:
- Go to https://dash.cloudflare.com
- Select any website/domain
- Scroll down the right sidebar
- Find "Account ID" under the API section
- Click to copy
Step 3: Set Environment Variables
Option A: Export in Terminal (Temporary)
export CLOUDFLARE_API_TOKEN=your_token_here
export CLOUDFLARE_ACCOUNT_ID=your_account_id_hereOption B: Create .env File (Recommended)
# Create .env file in your project directory
echo "CLOUDFLARE_API_TOKEN=your_token_here" > .env
echo "CLOUDFLARE_ACCOUNT_ID=your_account_id_here" >> .envOption C: Add to Shell Profile (Permanent)
# Add to ~/.bashrc, ~/.zshrc, or equivalent
echo 'export CLOUDFLARE_API_TOKEN=your_token_here' >> ~/.bashrc
echo 'export CLOUDFLARE_ACCOUNT_ID=your_account_id_here' >> ~/.bashrc
source ~/.bashrcUsage
Interactive Mode (Recommended)
cf-bulk-delete interactiveChoose your resources, select protection level, confirm deletion.
Direct Commands
# List all resources
cf-bulk-delete list
# Preview cleanup (safe)
cf-bulk-delete delete pages my-project --max-age 30 --dry-run
# Execute cleanup
cf-bulk-delete delete pages my-project --max-age 30
# Clean old preview deployments only
cf-bulk-delete delete pages my-project --environment preview --max-age 7Safety Features
- Dry-run mode - Preview before deletion
- Production protection - Skips production deployments by default
- Latest deployment protection - Keeps most recent deployment
- Batch processing - Rate-limited to avoid API throttling
Command Reference
# Core commands
cf-bulk-delete list # List all resources
cf-bulk-delete deployments pages my-project # Show deployments
cf-bulk-delete delete pages my-project # Bulk delete
cf-bulk-delete interactive # Interactive mode
cf-bulk-delete token-template # Show API token template link
# Options
--dry-run # Preview only
--max-age <days> # Delete older than X days
--environment <env> # Target specific environment
--skip-production # Skip production (default: true, use "false" to include production)
--keep-latest <n> # Keep newest N Pages deployments protected (default: 1)
--batch-size <n> # Process in batches (default: 10)
--force # Force delete aliased deployments (default: true)
--no-force # Disable force mode for aliased deploymentsExamples
Emergency cleanup (keeps production safe):
cf-bulk-delete delete pages my-project --max-age 7 --dry-run
cf-bulk-delete delete pages my-project --max-age 7Clean only preview deployments:
cf-bulk-delete delete pages my-project --environment preview --max-age 1Workers version cleanup:
cf-bulk-delete delete workers my-script --max-age 30Programmatic Usage
import { ServiceManager } from 'cloudflare-bulk-delete';
const manager = new ServiceManager(apiToken, accountId);
// Get deployments
const deployments = await manager.listDeployments('pages', 'my-project');
// Bulk delete
const result = await manager.bulkDeleteDeployments('pages', 'my-project', deployments, {
skipProduction: true,
dryRun: false
});
console.log(`Deleted: ${result.success}, Failed: ${result.failed}`);Troubleshooting
"Invalid API Token"
- Verify token permissions include:
Account > Pages > WriteAccount > Workers Scripts > Write- Cloudflare Dashboard may display these as
Cloudflare Pages EditandWorkers Scripts Edit.
- Check token hasn't expired
- Ensure token is for the correct account
- Try regenerating the token with:
cf-bulk-delete token-template
"Cannot delete an aliased deployment"
Error: You cannot delete an aliased deployment without a `?force=true` parameter- Solution: This is automatically handled! The tool uses
force=trueby default - If you want to preserve aliased deployments, use
--no-forceflag - Aliased deployments are special deployments linked to custom domains or branch aliases
"Too Many Requests"
- Tool has built-in rate limiting
- Reduce batch size:
--batch-size 5
"Account ID not found"
- Double-check your Account ID from Cloudflare Dashboard
- Ensure you're using Account ID, not Zone ID
- Account ID format: 32-character hexadecimal string
Debug mode:
LOG_LEVEL=debug cf-bulk-delete listLicense
MIT License - see LICENSE
Solves: Cloudflare "too many deployments to be deleted" error
Author: Rama Aditya
Repository: https://github.com/RamaAditya49/cloudflare-bulk-delete
