commandby razorvision

Generate Environment Variables

Interactively create a `.env.local` file with all required variables.

Installs: 0
Used in: 1 repos
Updated: 2d ago
$npx ai-builder add command razorvision/generate-env

Installs to .claude/commands/generate-env.md

# Generate Environment Variables

Interactively create a `.env.local` file with all required variables.

## Usage

```
/generate-env
```

## What This Command Does

1. **Reads .env.example** to find all required variables
2. **Asks for values** interactively
3. **Generates secrets** automatically where appropriate
4. **Creates .env.local** with your values
5. **Validates the configuration**

## Instructions for Claude

When the user runs `/generate-env`, follow these steps:

### Step 1: Check for Existing .env.local

```bash
ls .env.local
```

If exists, ask: "A .env.local file already exists. What would you like to do?
1. Overwrite it completely
2. Add missing variables only
3. Cancel"

### Step 2: Read .env.example

```bash
cat .env.example
```

Parse the file to identify:
- Required variables (marked with `[REQUIRED]`)
- Optional variables (marked with `[OPTIONAL]`)
- Variables with default values

### Step 3: Collect Values Interactively

Go through each section and ask for values:

---

**Application Settings**

"What's your application name? [default: my-app]"
→ `NEXT_PUBLIC_APP_NAME=user-input`

"What port should the dev server use? [default: 3000]"
→ `PORT=3000`

---

**Database**

"Which database provider are you using?
1. Supabase
2. Neon
3. PlanetScale
4. Local PostgreSQL
5. SQLite
6. Other (enter connection string)"

Based on selection, either:
- Provide instructions to get the connection string
- Ask for the connection string directly

"Enter your DATABASE_URL:"
→ `DATABASE_URL=user-input`

If serverless (Supabase/Neon), also ask:
"Enter your DIRECT_URL (for migrations):"
→ `DIRECT_URL=user-input`

---

**Authentication**

"Generate a new AUTH_SECRET? (recommended) [Y/n]"

If yes:
```bash
openssl rand -base64 32
```
→ `AUTH_SECRET=generated-secret`

"Are you using OAuth providers?"

If yes, ask for each:

**GitHub OAuth:**
"Do you have GitHub OAuth credentials? [y/N]"
If yes:
- "Enter GITHUB_CLIENT_ID:"
- "Enter GITHUB_CLIENT_SECRET:"

If no, provide setup instructions:
"To set up GitHub OAuth:
1. Go to https://github.com/settings/developers
2. Click 'New OAuth App'
3. Set callback: http://localhost:3000/api/auth/callback/github
4. Copy Client ID and Secret"

**Google OAuth:**
(Similar flow)

---

**External Services (Optional)**

"Do you want to configure any of these services?
1. OpenAI API
2. Stripe (payments)
3. Resend (email)
4. Sentry (error tracking)
5. None / Skip"

For each selected, ask for the API key/credentials.

---

### Step 4: Generate .env.local

Create the file with collected values:

```bash
# ==============================================================================
# ENVIRONMENT VARIABLES
# ==============================================================================
# Generated by /generate-env on [date]
# ==============================================================================

# ------------------------------------------------------------------------------
# APPLICATION
# ------------------------------------------------------------------------------
NODE_ENV=development
PORT=3000
NEXT_PUBLIC_APP_URL=http://localhost:3000

# ------------------------------------------------------------------------------
# DATABASE
# ------------------------------------------------------------------------------
DATABASE_URL="postgresql://..."
DIRECT_URL="postgresql://..."

# ------------------------------------------------------------------------------
# AUTHENTICATION
# ------------------------------------------------------------------------------
AUTH_SECRET="[generated]"
NEXTAUTH_URL=http://localhost:3000

# GitHub OAuth
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

# Google OAuth
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

# ------------------------------------------------------------------------------
# EXTERNAL SERVICES (Optional)
# ------------------------------------------------------------------------------
# OPENAI_API_KEY=
# STRIPE_SECRET_KEY=
# RESEND_API_KEY=
# SENTRY_DSN=
```

### Step 5: Write the File

Use the Write tool to create `.env.local`

### Step 6: Validate

Run a quick validation:
- Check DATABASE_URL format
- Verify AUTH_SECRET is set
- Confirm file was created

### Step 7: Summary

```
✅ Created .env.local with the following configuration:

Database: Supabase PostgreSQL
Auth: NextAuth.js with GitHub OAuth
External Services: None configured

Next steps:
1. Complete any empty OAuth credentials
2. Run: npm run dev
3. Test: http://localhost:3000/api/auth/signin
```

## Non-Interactive Mode

If the user provides a template:

```
/generate-env --from supabase --auth github
```

Generate based on preset configurations without asking questions.

## Environment Templates

**Supabase + NextAuth:**
```bash
DATABASE_URL="postgresql://postgres.[PROJECT_REF]:[PASSWORD]@aws-0-[REGION].pooler.supabase.com:6543/postgres?pgbouncer=true"
DIRECT_URL="postgresql://postgres.[PROJECT_REF]:[PASSWORD]@aws-0-[REGION].pooler.supabase.com:5432/postgres"
AUTH_SECRET="[generate]"
NEXTAUTH_URL=http://localhost:3000
```

**Neon + NextAuth:**
```bash
DATABASE_URL="postgresql://[USER]:[PASSWORD]@[HOST]/[DB]?sslmode=require"
AUTH_SECRET="[generate]"
NEXTAUTH_URL=http://localhost:3000
```

**Local Development:**
```bash
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/myapp_dev"
AUTH_SECRET="[generate]"
NEXTAUTH_URL=http://localhost:3000
```

Quick Install

$npx ai-builder add command razorvision/generate-env

Details

Type
command
Slug
razorvision/generate-env
Created
6d ago