Environment Manager
Overview
This skill helps manage environment variables and secrets across multiple environments (development, staging, production). It detects missing variables, identifies mismatches, audits for exposed secrets, and helps safely rotate credentials without downtime.
Instructions
Auditing Environment Variables
Find all env var references in code:
grep -rn "process\.env\." src/ --include="*.ts" --include="*.js" | \
sed 's/.*process\.env\.\([A-Z_]*\).*/\1/' | sort -u
For Python:
grep -rn "os\.environ\|os\.getenv" src/ --include="*.py" | \
sed 's/.*os\.\(environ\["\|getenv("\)\([A-Z_]*\).*/\2/' | sort -u
Compare against what's defined:
# From .env.example or .env
grep -v '^#' .env.example | grep '=' | cut -d'=' -f1 | sort -u
Report:
- Variables referenced in code but missing from
.env.example → ⚠️ undocumented
- Variables in
.env.example but never referenced in code → ℹ️ possibly stale
- Variables with no default and no validation → 🔴 app will crash if missing
Comparing Environments
Get variable lists from each environment:
- Local: Parse
.env or .env.local
- CI/CD: Check platform config (GitHub Actions secrets, GitLab CI variables)
- Hosting: Check platform env vars (Vercel, Railway, Heroku config)
- Secrets manager: Query Doppler, AWS SSM, or Vault
Build a comparison matrix:
Variable | dev | staging | prod | Notes
DATABASE_URL | ✓ | ✓ | ✓ | Different per env ✓
STRIPE_SECRET_KEY | ✓ | ✓ | ✗ | ⚠️ Missing in prod!
REDIS_URL | ✗ | ✓ | ✓ | ℹ️ Not needed locally
NEXT_PUBLIC_API_URL | ✓ | ✓ | ✓ | Verify values differ
Flag issues:
- Variable present in staging but missing in production → likely deployment bug
- Same secret value across dev and prod → security risk
- Public-prefixed variables with secret values → will be exposed to client
Secret Rotation
- Identify the secret to rotate (API key, database password, JWT secret)
- Check where it's used:
grep -rn "THE_VAR_NAME" . --include="*.ts" --include="*.js" --include="*.yml" --include="*.yaml" --include="Dockerfile"
- Generate rotation plan:
- For API keys: Create new key → update all environments → verify → revoke old key
- For database passwords: Update password → update connection strings → restart services
- For JWT secrets: Implement dual-key validation → deploy → set new primary → remove old
- Verify no hardcoded values exist (should all reference env vars)
Setting Up a New Environment
- Start from
.env.example as the template
- Categorize each variable:
- Shared config (feature flags, API URLs) → copy and adjust for the new env
- Secrets (API keys, passwords) → generate new ones, never copy from another env
- Infrastructure (database URLs, Redis URLs) → get from the new env's infra
- Validate the new environment:
# Check app starts without missing var errors
node -e "require('dotenv').config(); console.log('Loaded', Object.keys(process.env).length, 'vars')"
Examples
Example 1: Audit for Missing Variables
User prompt:
We keep getting "undefined" errors in staging. Can you audit our env vars?
Agent output:
Scanned src/ for environment variable references. Found 34 unique variables.
🔴 Missing from .env.example (undocumented):
OPENAI_API_KEY — referenced in src/lib/ai.ts:12
WEBHOOK_SECRET — referenced in src/api/webhooks.ts:8
RATE_LIMIT_MAX — referenced in src/middleware/rateLimit.ts:3
⚠️ Referenced but no validation/default:
SMTP_HOST — used in src/lib/email.ts:5, crashes if undefined
CACHE_TTL — used in src/lib/cache.ts:2, parseInt(undefined) = NaN
ℹ️ In .env.example but never referenced in code:
LEGACY_API_URL — possibly from a removed feature
DEBUG_MODE — no references found
Recommendation: Add the 3 undocumented vars to .env.example, add default
values for SMTP_HOST and CACHE_TTL, and remove the 2 stale entries.
Example 2: Sync Staging with Production
User prompt:
We're about to launch. Compare staging and production env vars to make sure nothing is missing.
Agent output:
Compared 41 variables across staging and production:
🔴 Missing in production (3):
STRIPE_WEBHOOK_SECRET — payments will fail without this
SENTRY_DSN — no error tracking in prod
FEATURE_FLAG_API_KEY — feature flags will default to off
⚠️ Same value in both environments (2):
JWT_SECRET — using identical secret is a security risk
DATABASE_URL — pointing to same DB! This should differ.
✓ Correctly different (28 vars)
ℹ️ Staging-only (8 vars) — debug/test vars, expected
Action items:
1. Set STRIPE_WEBHOOK_SECRET in prod (get from Stripe Dashboard → Webhooks)
2. Set SENTRY_DSN in prod (get from Sentry → Project Settings → Client Keys)
3. Generate a new JWT_SECRET for prod: openssl rand -base64 32
4. Verify DATABASE_URL points to the production database, not staging
Guidelines
- Never print or log actual secret values — show only variable names and metadata
- When comparing environments, flag identical secrets as a security concern
- Always check for
NEXT_PUBLIC_ or VITE_ prefixed vars that contain actual secrets
- Recommend
.env.example as the source of truth, committed to git (without values)
- For rotation, always plan for zero-downtime: new key → deploy → verify → revoke old
- Check CI/CD pipeline configs too — secrets there often go stale after renames
- Suggest validation libraries (envalid, zod) to catch missing vars at startup, not runtime
1---2name: env-manager3description: Manage environment variables and secrets across development, staging, and production environments. Use when someone needs to audit env vars, sync secrets between environments, detect missing or mismatched variables, rotate credentials, or set up a new environment from an existing one. Trigger words: env vars, environment variables, secrets, .env file, dotenv, config management, secret rotation, missing variable, environment sync.4license: Apache-2.05---67# Environment Manager89## Overview1011This skill helps manage environment variables and secrets across multiple environments (development, staging, production). It detects missing variables, identifies mismatches, audits for exposed secrets, and helps safely rotate credentials without downtime.1213## Instructions1415### Auditing Environment Variables16171. **Find all env var references in code:**18 ```bash19 grep -rn "process\.env\." src/ --include="*.ts" --include="*.js" | \20 sed 's/.*process\.env\.\([A-Z_]*\).*/\1/' | sort -u21 ```22 For Python:23 ```bash24 grep -rn "os\.environ\|os\.getenv" src/ --include="*.py" | \25 sed 's/.*os\.\(environ\["\|getenv("\)\([A-Z_]*\).*/\2/' | sort -u26 ```27282. **Compare against what's defined:**29 ```bash30 # From .env.example or .env31 grep -v '^#' .env.example | grep '=' | cut -d'=' -f1 | sort -u32 ```33343. **Report:**35 - Variables referenced in code but missing from `.env.example` → ⚠️ undocumented36 - Variables in `.env.example` but never referenced in code → ℹ️ possibly stale37 - Variables with no default and no validation → 🔴 app will crash if missing3839### Comparing Environments40411. Get variable lists from each environment:42 - **Local:** Parse `.env` or `.env.local`43 - **CI/CD:** Check platform config (GitHub Actions secrets, GitLab CI variables)44 - **Hosting:** Check platform env vars (Vercel, Railway, Heroku config)45 - **Secrets manager:** Query Doppler, AWS SSM, or Vault46472. Build a comparison matrix:48 ```49 Variable | dev | staging | prod | Notes50 DATABASE_URL | ✓ | ✓ | ✓ | Different per env ✓51 STRIPE_SECRET_KEY | ✓ | ✓ | ✗ | ⚠️ Missing in prod!52 REDIS_URL | ✗ | ✓ | ✓ | ℹ️ Not needed locally53 NEXT_PUBLIC_API_URL | ✓ | ✓ | ✓ | Verify values differ54 ```55563. Flag issues:57 - Variable present in staging but missing in production → likely deployment bug58 - Same secret value across dev and prod → security risk59 - Public-prefixed variables with secret values → will be exposed to client6061### Secret Rotation62631. Identify the secret to rotate (API key, database password, JWT secret)642. Check where it's used:65 ```bash66 grep -rn "THE_VAR_NAME" . --include="*.ts" --include="*.js" --include="*.yml" --include="*.yaml" --include="Dockerfile"67 ```683. Generate rotation plan:69 - For API keys: Create new key → update all environments → verify → revoke old key70 - For database passwords: Update password → update connection strings → restart services71 - For JWT secrets: Implement dual-key validation → deploy → set new primary → remove old724. Verify no hardcoded values exist (should all reference env vars)7374### Setting Up a New Environment75761. Start from `.env.example` as the template772. Categorize each variable:78 - **Shared config** (feature flags, API URLs) → copy and adjust for the new env79 - **Secrets** (API keys, passwords) → generate new ones, never copy from another env80 - **Infrastructure** (database URLs, Redis URLs) → get from the new env's infra813. Validate the new environment:82 ```bash83 # Check app starts without missing var errors84 node -e "require('dotenv').config(); console.log('Loaded', Object.keys(process.env).length, 'vars')"85 ```8687## Examples8889### Example 1: Audit for Missing Variables9091**User prompt:**92```93We keep getting "undefined" errors in staging. Can you audit our env vars?94```9596**Agent output:**97```98Scanned src/ for environment variable references. Found 34 unique variables.99100🔴 Missing from .env.example (undocumented):101 OPENAI_API_KEY — referenced in src/lib/ai.ts:12102 WEBHOOK_SECRET — referenced in src/api/webhooks.ts:8103 RATE_LIMIT_MAX — referenced in src/middleware/rateLimit.ts:3104105⚠️ Referenced but no validation/default:106 SMTP_HOST — used in src/lib/email.ts:5, crashes if undefined107 CACHE_TTL — used in src/lib/cache.ts:2, parseInt(undefined) = NaN108109ℹ️ In .env.example but never referenced in code:110 LEGACY_API_URL — possibly from a removed feature111 DEBUG_MODE — no references found112113Recommendation: Add the 3 undocumented vars to .env.example, add default114values for SMTP_HOST and CACHE_TTL, and remove the 2 stale entries.115```116117### Example 2: Sync Staging with Production118119**User prompt:**120```121We're about to launch. Compare staging and production env vars to make sure nothing is missing.122```123124**Agent output:**125```126Compared 41 variables across staging and production:127128🔴 Missing in production (3):129 STRIPE_WEBHOOK_SECRET — payments will fail without this130 SENTRY_DSN — no error tracking in prod131 FEATURE_FLAG_API_KEY — feature flags will default to off132133⚠️ Same value in both environments (2):134 JWT_SECRET — using identical secret is a security risk135 DATABASE_URL — pointing to same DB! This should differ.136137✓ Correctly different (28 vars)138ℹ️ Staging-only (8 vars) — debug/test vars, expected139140Action items:1411. Set STRIPE_WEBHOOK_SECRET in prod (get from Stripe Dashboard → Webhooks)1422. Set SENTRY_DSN in prod (get from Sentry → Project Settings → Client Keys)1433. Generate a new JWT_SECRET for prod: openssl rand -base64 321444. Verify DATABASE_URL points to the production database, not staging145```146147## Guidelines148149- Never print or log actual secret values — show only variable names and metadata150- When comparing environments, flag identical secrets as a security concern151- Always check for `NEXT_PUBLIC_` or `VITE_` prefixed vars that contain actual secrets152- Recommend `.env.example` as the source of truth, committed to git (without values)153- For rotation, always plan for zero-downtime: new key → deploy → verify → revoke old154- Check CI/CD pipeline configs too — secrets there often go stale after renames155- Suggest validation libraries (envalid, zod) to catch missing vars at startup, not runtime