Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Delete Commands for Worker Resources, Namespaces, Keys, and Queues

How to remove Workers, D1, KV, Queues, secrets, and related bindings safely with Wrangler CLI, runtime APIs, and REST—confirmations, prerequisites, and checks.

This page summarizes Cloudflare documentation on deleting Workers platform resources: whole applications, namespaces, individual keys, queued messages, vectors, certificates, and agent-memory data. Most operations use the Wrangler CLI (npx wrangler …); some run inside a Worker binding or through the HTTP API. Destructive actions often prompt for confirmation; several deletes are permanent or require the resource to be empty first.

Wrangler delete commands: what gets removed and what stays

Section titled “Wrangler delete commands: what gets removed and what stays”

A Wrangler delete removes the remote resource (or the targeted slice of it) in your Cloudflare account. It does not automatically edit your local wrangler.toml unless a command offers --update-config (for example when creating resources). After deleting a bound resource, remove or update the matching binding in your config so the next deploy does not reference a missing ID.

Layer Typical command pattern What disappears
Whole Worker wrangler delete Worker script and associated developer-platform resources tied to that delete (see Workers commands)
Named platform resource wrangler <product> delete <NAME|ID> That D1 DB, KV namespace, queue, Vectorize index, Hyperdrive config, etc.
Single record wrangler kv key delete, wrangler vectorize delete-vectors, wrangler queues purge One key, selected vectors, or all messages—not the parent queue
Secret / credential wrangler secret delete, wrangler pages secret delete Secret value only; the Worker or Pages project remains

Use --env (or --e) when your Wrangler configuration defines environments, so you delete staging secrets or preview KV namespaces instead of production. Global flags such as --config, --cwd, and --profile apply across command families documented under General commands.

Worker delete: remove a script and linked platform resources

Section titled “Worker delete: remove a script and linked platform resources”

To tear down an entire Worker from the CLI, use wrangler delete with optional --name and --env, or --dry-run to see what would happen without deleting:

Delete your Worker and all associated Cloudflare developer platform resources.

— Cloudflare, Workers commands

That is broader than wrangler secret delete <KEY>, which only removes one secret variable from the Worker (Workers commands). Preview flows have their own deletes, for example wrangler preview delete (Preview and its deployments) and wrangler preview secret delete <KEY> (Workers commands).

Workers for Platforms: a dispatch namespace cannot be deleted until every user Worker inside it is gone:

You must delete all user Workers in the dispatch namespace before it can be deleted.

— Cloudflare, Workers for Platforms commands

Secret delete: Worker, Pages, Secrets Store, and legacy Wrangler

Section titled “Secret delete: Worker, Pages, Secrets Store, and legacy Wrangler”

Secrets are deleted by name or ID, depending on the product:

  • Worker: npx wrangler secret delete <KEY> (Workers commands).
  • Pages: npx wrangler pages secret delete <KEY> with --project-name (Pages commands).
  • Secrets Store: npx wrangler secrets-store secret delete <STORE-ID> --secret-id <ID>; delete an entire store with secrets-store store delete (Secrets Store commands).
  • Legacy Wrangler v1: wrangler secret delete <name> --env ENVIRONMENT_NAME (Legacy commands).

Listing before delete reduces typos: wrangler secret list, wrangler pages secret list, or wrangler secrets-store secret list <STORE-ID> (see the same command reference pages).

mTLS and origin trust material use separate deletes: wrangler cert delete / wrangler mtls-certificate delete with --id or --name (Certificates commands), or the zone API for a custom origin trust store (Custom Origin Trust Store).

KV namespace delete and key delete: whole namespace vs one key

Section titled “KV namespace delete and key delete: whole namespace vs one key”

Namespace delete removes the KV namespace itself:

Delete a given namespace.

— Cloudflare, KV commands

Identify it by name, --binding, or --namespace-id; use --preview for preview namespaces and --skip-confirmation to skip prompts (KV commands).

Key delete removes one pair from a namespace:

Remove a single key value pair from the given namespace

— Cloudflare, KV commands

Add --local or --remote when you mean dev persistence vs production storage. Bulk delete reads keys from a file: wrangler kv bulk delete <FILENAME> with optional --force (KV commands).

Inside a running Worker, the KV delete() API also removes a key; deleting a missing key still counts as success, and propagation across the network may take time:

Calling delete() on a non-existing key is returned as a successful delete.

— Cloudflare, Delete key-value pairs

D1 delete database and DROP INDEX: when SQL delete is not enough

Section titled “D1 delete database and DROP INDEX: when SQL delete is not enough”

Remote database delete uses npx wrangler d1 delete <NAME> where <NAME> is the database name or binding; --skip-confirmation skips the prompt (D1 commands). Export first if you need a backup: wrangler d1 export with --output (D1 commands).

For schema-only cleanup, D1 supports DROP INDEX; dropped indexes cannot be restored (Use indexes). Inspecting indexes before drop is done via wrangler d1 execute and PRAGMA index_info (SQL statements).

