Back to Skills

env-setup

verified

Set up secure environment variable management using dotenvx + direnv + git worktree. Use when user asks to set up env management, wants to encrypt .env files, or needs to configure environment variables for worktree-based development. Also use when setting up a new project that needs secure env handling.

View on GitHub

Marketplace

kazuph-dotfiles

kazuph/dotfiles

Plugin

dotenvx-direnv-worktree

development

Repository

kazuph/dotfiles
14stars

plugins/dotenvx-direnv-worktree/skills/env-setup/SKILL.md

Last Verified

January 25, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/kazuph/dotfiles/blob/main/plugins/dotenvx-direnv-worktree/skills/env-setup/SKILL.md -a claude-code --skill env-setup

Installation paths:

Claude
.claude/skills/env-setup/
Powered by add-skill CLI

Instructions

# Environment Setup Skill (dotenvx + direnv + worktree)

Git worktreeを使った並列開発で、環境変数を安全かつ効率的に管理する環境をセットアップします。

## Core Principle

**暗号化は常時維持**: ディスク上は暗号化、メモリ上のみ復号。復号されたファイルが作られることはない。

```
ディスク上          メモリ上(実行時のみ)
┌─────────────┐     ┌─────────────┐
│ .env        │     │ DATABASE_URL=xxx │
│ (暗号化)    │ ──→ │ API_KEY=yyy      │
│ xxxxxxxxxx  │     │ (復号済み)       │
└─────────────┘     └─────────────────┘
     ↑                    ↑
  常にこの状態        プロセス実行中のみ
```

## Tool Stack

| ツール | 役割 | インストール |
|--------|------|-------------|
| **git-wt** | Git worktree管理 | `brew install k1LoW/tap/git-wt` |
| **direnv** | ディレクトリ単位で環境変数を自動読み込み | `brew install direnv` |
| **dotenvx** | .envファイルの暗号化管理 | `npm install -g @dotenvx/dotenvx` |

## Setup Instructions

以下の手順で環境をセットアップしてください。

### Step 1: Check Prerequisites

まず必要なツールがインストールされているか確認:

```bash
# Check direnv
which direnv || echo "direnv not installed"

# Check dotenvx
which dotenvx || npm list -g @dotenvx/dotenvx || echo "dotenvx not installed"

# Check git-wt (optional but recommended)
git wt --version || echo "git-wt not installed (optional)"
```

インストールされていない場合は、ユーザーに案内してインストールを促す。

### Step 2: Create/Encrypt .env File

既存の.envがあれば暗号化、なければサンプルを作成:

```bash
# If .env exists
dotenvx encrypt

# The .env.keys file will be generated with DOTENV_PRIVATE_KEY
# Extract the key for .envrc
```

### Step 3: Create .envrc

以下の内容で.envrcを作成:

```bash
# .envrc
export DOTENV_PRIVATE_KEY="<key from .env.keys>"
eval "$(dotenvx decrypt --stdout --format shell)"
```

**重要**: .env.keysからDOTENV_PRIVATE_KEYの値を転記後、.env.keysは削除可能。

### Step 4: Update .gitignore

以下を.gitignoreに追加(未追加の場合):

```
.worktree
.artifacts
.envrc
.env.keys
```

### Step 5: Activate direnv

```bash
direnv allow
```

### Step 6: (Optional) Configure git-wt

> **Note:** git-wtは**プロジェクトローカルな.worktree/**に配置する設計です。

.gitconfigで設定:

```bash
git config --global wt.basedir ".worktree"
git config --global wt.copyignored true
git config --global --add wt.hook "npm install || pnpm in

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
4447 chars