Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Analyze environment variables in JavaScript/TypeScript projects. Identifies unused variables, infers permission scopes, detects specific services (Stripe, AWS, Supabase), and documents code paths. Includes optional cleanup of unused variables with regression detection. Use when auditing .env files, reviewing security, or documenting project configuration.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-08 | ✗→✓ | ▲ Improved | 125% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 171% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 62% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 203% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 134% | 0% |
<objective> Perform a comprehensive audit of environment variables in a JS/TS project:
</objective>
<quick_start> Audit only (default):
.env* files in project rootprocess.env., import.meta.env., and destructured env patternsWith cleanup (--cleanup flag):
</quick_start>
<process>
Find all env-related files:
bashfind . -maxdepth 2 -name ".env*" -o -name "env.d.ts" | grep -v node_modules
Common files:
.env - Local development.env.local - Local overrides.env.development / .env.production - Environment-specific.env.example - Template for required variablesParse each env file for variable declarations:
Grep pattern: ^[A-Z][A-Z0-9_]+=Build a list of all declared variables with their source file.
Search for environment variable usage patterns:
Direct access:
process.env.VARIABLE_NAME
import.meta.env.VARIABLE_NAME
process.env["VARIABLE_NAME"]Destructured patterns:
javascriptconst { API_KEY, DATABASE_URL } = process.env
Framework-specific:
javascript// Next.js public vars NEXT_PUBLIC_* // Vite VITE_*
Use Grep tool with patterns:
process\.env\.([A-Z][A-Z0-9_]+)
import\.meta\.env\.([A-Z][A-Z0-9_]+)For each declared variable:
Flag potential issues:
Match variable names against known service patterns. See references/service-patterns.md for the complete list.
Categories:
Permission levels:
For each used variable, document:
Example:
STRIPE_SECRET_KEY
├── src/lib/stripe.ts:15 - Stripe client initialization
├── src/api/webhooks/stripe.ts:8 - Webhook signature verification
└── src/api/checkout/route.ts:23 - Create checkout sessionUse the template in templates/env-audit-report.md to generate the final document.
Output to: ENV_AUDIT.md in project root (or user-specified location)
Trigger: User passes --cleanup flag or explicitly requests cleanup after reviewing the audit report.
Display unused variables with context:
UNUSED VARIABLES (candidates for removal):
1. OLD_API_KEY (.env, .env.local)
- Last modified: [file date]
- No code references found
2. DEPRECATED_SERVICE_URL (.env)
- Last modified: [file date]
- No code references foundBefore confirming removal, search for dynamic access patterns that grep may have missed:
javascript// These patterns indicate variables might be used dynamically: process.env[variableName] // Dynamic key access process.env[`${prefix}_KEY`] // Template literal access Object.keys(process.env) // Iteration over all env vars { ...process.env } // Spread operator
Use Grep with patterns:
process\.env\[
Object\.keys\(process\.env\)
Object\.entries\(process\.env\)
\.\.\.process\.envIf dynamic access patterns found: Flag affected variables for manual review and warn user.
Use AskUserQuestion to confirm each removal:
The following variables appear unused. Select which to remove:
[ ] OLD_API_KEY - Remove from .env, .env.local
[ ] DEPRECATED_SERVICE_URL - Remove from .env
[ ] Skip cleanup
⚠️ Variables will be backed up before removal.Safety rules:
.env.example (it serves as documentation)Before modifying any file:
bash# Create timestamped backup directory mkdir -p .env-backups/$(date +%Y%m%d_%H%M%S) # Backup each env file being modified cp .env .env-backups/$(date +%Y%m%d_%H%M%S)/.env.backup cp .env.local .env-backups/$(date +%Y%m%d_%H%M%S)/.env.local.backup
For each confirmed variable:
Append cleanup summary to ENV_AUDIT.md:
markdown## Cleanup Log **Date:** [timestamp] **Backup Location:** .env-backups/[timestamp]/ ### Removed Variables | Variable | Removed From | Reason | |----------|--------------|--------| | OLD_API_KEY | .env, .env.local | Unused - no code references | ### Preserved (Manual Review Required) | Variable | Reason | |----------|--------| | DYNAMIC_VAR | Dynamic access pattern detected |
Purpose: Validate that removing unused variables doesn't break the application.
Before removing any variables, capture baseline state:
bash# Check if project builds successfully npm run build 2>&1 | tee .env-backups/pre-cleanup-build.log echo $? > .env-backups/pre-cleanup-build-status # Run tests if available npm test 2>&1 | tee .env-backups/pre-cleanup-test.log echo $? > .env-backups/pre-cleanup-test-status
Store exit codes:
0 = Success (baseline is green)Search for patterns that indicate runtime env var access:
High-risk patterns (require manual review):
javascript// Config objects that spread env const config = { ...process.env } // Dynamic key construction const key = `${SERVICE}_API_KEY` process.env[key] // Iteration patterns Object.entries(process.env).filter(([k]) => k.startsWith('FEATURE_')) // External config loaders require('dotenv').config({ path: customPath })
Detection commands:
Grep: process\.env\[(?!['"][A-Z])
Grep: Object\.(keys|values|entries)\(process\.env\)
Grep: \.\.\.process\.env
Grep: dotenv.*configIf detected: List affected files and require explicit user acknowledgment before proceeding.
After removing variables, run validation:
bash# Verify build still succeeds npm run build 2>&1 | tee .env-backups/post-cleanup-build.log POST_BUILD_STATUS=$? # Verify tests still pass npm test 2>&1 | tee .env-backups/post-cleanup-test.log POST_TEST_STATUS=$?
Compare pre and post states:
| Check | Pre-Cleanup | Post-Cleanup | Status | |-------|-------------|--------------|--------| | Build | ✅ Pass | ✅ Pass | OK | | Tests | ✅ Pass | ✅ Pass | OK |
If regression detected:
⚠️ REGRESSION DETECTED
Build/tests failed after removing variables.
Options:
If user requests rollback:
bash# Restore from backup cp .env-backups/[timestamp]/.env.backup .env cp .env-backups/[timestamp]/.env.local.backup .env.local # Verify restoration npm run build && npm test
If in a git repository, offer branch-based cleanup:
bash# Create cleanup branch git checkout -b env-cleanup/$(date +%Y%m%d) # After cleanup, changes can be reviewed via PR git add .env .env.local git commit -m "chore: remove unused environment variables Removed: - OLD_API_KEY (unused) - DEPRECATED_SERVICE_URL (unused) Backup: .env-backups/[timestamp]/"
Benefits:
git checkout -</process>
<reference_index> Service Patterns: references/service-patterns.md - Known services and their variable naming conventions </reference_index>
<success_criteria> Audit is complete when:
Cleanup is complete when (if --cleanup requested):
Regression prevention is complete when:
</success_criteria>
Other measured skills in the registry, with their headline benchmark lift.