Agent skill
generate-jwt-secret-env
Generate, repair, or verify a cryptographically secure JWT_SECRET in .env for Node.js and NestJS projects when code under src/ references JWT_SECRET and the active .env value is missing, empty, or set to change-me-in-production. Use when fixing JWT auth startup failures, hardening environment configuration, standardizing .env secrets, or repairing placeholder JWT_SECRET values.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/typescript-generate-jwt-secret-env-setup
SKILL.md
Generate JWT_SECRET in .env
Workflow
-
Resolve target files and preconditions.
- Require a repository root with a readable
src/directory. - Require a writable
.envfile; create.envonly if it is missing and the task asks to initialize environment values. - Preferred reference check:
rg -n --glob "src/**" "JWT_SECRET"
- Accept reference patterns such as:
config.get('JWT_SECRET')ConfigService.get('JWT_SECRET')process.env.JWT_SECRET
- Stop without editing
.envif nosrc/reference exists.
- Require a repository root with a readable
-
Inspect
.envand determine whether generation is needed.- Parse lines and locate active (non-comment)
JWT_SECRET=entries. - Generate only if:
- Key is absent, or
- Value is empty (
JWT_SECRET=,JWT_SECRET="",JWT_SECRET=''), or - Value is exactly
change-me-in-production(with or without quotes).
- Do not overwrite any other non-placeholder value.
- If multiple active keys exist, update only the first eligible active key by default.
- Parse lines and locate active (non-comment)
-
Generate a cryptographically secure secret.
- Preferred Node command:
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
- Accept equivalent secure output formats (
hexis also valid) when randomness comes from a cryptographically secure source.
- Preferred Node command:
-
Update
.envsafely.- If an active
JWT_SECRET=line exists and is empty/placeholder, replace only its value. - If no active key exists, append
JWT_SECRET=<generated>in a sensible auth/env section. - Preserve unrelated lines, comments, spacing style, and key order.
- If duplicate active keys exist, update only the first active eligible key and leave the rest unchanged unless the task explicitly asks for cleanup.
- If an active
-
Perform security checks.
- Confirm
.envis ignored by git (.gitignoreor equivalent ignore rules). - Confirm no command output, logs, or summaries expose the generated secret value.
- Never print the generated secret in summaries unless the user explicitly asks for it.
- If
.envis tracked by git and the task is to harden security, recommend rotating the leaked secret after ignore rules are fixed.
- Confirm
-
Run deterministic verification gates.
- Re-scan
src/references and confirm they still resolve toJWT_SECRET. - Confirm
.envnow has an activeJWT_SECRET=entry with a non-empty, non-placeholder value. - Report one of these outcomes:
updated(secret generated and written),unchanged-valid(existing non-placeholder secret kept),skipped-no-reference(nosrc/usage),blocked(missing permissions/files or other hard blocker with exact cause).
- Re-scan
Use detailed parsing and edge-case behavior from reference.md.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?