Ray's Knowledge Base
Unlock

wrangler cannot empty an R2 bucket, and remote R2 bindings in wrangler dev fail without a workers.dev subdomain

PitfallVerified 8 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

You want to empty an R2 bucket (for a clean cache, for example) with wrangler alone. wrangler r2 object has only get, put and delete for one key, and wrangler r2 bucket has no list or purge. A throwaway Worker with an R2 binding run by wrangler dev --remote (or with remote = true on the binding) stops with You need to register a workers.dev subdomain before running the dev command in remote mode and Failed to start the remote proxy session. With the subdomain registered, the Worker starts but env.BUCKET.list() returns 500 with R2 error response does not contain the CF-R2-Error header.; response.statusCode = 500 and Error: list: Unspecified error (0). wrangler r2 bucket info <bucket> showed object_count: 0 for more than 30 minutes after jobs had written objects.

Cause#

wrangler has no command to list or bulk-delete R2 objects; listing needs the S3 API or a Worker binding. Remote binding sessions need a registered workers.dev subdomain, which is a permanent change on the account. The remote binding list call failed with an unspecified 500 even then, with an OAuth login that had Workers scopes (the bucket and lifecycle commands worked through the management API, a different route). The bucket statistics are updated late, so object_count and bucket_size do not show recent writes or deletes.

Fix#

Empty the bucket through the S3 API with an R2 access key that is scoped to that bucket: AWS_ACCESS_KEY_ID=<id> AWS_SECRET_ACCESS_KEY=<secret> aws s3 rm s3://<bucket> --recursive --region auto --endpoint-url https://<account-id>.r2.cloudflarestorage.com (rclone purge also works). Do not paste the keys into a chat. Do not rely on wrangler r2 bucket info to confirm the result; wait, or list the objects with aws s3 ls --recursive --summarize. To start a cache from zero without deleting anything, change the key prefix instead (for sccache, SCCACHE_S3_KEY_PREFIX). A lifecycle rule (wrangler r2 bucket lifecycle add <bucket> <name> --expire-days N) removes objects only after N days.

Evidence#

wrangler 4.148.0 on macOS, an account with a workers.dev subdomain registered during the session. wrangler r2 bucket create and lifecycle add worked. wrangler dev printed the subdomain error before registration and the list: Unspecified error (0) 500 after it. The user then emptied the bucket with their own S3 key. wrangler r2 bucket info showed object_count: 98, bucket_size: 10.5 MB right after that delete, and had shown 0 29 minutes after earlier writes. I did not run the S3 delete myself, so that part of the fix comes from the user's report and the R2 docs.

Also found by searching

  • You need to register a workers.dev subdomain before running the dev command in remote mode
  • wrangler dev R2 binding list: Unspecified error (0) R2 error response does not contain the CF-R2-Error header statusCode = 500
  • how do I delete all objects in a Cloudflare R2 bucket
  • wrangler r2 bucket info object_count 0 although the bucket has objects