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: >-4 Manage environment variables and secrets across development, staging, and5 production environments. Use when someone needs to audit env vars, sync6 secrets between environments, detect missing or mismatched variables, rotate7 credentials, or set up a new environment from an existing one. Trigger words:8 env vars, environment variables, secrets, .env file, dotenv, config management,9 secret rotation, missing variable, environment sync.10license: Apache-2.011compatibility: "Works with .env files, Docker, CI/CD platforms. Optional: Doppler CLI, AWS SSM, Vault"12metadata:13 source: https://skillmd.com/skills/eliferjunior/env-manager14 author: terminal-skills15 version: "1.0.0"16 category: devops17 tags: ["environment-variables", "secrets", "configuration", "devops", "security"]18---1920# Environment Manager2122## Overview2324This 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.2526## Instructions2728### Auditing Environment Variables29301. **Find all env var references in code:**31 ```bash32 grep -rn "process\.env\." src/ --include="*.ts" --include="*.js" | \33 sed 's/.*process\.env\.\([A-Z_]*\).*/\1/' | sort -u34 ```35 For Python:36 ```bash37 grep -rn "os\.environ\|os\.getenv" src/ --include="*.py" | \38 sed 's/.*os\.\(environ\["\|getenv("\)\([A-Z_]*\).*/\2/' | sort -u39 ```40412. **Compare against what's defined:**42 ```bash43 # From .env.example or .env44 grep -v '^#' .env.example | grep '=' | cut -d'=' -f1 | sort -u45 ```46473. **Report:**48 - Variables referenced in code but missing from `.env.example` → ⚠️ undocumented49 - Variables in `.env.example` but never referenced in code → ℹ️ possibly stale50 - Variables with no default and no validation → 🔴 app will crash if missing5152### Comparing Environments53541. Get variable lists from each environment:55 - **Local:** Parse `.env` or `.env.local`56 - **CI/CD:** Check platform config (GitHub Actions secrets, GitLab CI variables)57 - **Hosting:** Check platform env vars (Vercel, Railway, Heroku config)58 - **Secrets manager:** Query Doppler, AWS SSM, or Vault59602. Build a comparison matrix:61 ```62 Variable | dev | staging | prod | Notes63 DATABASE_URL | ✓ | ✓ | ✓ | Different per env ✓64 STRIPE_SECRET_KEY | ✓ | ✓ | ✗ | ⚠️ Missing in prod!65 REDIS_URL | ✗ | ✓ | ✓ | ℹ️ Not needed locally66 NEXT_PUBLIC_API_URL | ✓ | ✓ | ✓ | Verify values differ67 ```68693. Flag issues:70 - Variable present in staging but missing in production → likely deployment bug71 - Same secret value across dev and prod → security risk72 - Public-prefixed variables with secret values → will be exposed to client7374### Secret Rotation75761. Identify the secret to rotate (API key, database password, JWT secret)772. Check where it's used:78 ```bash79 grep -rn "THE_VAR_NAME" . --include="*.ts" --include="*.js" --include="*.yml" --include="*.yaml" --include="Dockerfile"80 ```813. Generate rotation plan:82 - For API keys: Create new key → update all environments → verify → revoke old key83 - For database passwords: Update password → update connection strings → restart services84 - For JWT secrets: Implement dual-key validation → deploy → set new primary → remove old854. Verify no hardcoded values exist (should all reference env vars)8687### Setting Up a New Environment88891. Start from `.env.example` as the template902. Categorize each variable:91 - **Shared config** (feature flags, API URLs) → copy and adjust for the new env92 - **Secrets** (API keys, passwords) → generate new ones, never copy from another env93 - **Infrastructure** (database URLs, Redis URLs) → get from the new env's infra943. Validate the new environment:95 ```bash96 # Check app starts without missing var errors97 node -e "require('dotenv').config(); console.log('Loaded', Object.keys(process.env).length, 'vars')"98 ```99100## Examples101102### Example 1: Audit for Missing Variables103104**User prompt:**105```106We keep getting "undefined" errors in staging. Can you audit our env vars?107```108109**Agent output:**110```111Scanned src/ for environment variable references. Found 34 unique variables.112113🔴 Missing from .env.example (undocumented):114 OPENAI_API_KEY — referenced in src/lib/ai.ts:12115 WEBHOOK_SECRET — referenced in src/api/webhooks.ts:8116 RATE_LIMIT_MAX — referenced in src/middleware/rateLimit.ts:3117118⚠️ Referenced but no validation/default:119 SMTP_HOST — used in src/lib/email.ts:5, crashes if undefined120 CACHE_TTL — used in src/lib/cache.ts:2, parseInt(undefined) = NaN121122ℹ️ In .env.example but never referenced in code:123 LEGACY_API_URL — possibly from a removed feature124 DEBUG_MODE — no references found125126Recommendation: Add the 3 undocumented vars to .env.example, add default127values for SMTP_HOST and CACHE_TTL, and remove the 2 stale entries.128```129130### Example 2: Sync Staging with Production131132**User prompt:**133```134We're about to launch. Compare staging and production env vars to make sure nothing is missing.135```136137**Agent output:**138```139Compared 41 variables across staging and production:140141🔴 Missing in production (3):142 STRIPE_WEBHOOK_SECRET — payments will fail without this143 SENTRY_DSN — no error tracking in prod144 FEATURE_FLAG_API_KEY — feature flags will default to off145146⚠️ Same value in both environments (2):147 JWT_SECRET — using identical secret is a security risk148 DATABASE_URL — pointing to same DB! This should differ.149150✓ Correctly different (28 vars)151ℹ️ Staging-only (8 vars) — debug/test vars, expected152153Action items:1541. Set STRIPE_WEBHOOK_SECRET in prod (get from Stripe Dashboard → Webhooks)1552. Set SENTRY_DSN in prod (get from Sentry → Project Settings → Client Keys)1563. Generate a new JWT_SECRET for prod: openssl rand -base64 321574. Verify DATABASE_URL points to the production database, not staging158```159160## Guidelines161162- Never print or log actual secret values — show only variable names and metadata163- When comparing environments, flag identical secrets as a security concern164- Always check for `NEXT_PUBLIC_` or `VITE_` prefixed vars that contain actual secrets165- Recommend `.env.example` as the source of truth, committed to git (without values)166- For rotation, always plan for zero-downtime: new key → deploy → verify → revoke old167- Check CI/CD pipeline configs too — secrets there often go stale after renames168- Suggest validation libraries (envalid, zod) to catch missing vars at startup, not runtime