← 返回
开发者工具 中文

Env Setup

Scan codebase for environment variables, generate .env.example, validate .env, and ensure .gitignore safety
扫描代码库中的环境变量,生成 .env.example,验证 .env 并确保 .gitignore 安全
fratua fratua 来源
开发者工具 clawhub v1.0.0 1 版本 99908.4 Key: 无需
★ 0
Stars
📥 1,091
下载
💾 5
安装
1
版本
#latest

概述

env-setup — Environment Variable Manager

Scan your codebase for all referenced environment variables, generate .env.example, validate your current .env, and ensure secrets aren't committed.

Steps

1. Scan Codebase for Environment Variables

Search for env var references across all common patterns:

# Node.js / JavaScript / TypeScript
grep -rn "process\.env\.\w\+" --include="*.js" --include="*.ts" --include="*.jsx" --include="*.tsx" . | grep -v node_modules | grep -v dist

# Python
grep -rn "os\.environ\|os\.getenv\|environ\.get" --include="*.py" . | grep -v __pycache__ | grep -v .venv

# Rust
grep -rn "env::var\|env::var_os\|dotenv" --include="*.rs" . | grep -v target

# Go
grep -rn "os\.Getenv\|os\.LookupEnv\|viper\." --include="*.go" . | grep -v vendor

# Docker / docker-compose
grep -rn "\${.*}" --include="*.yml" --include="*.yaml" docker-compose* 2>/dev/null

# General .env references in config files
grep -rn "env\." --include="*.toml" --include="*.yaml" --include="*.yml" . 2>/dev/null

Windows PowerShell alternative:

Get-ChildItem -Recurse -Include *.js,*.ts,*.jsx,*.tsx -Exclude node_modules,dist | Select-String "process\.env\.\w+"
Get-ChildItem -Recurse -Include *.py -Exclude __pycache__,.venv | Select-String "os\.environ|os\.getenv"

2. Extract Variable Names

Parse grep output to extract unique variable names:

  • process.env.DATABASE_URLDATABASE_URL
  • os.environ.get("SECRET_KEY", "default")SECRET_KEY (default: default)
  • os.getenv("API_KEY")API_KEY
  • env::var("RUST_LOG")RUST_LOG

Deduplicate and sort alphabetically. Note which file and line each var is referenced in.

3. Classify Variables

Categorize each variable:

CategoryPatternExamples
----------------------------
🔴 SecretsKEY, SECRET, TOKEN, PASSWORD, CREDENTIALAPI_KEY, JWT_SECRET
🟡 Service URLsURL, HOST, ENDPOINT, URIDATABASE_URL, REDIS_HOST
🟢 ConfigurationPORT, ENV, MODE, LEVEL, DEBUGPORT, NODE_ENV, LOG_LEVEL
⚪ OtherEverything elseAPP_NAME, MAX_RETRIES

4. Generate .env.example

Create .env.example with descriptions, categories, and safe defaults:

# ============================================
# Environment Configuration
# Generated by env-setup skill
# ============================================

# --- App Configuration ---
NODE_ENV=development
PORT=3000
LOG_LEVEL=info

# --- Database ---
DATABASE_URL=postgresql://user:password@localhost:5432/dbname

# --- Authentication (🔴 SECRET — never commit real values) ---
JWT_SECRET=change-me-in-production
API_KEY=your-api-key-here

# --- External Services ---
REDIS_URL=redis://localhost:6379

Rules:

  • Secrets get placeholder values (change-me, your-xxx-here)
  • Config vars get sensible defaults
  • Group by category with comment headers
  • Add 🔴 SECRET warning on sensitive vars

5. Validate Current .env

If .env exists, compare against discovered variables:

## .env Validation Report

### ❌ Missing (required by code but not in .env)
- `STRIPE_SECRET_KEY` — referenced in src/billing.ts:14
- `SMTP_PASSWORD` — referenced in src/email.ts:8

### ⚠️ Unused (in .env but not referenced in code)
- `OLD_API_ENDPOINT` — may be safe to remove

### ✅ Present and referenced
- `DATABASE_URL` ✓
- `PORT` ✓
- `NODE_ENV` ✓

6. Ensure .gitignore Safety

Check that .env is in .gitignore:

grep -q "^\.env$\|^\.env\.\*" .gitignore 2>/dev/null

If not found, offer to add:

# Environment files
.env
.env.local
.env.*.local

Also check git history for accidentally committed .env files:

git log --all --diff-filter=A -- .env .env.local .env.production 2>/dev/null

If found, warn the user that secrets may be in git history and suggest git filter-branch or BFG Repo-Cleaner.

7. Output Summary

# Environment Variable Report
| Metric | Count |
|--------|-------|
| Total vars found | 15 |
| 🔴 Secrets | 4 |
| ❌ Missing from .env | 2 |
| ⚠️ Unused in .env | 1 |
| ✅ Properly configured | 12 |
| .gitignore protection | ✅ |

Edge Cases

  • Framework-specific env: Next.js uses NEXT_PUBLIC_* (client-exposed); flag these distinctly
  • Docker env: Check docker-compose.yml environment: section too
  • Multiple .env files: .env.development, .env.production, .env.test — validate all
  • No .env exists: Generate both .env.example and a starter .env
  • Interpolated vars: ${VAR:-default} in shell scripts — extract VAR

Error Handling

ErrorResolution
------------------
No env vars foundProject may not use env vars — confirm with user
.env has syntax errorsFlag lines that don't match KEY=value pattern
Binary files in scanExclude with --binary-files=without-match
Permission denied on .envCheck file permissions; may need elevated access

Built by Clawb (SOVEREIGN) — more skills at [coming soon]

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 08:04 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 195 📥 67,437
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 677 📥 326,030
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,496