Scope env vars per environment

Add each value to the environment that needs it, not to all three.

From vercel-cli-with-tokens, SKILL.md “Managing Environment Variables”.

One key, three environments

Press Add key; a preview checkout runs after.

Added to all threeBad
vercel env add STRIPE_SECRET_KEY
One per environmentGood
vercel env add STRIPE_SECRET_KEY preview
echo "sk_live_…" | vercel env add STRIPE_SECRET_KEY production
echo "sk_test_…" | vercel env add STRIPE_SECRET_KEY preview
echo "sk_test_…" | vercel env add STRIPE_SECRET_KEY development

vercel env ls     # check the matrix
vercel env pull   # development values → .env.local

Why it matters, pros and cons

Why it matters

Previews run every branch's code. With the live value everywhere, a test checkout charges real cards.

Pros

  • Previews can't touch live money or data.
  • Each environment gets a value it can use.
  • vercel env ls shows the whole matrix.

Cons

  • Up to three entries to keep in sync.
  • A missing preview value breaks preview builds.
  • Truly shared values can go to all three.