Queue delete vs purge: remove the queue or only its messages

Section titled “Queue delete vs purge: remove the queue or only its messages”
  • wrangler queues delete <NAME> deletes the queue resource (Queues commands).
  • wrangler queues purge <NAME> empties messages; --force skips confirmation (Queues commands).

Related cleanup: remove consumers (queues consumer remove, HTTP/worker variants), delete event subscriptions with wrangler queues subscription delete <QUEUE> --id <subscription-id> (Manage event subscriptions, Queues commands). pause-delivery / resume-delivery stop or restart delivery without deleting the queue.

Vectorize delete index, delete-vectors, and delete-metadata-index

Section titled “Vectorize delete index, delete-vectors, and delete-metadata-index”
Goal Command / API
Remove entire index wrangler vectorize delete <NAME> (--force, --deprecated-v1 if needed) (Vectorize commands)
Remove specific vectors wrangler vectorize delete-vectors <NAME> --ids … or env.YOUR_INDEX.deleteByIds([...]) in a Worker (Vectorize client API)
Remove metadata filter index wrangler vectorize delete-metadata-index <NAME> --propertyName='…' (Vectorize commands)

Vector deletes from the client API are asynchronous; vectors may take a few seconds to disappear from the index (Vectorize client API).

Artifacts, AI Search, Agent Memory, and Containers delete rules

Section titled “Artifacts, AI Search, Agent Memory, and Containers delete rules”

Artifacts: delete a repository with wrangler artifacts repos delete <NAME> --namespace <NAMESPACE> (--force skips confirmation) (Artifacts commands). An Artifacts namespace via REST must be empty first; otherwise the API returns 409 (Artifacts REST API):

The namespace must be empty before you delete it.

— Cloudflare, Artifacts REST API

AI Search: wrangler ai-search delete <NAME> or wrangler ai-search namespace delete <NAME> (AI Search Wrangler commands); in Workers, await env.AI_SEARCH.delete("old-docs") (AI Search Workers binding).

Agent Memory: HTTP DELETE routes mark namespaces, profiles, sessions, or individual memories for deletion (Agent Memory HTTP API); the Workers API exposes deleteProfile, deleteSession, and delete(memoryId) (Agent Memory Workers API).

Containers: wrangler containers delete <CONTAINER_ID>; registry cleanup uses containers images delete, containers registries delete (Containers commands).

Other Wrangler deletes in the same pattern: hyperdrive delete <ID>, workflows delete <NAME> (also deletes workflow instances), vpc service delete <SERVICE-ID>, pages project delete, pages deployment delete, tunnel delete, vectorize delete, browser close <SESSIONID> (Hyperdrive, Workflows, VPC, Pages, Tunnel, Browser Run).

Durable Object facets: this.ctx.facets.delete(name) aborts the facet and deletes its SQLite database (Durable Object Facets).

Confirmation flags and non-interactive CI deletes

Section titled “Confirmation flags and non-interactive CI deletes”

Many delete commands prompt [y/n]. For automation, documentation documents flags such as:

  • --skip-confirmation / --y on d1 delete, kv namespace delete, Worker preview deletes
  • --force on artifacts repos delete, vectorize delete, queues purge, queues subscription delete, pages deployment delete
  • --yes on pages project delete

In CI, D1 migrations apply notes that confirmation is skipped in non-interactive environments while backups still run—useful context when deletes are part of migration workflows, not a substitute for backing up before d1 delete.

Certificate delete examples show an interactive confirm step unless you answer yes (Certificates commands).

  • Deleting a parent while children exist — Artifacts namespaces (409), dispatch namespaces (user Workers must be removed first).
  • Confusing purge with delete — queues purge leaves the queue; queues delete removes it.
  • Wrong target environment — omitting --env or --preview when multiple namespaces exist.
  • Expecting instant KV or Vectorize consistency — Worker delete() and deleteByIds can succeed before every edge location reflects the change.
  • Removing secrets but not bindings — secret delete does not remove secrets_store or KV bindings from config.
  • Tunnel delete — terminates live connections with no undo (Tunnel commands).
  1. From your project directory, run the matching list command (wrangler d1 list, wrangler kv namespace list, wrangler queues list, wrangler vectorize list, or wrangler deployments list) and confirm the deleted name or ID no longer appears—see D1, KV, Queues, Vectorize, and Workers command references.
  2. For a single KV key, query or list keys in the namespace (or re-run your app) after wrangler kv key delete; for Worker code paths, await delete() as documented in Delete key-value pairs.
  3. After wrangler secret delete, run wrangler secret list (or wrangler pages secret list with --project-name) and verify the variable name is absent (Workers, Pages).
  4. After destructive changes, run wrangler deployments status or attempt a dry-run deploy to ensure bindings in wrangler.toml still match account resources (Workers commands).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match the official docs or your account behavior, email yimasynthetic@gmail.com with the page URL and the exact sentence you think is wrong so it can be corrected.