<< All versions
Skill v1.0.1
currentAutomated scan100/100majiayu000/claude-skill-registry/direnv
3 files
──Details
PublishedJune 24, 2026 at 09:35 PM
Content Hashsha256:00236fbb951d8cd3...
Git SHA6d0bffa14ce1
Bump Typepatch
──Files
Files (1 file, 5.9 KB)
SKILL.md5.9 KBactive
SKILL.md · 354 lines · 5.9 KB
version: "1.0.1" name: direnv description: Direnv environment management for automatic per-project shell configuration. Use when setting up .envrc files, configuring project-specific environment variables, or integrating direnv with development tools like nix, asdf, pyenv, or nvm. user-invocable: false
Direnv Skill
This skill provides direnv configuration patterns and best practices for automatic environment management.
Basic .envrc Structure
bash
# .envrc - Auto-loaded when entering directory# Environment variablesexport DATABASE_URL="postgresql://localhost:5432/myapp_dev"export API_KEY="dev-key-only"export DEBUG=true# PATH modificationsPATH_add binPATH_add scripts# Source additional filessource_env_if_exists .envrc.local
Security Best Practices
Never Commit Secrets
bash
# .envrc - Committed to repo (safe defaults only)export DATABASE_URL="${DATABASE_URL:-postgresql://localhost:5432/dev}"export LOG_LEVEL="${LOG_LEVEL:-debug}"# Load local overrides with real secretssource_env_if_exists .envrc.local
bash
# .envrc.local - NEVER commit (add to .gitignore)export DATABASE_URL="postgresql://user:real_password@prod-db:5432/prod"export API_KEY="sk-real-production-key"
.gitignore Entry
gitignore
# Always ignore local environment overrides.envrc.local.envrc.private
Built-in Functions
Path Management
bash
# Add to PATH (prepends)PATH_add binPATH_add node_modules/.binPATH_add .venv/bin# Add to PATH only if directory existspath_add bin 2>/dev/null || true
Environment Loading
bash
# Source another envrc if it existssource_env_if_exists ../.envrcsource_env_if_exists .envrc.local# Load from .env filedotenvdotenv_if_exists .env.local# Source a file (error if missing)source_env .envrc.shared
Layout Functions
bash
# Python virtual environmentlayout pythonlayout python3layout pyenv 3.11.0# Node.jslayout node# Rubylayout ruby# Golayout go
Language-Specific Patterns
Python Projects
bash
# .envrc for Python with uv/piplayout python3# Or with specific version via pyenvlayout pyenv 3.11# Environment variablesexport PYTHONDONTWRITEBYTECODE=1export PYTHONUNBUFFERED=1# Django settingsexport DJANGO_SETTINGS_MODULE="config.settings.local"export DJANGO_DEBUG=true# Databaseexport DATABASE_URL="${DATABASE_URL:-postgresql://localhost:5432/myapp_dev}"# Load secrets from local filesource_env_if_exists .envrc.local
Node.js Projects
bash
# .envrc for Node.jslayout node# Use specific Node version with nvmuse nvm 20# Or with asdfuse asdf# Add local binaries to pathPATH_add node_modules/.bin# Environmentexport NODE_ENV=developmentexport PORT=3000source_env_if_exists .envrc.local
Go Projects
bash
# .envrc for Golayout go# Set Go-specific varsexport CGO_ENABLED=0export GOFLAGS="-mod=vendor"source_env_if_exists .envrc.local
Rust Projects
bash
# .envrc for Rustexport CARGO_HOME="${PWD}/.cargo"export RUSTUP_HOME="${PWD}/.rustup"PATH_add target/debugPATH_add target/releasesource_env_if_exists .envrc.local
Integration Patterns
With asdf Version Manager
bash
# .envrc with asdfuse asdf# This reads .tool-versions and sets up all tools# Ensure .tool-versions exists:# python 3.11.0# nodejs 20.10.0# postgres 15.0
With Nix
bash
# .envrc with nix-shelluse nix# Or with flakesuse flake# With specific nixpkgsuse nix -p python311 nodejs_20
With Docker Compose
bash
# .envrc for Docker-based developmentexport COMPOSE_PROJECT_NAME="myapp"export COMPOSE_FILE="docker-compose.yml:docker-compose.dev.yml"# Container environmentexport DOCKER_BUILDKIT=1source_env_if_exists .envrc.local
Monorepo Patterns
Root .envrc
bash
# /monorepo/.envrcexport MONOREPO_ROOT="${PWD}"export PATH="${MONOREPO_ROOT}/scripts:${PATH}"# Shared configurationexport LOG_FORMAT=jsonexport TZ=UTC
Service .envrc
bash
# /monorepo/services/api/.envrc# Inherit from parentsource_env ../.envrc# Service-specificexport SERVICE_NAME="api"export PORT=8080layout python3
Strict Mode Pattern
bash
# .envrc with strict requirementsstrict_env# Now all required vars must be set: "${DATABASE_URL:?DATABASE_URL must be set}": "${API_KEY:?API_KEY must be set}"# Or provide defaultsexport LOG_LEVEL="${LOG_LEVEL:-info}"
Common Patterns
Watch and Reload
bash
# .envrcwatch_file .tool-versionswatch_file requirements.txtwatch_file package.json# Reload when these files change
Conditional Configuration
bash
# .envrc with conditional logicif has python3; thenlayout python3elif has python; thenlayout pythonfiif [[ -f "package.json" ]]; thenPATH_add node_modules/.binfi
Export Functions
bash
# .envrc with helper functionsexport_function() {local name=$1local body=$2eval "$name() { $body; }"export -f "$name"}export_function run_tests "pytest tests/ -v"export_function lint "ruff check . && mypy ."
Anti-Patterns to Avoid
bash
# ❌ Bad: Hardcoded secretsexport API_KEY="sk-live-abc123"# ✅ Good: Use local overridesexport API_KEY="${API_KEY:-}"source_env_if_exists .envrc.local# ❌ Bad: Absolute pathsexport VENV_PATH="/Users/john/projects/myapp/.venv"# ✅ Good: Relative pathsexport VENV_PATH="${PWD}/.venv"# ❌ Bad: Modifying system pathsexport PATH="/usr/local/custom:${PATH}"# ✅ Good: Use PATH_add for project pathsPATH_add bin
Setup Commands
bash
# Install direnv (macOS)brew install direnv# Install direnv (Ubuntu/Debian)sudo apt install direnv# Add to shell (bash)echo 'eval "$(direnv hook bash)"' >> ~/.bashrc# Add to shell (zsh)echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc# Add to shell (fish)echo 'direnv hook fish | source' >> ~/.config/fish/config.fish# Allow .envrc in current directorydirenv allow# Reload after changesdirenv reload# Block .envrcdirenv deny