Clear Cloudflare KV Namespace
Cloudflare doesn’t give you a way to clear out a KV namespace, so here’s how I do it. This script grabs all the keys and deletes them one by one.
wrangler kv:key list \
--namespace-id=<YOUR_NAMESPACE_ID> \
--remote \
--preview | \
jq -r '.[].name' | \
xargs -I {} wrangler kv:key delete \
"{}" \
--namespace-id=<YOUR_NAMESPACE_ID> \
--remote \
--preview
Depending on the size of your KV namespace it may not fast, but it works. Remove --preview if you’re targeting production.