Env manager

From TerminalSkills/skills · View interactive version

Env manager is an AI agent skill from the GitHub repository TerminalSkills/skills. 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:

How to use this skill

Skill file

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

  1. Find all env var references in code. Match both dot access and bracket access, and both process.env and process.env["NAME"]:

```bash

grep -rhoE "process\.env(\.[A-Za-z_][A-Za-z0-9_]|\[[\"'][A-Za-z_][A-Za-z0-9_][\"']\])" src/ \

--include=".ts" --include=".js" | grep -oE "[A-Za-z_][A-Za-z0-9_]*" | grep -vE "^(process|env)$" | sort -u

```

For Python, which covers os.environ["X"], os.environ.get("X") and os.getenv("X"):

```bash

grep -rhoE "os\.(environ(\.get)?|getenv)[\[(][\"'][A-Z_][A-Z0-9_][\"']" src/ --include=".py" | \

grep -oE "[A-Z][A-Z0-9_]*" | sort -u

```

Both commands miss names built at runtime (process.env[key]); check those by reading the code.

  1. Compare against what's defined:

```bash

# From .env.example or .env

grep -v '^#' .env.example | grep '=' | cut -d'=' -f1 | sort -u

```

  1. Report:

Comparing Environments

  1. Get variable lists from each environment:
  1. 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

```

  1. Flag issues:

Secret Rotation

  1. Identify the secret to rotate (API key, database password, JWT secret)
  2. Check where it's used:

```bash

grep -rn "THE_VAR_NAME" . --include=".ts" --include=".js" --include=".yml" --include=".yaml" --include="Dockerfile"

```

  1. Generate rotation plan:
  1. Verify no hardcoded values exist (should all reference env vars)

Setting Up a New Environment

  1. Start from .env.example as the template
  2. Categorize each variable:
  1. Validate the new environment against the list of required variables. Node 20.6+ loads a file with --env-file and needs no dependency:

```bash

node --env-file=.env -e "

const required = ['DATABASE_URL', 'STRIPE_SECRET_KEY', 'APP_BASE_URL'];

const missing = required.filter(k => !process.env[k]);

if (missing.length) { console.error('missing: ' + missing.join(', ')); process.exit(1); }

console.log('all ' + required.length + ' required variables are set');

"

```

Run this in CI before the deploy step. A schema validator such as envalid or zod gives the same check inside the app at startup.

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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.