infra-config-setup-env
インフラ構成を環境に合わせて設定し、Zodというライブラリを使って設定内容を検証することで、設定ミスを防ぎ、安定したシステム環境を構築するSkill。
📜 元の英語説明(参考)
Environment configuration, Zod validation
🇯🇵 日本人クリエイター向け解説
インフラ構成を環境に合わせて設定し、Zodというライブラリを使って設定内容を検証することで、設定ミスを防ぎ、安定したシステム環境を構築するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o infra-config-setup-env.zip https://jpskill.com/download/10254.zip && unzip -o infra-config-setup-env.zip && rm infra-config-setup-env.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10254.zip -OutFile "$d\infra-config-setup-env.zip"; Expand-Archive "$d\infra-config-setup-env.zip" -DestinationPath $d -Force; ri "$d\infra-config-setup-env.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
infra-config-setup-env.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
infra-config-setup-envフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
環境管理
クイックガイド: アプリごとの .env ファイル。フレームワーク固有のプレフィックス(Next.js の場合は
NEXT_PUBLIC_*、Vite の場合はVITE_*)。起動時の Zod バリデーション。.env.example テンプレートの維持。シークレットのコミット禁止(.gitignore)。環境に基づいたフィーチャーフラグ。
<critical_requirements>
重要: この Skill を使用する前に
すべてのコードは CLAUDE.md のプロジェクト規約に従う必要があります (kebab-case、名前付きエクスポート、インポート順序、
import type、名前付き定数)
(アプリケーションの起動時に、すべての環境変数を Zod で検証する必要があります)
(クライアント側の変数には、フレームワーク固有のプレフィックスを使用する必要があります - Next.js の場合は NEXT_PUBLIC_*、Vite の場合は VITE_*)
(必要なすべての変数がドキュメント化された .env.example テンプレートを維持する必要があります)
(シークレットをバージョン管理にコミットしてはいけません - .env.local と CI シークレットを使用してください)
(アプリごとの .env ファイルを使用する必要があります - ルートレベルの .env ファイルは使用しないでください)
</critical_requirements>
自動検出: 環境変数、.env ファイル、Zod バリデーション、t3-env、@t3-oss/env、シークレット管理、NEXT_PUBLIC_ プレフィックス、VITE_ プレフィックス、フィーチャーフラグ、z.stringbool
使用する場面:
- 起動時に型安全な環境変数のための Zod バリデーションを設定する
- フレームワーク固有のプレフィックスを持つアプリごとの .env ファイルを管理する
- シークレットを保護する(コミットしない、.env.local と CI シークレットを使用する)
- 環境に基づいたフィーチャーフラグを実装する
使用しない場面:
- ランタイム構成の変更(外部のフィーチャーフラグサービスを使用する)
- ユーザー固有の設定(データベースまたはユーザー設定を使用する)
- 頻繁に変更される値(構成 API またはデータベースを使用する)
- 段階的なロールアウトを伴う複雑な A/B テスト(専用のフィーチャーフラグサービスを使用する)
カバーする主要なパターン:
- アプリごとの .env ファイル(ルートレベルではない、競合を防ぐ)
- 型の安全性と早期の失敗のための起動時の Zod バリデーション
- Next.js/Vite プロジェクト向けの T3 Env パターン(推奨)
- フレームワーク固有のプレフィックス(クライアントの場合は
NEXT_PUBLIC_*、Vite クライアントの場合はVITE_*) - ドキュメントとオンボーディングのための .env.example テンプレート
詳細なリソース:
- コード例については、examples/ フォルダを参照してください:
- examples/core.md - 必須パターン(アプリごとの .env、Zod バリデーション)
- examples/t3-env.md - Next.js/Vite 向けの T3 Env パターン(推奨)
- examples/naming-and-templates.md - フレームワークプレフィックス、.env.example
- examples/security-and-secrets.md - シークレット管理
- examples/feature-flags-and-config.md - フィーチャーフラグ、集中構成
- 意思決定フレームワークとアンチパターンについては、reference.md を参照してください
<philosophy>
哲学
環境管理は、構成はコードであるという原則に従います。つまり、検証、型付け、およびバージョン管理されるべきです。このシステムは、アプリごとの .env ファイルとフレームワーク固有のプレフィックス、起動時の Zod バリデーション、およびシークレットの漏洩を防ぐための厳格なセキュリティプラクティスを使用します。
</philosophy>
<patterns>
コアパターン
パターン 1: アプリごとの環境ファイル
各アプリ/パッケージは、競合を防ぎ、所有権を明確にするために、独自の .env ファイルを持ちます。
ファイル構造
apps/
├── client-next/
│ ├── .env # ローカル開発 (NEXT_PUBLIC_API_URL)
│ └── .env.production # 本番環境のオーバーライド
├── client-react/
│ ├── .env # ローカル開発
│ └── .env.production # 本番環境のオーバーライド
└── server/
├── .env # ローカルサーバー構成
├── .env.example # 新規開発者向けのテンプレート
└── .env.local.example # ローカルオーバーライドテンプレート
packages/
├── api/
│ └── .env # API パッケージ構成
└── api-mocks/
└── .env # モックサーバー構成
ファイルの種類と目的
.env- デフォルトの開発値(アプリの場合はコミット、機密性の高いパッケージの場合は gitignore).env.example- ドキュメントテンプレート(コミット、必要なすべての変数を示す).env.local- ローカル開発者のオーバーライド(gitignore、.envよりも優先される).env.production- 本番環境構成(コミットまたは CI シークレット内).env.local.example- ローカルオーバーライドテンプレート(コミット)
ロード順序と優先順位
Next.js のロード順序(優先度が高い順):
process.env(環境にすでに設定されている).env.$(NODE_ENV).local(例:.env.production.local).env.local(NODE_ENV=testの場合はロードされない).env.$(NODE_ENV)(例:.env.production).env
Vite のロード順序:
.env.[mode].local(例:.env.production.local).env.[mode](例:.env.production).env.local.env
例外: キャッシュの無効化のために、共有変数はビルドツールの環境構成に含めることができます。
完全なコード例については、examples/core.md を参照してください。
パターン 2: Zod による型安全な環境変数
Zod スキーマを使用して、アプリケーションの起動時に環境変数を検証します。スキーマを定義し、起動時に解析し、型付きの env オブジェクトをエクスポートします。
// lib/env.ts
const envSchema = z.object({
VITE_API_URL: z.string().url(),
VITE_API_TIMEOUT: z.coerce.number().default(DEFAULT_API_TIMEOUT_MS),
VITE_ENABLE_ANALYTICS: z.stringbool().default(false), // Zod 4+ (z.coerce.boolean() ではない)
});
export const env = envSchema.parse(import.meta.env);
主な注意点:
z.coerce.boolean()は"false"をtrueに変換します(文字列は truthy であるため) - 必ず代わりにz.stringbool()を使用してください- Zod 4 のエラー処理には、
error.errorsではなくerror.issuesを使用してください
注: Next.js/Vite プロジェクトの場合は、クライアント/サーバー変数の分離とビルド時の検証のために、T3 Env (
@t3-oss/env-nextjsまたは@t3-oss/env-core) を検討してください。examples/t3-env.md を参照してください。
完全な良い例/悪い例の比較については、examples/core.md を参照してください。
パターン 3: フレームワーク固有の命名規則
フレームワークを使用します
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Environment Management
Quick Guide: Per-app .env files. Framework-specific prefixes (
NEXT_PUBLIC_*for Next.js,VITE_*for Vite). Zod validation at startup. Maintain .env.example templates. Never commit secrets (.gitignore). Environment-based feature flags.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST validate ALL environment variables with Zod at application startup)
(You MUST use framework-specific prefixes for client-side variables - NEXT_PUBLIC_* for Next.js, VITE_* for Vite)
(You MUST maintain .env.example templates with ALL required variables documented)
(You MUST never commit secrets to version control - use .env.local and CI secrets)
(You MUST use per-app .env files - NOT root-level .env files)
</critical_requirements>
Auto-detection: Environment variables, .env files, Zod validation, t3-env, @t3-oss/env, secrets management, NEXT_PUBLIC_ prefix, VITE_ prefix, feature flags, z.stringbool
When to use:
- Setting up Zod validation for type-safe environment variables at startup
- Managing per-app .env files with framework-specific prefixes
- Securing secrets (never commit, use .env.local and CI secrets)
- Implementing environment-based feature flags
When NOT to use:
- Runtime configuration changes (use an external feature flag service)
- User-specific settings (use database or user preferences)
- Frequently changing values (use configuration API or database)
- Complex A/B testing with gradual rollouts (use a dedicated feature flag service)
Key patterns covered:
- Per-app .env files (not root-level, prevents conflicts)
- Zod validation at startup for type safety and early failure
- T3 Env pattern for Next.js/Vite projects (recommended)
- Framework-specific prefixes (
NEXT_PUBLIC_*for client,VITE_*for Vite client) - .env.example templates for documentation and onboarding
Detailed Resources:
- For code examples, see examples/ folder:
- examples/core.md - Essential patterns (per-app .env, Zod validation)
- examples/t3-env.md - T3 Env pattern for Next.js/Vite (recommended)
- examples/naming-and-templates.md - Framework prefixes, .env.example
- examples/security-and-secrets.md - Secret management
- examples/feature-flags-and-config.md - Feature flags, centralized config
- For decision frameworks and anti-patterns, see reference.md
<philosophy>
Philosophy
Environment management follows the principle that configuration is code -- it should be validated, typed, and versioned. The system uses per-app .env files with framework-specific prefixes, Zod validation at startup, and strict security practices to prevent secret exposure.
</philosophy>
<patterns>
Core Patterns
Pattern 1: Per-App Environment Files
Each app/package has its own .env file to prevent conflicts and clarify ownership.
File Structure
apps/
├── client-next/
│ ├── .env # Local development (NEXT_PUBLIC_API_URL)
│ └── .env.production # Production overrides
├── client-react/
│ ├── .env # Local development
│ └── .env.production # Production overrides
└── server/
├── .env # Local server config
├── .env.example # Template for new developers
└── .env.local.example # Local overrides template
packages/
├── api/
│ └── .env # API package config
└── api-mocks/
└── .env # Mock server config
File Types and Purpose
.env- Default development values (committed for apps, gitignored for sensitive packages).env.example- Documentation template (committed, shows all required variables).env.local- Local developer overrides (gitignored, takes precedence over.env).env.production- Production configuration (committed or in CI secrets).env.local.example- Local override template (committed)
Loading Order and Precedence
Next.js loading order (highest to lowest priority):
process.env(already set in environment).env.$(NODE_ENV).local(e.g.,.env.production.local).env.local(not loaded whenNODE_ENV=test).env.$(NODE_ENV)(e.g.,.env.production).env
Vite loading order:
.env.[mode].local(e.g.,.env.production.local).env.[mode](e.g.,.env.production).env.local.env
Exception: Shared variables can go in your build tool's env configuration for cache invalidation
See examples/core.md for complete code examples.
Pattern 2: Type-Safe Environment Variables with Zod
Validate environment variables at application startup using Zod schemas. Define a schema, parse at startup, export a typed env object.
// lib/env.ts
const envSchema = z.object({
VITE_API_URL: z.string().url(),
VITE_API_TIMEOUT: z.coerce.number().default(DEFAULT_API_TIMEOUT_MS),
VITE_ENABLE_ANALYTICS: z.stringbool().default(false), // Zod 4+ (NOT z.coerce.boolean())
});
export const env = envSchema.parse(import.meta.env);
Key gotchas:
z.coerce.boolean()converts"false"totrue(string is truthy) - always usez.stringbool()instead- Use
error.issues(noterror.errors) for Zod 4 error handling
Note: For Next.js/Vite projects, consider T3 Env (
@t3-oss/env-nextjsor@t3-oss/env-core) for client/server variable separation and build-time validation. See examples/t3-env.md.
See examples/core.md for complete good/bad comparisons.
Pattern 3: Framework-Specific Naming Conventions
Use framework-specific prefixes for client-side variables and SCREAMING_SNAKE_CASE for all environment variables.
Mandatory Conventions
- SCREAMING_SNAKE_CASE - All environment variables use uppercase with underscores
- Descriptive names - Variable names clearly indicate purpose
- Framework prefixes - Use
NEXT_PUBLIC_*(Next.js) orVITE_*(Vite) for client-side variables
Framework Prefixes
Next.js:
NEXT_PUBLIC_*- Client-side accessible (embedded in bundle) - use for API URLs, public keys, feature flags- No prefix - Server-side only (database URLs, secret keys, API tokens)
Vite:
VITE_*- Client-side accessible (embedded in bundle) - use for API URLs, public configuration- No prefix - Build-time only (not exposed to client)
Node.js/Server:
NODE_ENV- Standard environment (development,production,test)PORT- Server port number- No prefix - All variables available server-side
See examples/naming-and-templates.md for complete code examples with good/bad comparisons.
</patterns>
<integration>
Integration Guide
Core dependencies:
- Zod (v4+): Runtime validation and type inference for environment variables
- T3 Env (
@t3-oss/env-nextjs,@t3-oss/env-core): Recommended wrapper for client/server separation
Framework support:
- Next.js: Automatic .env file loading with
NEXT_PUBLIC_*prefix for client-side - Vite: Automatic .env file loading with
VITE_*prefix for client-side
Monorepo considerations:
- Declare shared env vars in your build tool's env configuration for cache invalidation
- Use per-app .env files even in monorepos to prevent conflicts
Replaces / Conflicts with:
- Hardcoded configuration values (use env vars instead)
- Runtime feature flag services for simple boolean flags (use env vars first, upgrade when needing gradual rollouts)
</integration>
<decision_framework>
Decision Framework
See reference.md for complete decision frameworks including environment configuration and feature flag decisions.
</decision_framework>
<red_flags>
RED FLAGS
High Priority Issues:
- Committing secrets to version control (.env files with real credentials)
- Using environment variables directly without Zod validation (causes runtime errors)
- Using
NEXT_PUBLIC_*orVITE_*prefix for secrets (embeds in client bundle)
Medium Priority Issues:
- Missing .env.example documentation (poor onboarding experience)
- Using production secrets in development (security risk)
- Root-level .env in monorepo (causes conflicts)
Gotchas:
- Next.js/Vite embed prefixed variables at build time, not runtime - requires rebuild to change
- Environment variables are strings - use
z.coerce.number()for numbers, usez.stringbool()for booleans (Zod 4+) - CRITICAL:
z.coerce.boolean()converts "false" totrue(string is truthy) - usez.stringbool()(Zod 4+) instead - Empty string env vars are NOT
undefined- use T3 Env'semptyStringAsUndefined: trueoption - Monorepo build tool caches may NOT be invalidated by env changes unless declared in the tool's env configuration
See reference.md for complete RED FLAGS, anti-patterns, and checklists.
</red_flags>
<critical_reminders>
CRITICAL REMINDERS
All code must follow project conventions in CLAUDE.md
(You MUST validate ALL environment variables with Zod at application startup)
(You MUST use framework-specific prefixes for client-side variables - NEXT_PUBLIC_* for Next.js, VITE_* for Vite)
(You MUST maintain .env.example templates with ALL required variables documented)
(You MUST never commit secrets to version control - use .env.local and CI secrets)
(You MUST use per-app .env files - NOT root-level .env files)
Failure to follow these rules will cause runtime errors, security vulnerabilities, and configuration confusion.
</critical_reminders>