Repository navigation
Description
cf deploy uploads a new Worker version without the Worker's existing secrets. Wrangler keeps them in the same sequence.
I hit this migrating my personal site with cf migrate. Workers Builds ran cf deploy --prebuilt on merge, the new version went live, and the four secrets behind the newsletter signup were gone. A rollback got production working again. The secrets are still missing from the latest version though, so every later upload inherits nothing.
Repro
cf 1.0.0-beta.5, Node 24, macOS. Fresh cf init template, only renamed:
cf init repro-cf --package-manager bun
cd repro-cf
cf deploy
cf workers secrets update FOO --worker repro-cf --type secret_text --text dummy
cf workers secrets list --worker repro-cf # [FOO]
cf deploy
cf workers secrets list --worker repro-cf # []A project converted with cf migrate --bundler wrangler shows the same result, as does a Vite project deployed with cf deploy --prebuilt.
The same steps with [email protected] (wrangler deploy, wrangler secret put FOO, wrangler deploy) keep FOO.
Expected
cf deploy keeps the secrets already set on the Worker, like wrangler deploy does. cf workers versions create keeps them.
What I found
createSharedProps in packages/cli/src/lib/deploy-input.ts passes keepVars: config.keep_vars ?? false and secretsFile to @cloudflare/deploy-helpers. The deploy there sets keepSecrets: keepVars || !!props.secretsFile, so keep_bindings never includes secret_text and the versions API gets no instruction to inherit secrets. cloudflare.config.ts has no keepVars equivalent and cf deploy has no --keep-vars flag, so a cf project can't opt in either.
Wrangler 4.141 contains the same keepSecrets expression, so the difference probably lies elsewhere in how Wrangler calls deploy. I didn't track that down.
Workaround
Declare each secret with bindings.secret() in cloudflare.config.ts. cf deploy then fails with "required secrets have not been set" instead of silently dropping them. That at least fails closed. It doesn't help once the latest version has already lost the secrets, because inheritance reads from the latest version, not the deployed one.
Setting them again by hand works, provided you still have the values. I don't have all of mine.
Activity
revert: deploy with wrangler until cf keeps secrets (#66)
a1local commentedon Sep 29, 2026
Same here on 1.0.0-beta.5 after
cf migrate(Wrangler bundler): firstcf deployshipped a production version with 0 of 3 secrets; rolled back withwrangler rollback. One more gap: neithercf deploy --dry-runnor the deploy output lists secret names, so there's no signal before it goes live. Showing secret names (not values), and warning when they differ from the live version, would have caught it.neotan commentedon Sep 29, 2026
Candidate fix and analysis: #72 (comment). In short: deploy always sends secret
keep_bindings, the same thing--secrets-filealready triggers.fix: keep existing Worker secrets on cf deploy
fix: keep existing Worker secrets on cf deploy
fix: keep existing Worker secrets on cf deploy
karanbalaji commentedon Sep 30, 2026
Confirming this independently — hit it migrating a production Worker (
cf migrate wrangler.json, firstcf deployafterward silently dropped all 8 existing secrets,wrangler secret list→[]). Thebindings.secret()fail-closed workaround described above works and is what we landed on, but it surfaced a follow-up gap worth flagging here since it's directly downstream of the same root cause:bindings.secret()has no "optional" mode, so it can't protect a secret that's genuinely optional in the application (in our case, an optionalQA_GOALenv var the Worker reads with a fallback if unset). Declaring it asbindings.secret()makescf deployrefuse to deploy at all until it's set — not appropriate for something meant to be opt-in. Leaving it undeclared to avoid that means it's back to being silently wiped by the next unrelated deploy if a user ever does set it. There doesn't currently seem to be a way to say "if this secret is set, keep it; if not, that's fine" — which the pre-cfbehavior (secrets just persist until explicitly deleted) supported for free.Also separately filed #96 for a related-but-distinct bug:
cf workers secrets update(a single named secret) also replaces the entire secret set rather than patching, via aPUTto/secretsinstead ofbulk'sPATCHto/secrets-bulk— hit it a second time mid-recovery from this exact issue.jamesopstad commentedon Sep 30, 2026
Fixing in cloudflare/workers-sdk#15964.
mauricekleine commentedon Sep 30, 2026
Thanks @jamesopstad!
chore: deploy with cf now that it keeps secrets (#73)
chore: exempt cf from the minimum release age
chore(web): deploy with the cf CLI
chore: exempt cf from the minimum release age
chore(web): deploy with the cf CLI (#1590)
chore: exempt cf from the release-age gate (#75)
cf deploydeletes all existing Worker secrets unless--secrets-fileis passed #72 as a duplicate of this issuefix: keep existing Worker secrets on cf deploy