direnv
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.
Best use case
direnv is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
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.
Teams using direnv should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/direnv/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How direnv Compares
| Feature / Agent | direnv | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
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.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 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 variables
export DATABASE_URL="postgresql://localhost:5432/myapp_dev"
export API_KEY="dev-key-only"
export DEBUG=true
# PATH modifications
PATH_add bin
PATH_add scripts
# Source additional files
source_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 secrets
source_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 bin
PATH_add node_modules/.bin
PATH_add .venv/bin
# Add to PATH only if directory exists
path_add bin 2>/dev/null || true
```
### Environment Loading
```bash
# Source another envrc if it exists
source_env_if_exists ../.envrc
source_env_if_exists .envrc.local
# Load from .env file
dotenv
dotenv_if_exists .env.local
# Source a file (error if missing)
source_env .envrc.shared
```
### Layout Functions
```bash
# Python virtual environment
layout python
layout python3
layout pyenv 3.11.0
# Node.js
layout node
# Ruby
layout ruby
# Go
layout go
```
## Language-Specific Patterns
### Python Projects
```bash
# .envrc for Python with uv/pip
layout python3
# Or with specific version via pyenv
layout pyenv 3.11
# Environment variables
export PYTHONDONTWRITEBYTECODE=1
export PYTHONUNBUFFERED=1
# Django settings
export DJANGO_SETTINGS_MODULE="config.settings.local"
export DJANGO_DEBUG=true
# Database
export DATABASE_URL="${DATABASE_URL:-postgresql://localhost:5432/myapp_dev}"
# Load secrets from local file
source_env_if_exists .envrc.local
```
### Node.js Projects
```bash
# .envrc for Node.js
layout node
# Use specific Node version with nvm
use nvm 20
# Or with asdf
use asdf
# Add local binaries to path
PATH_add node_modules/.bin
# Environment
export NODE_ENV=development
export PORT=3000
source_env_if_exists .envrc.local
```
### Go Projects
```bash
# .envrc for Go
layout go
# Set Go-specific vars
export CGO_ENABLED=0
export GOFLAGS="-mod=vendor"
source_env_if_exists .envrc.local
```
### Rust Projects
```bash
# .envrc for Rust
export CARGO_HOME="${PWD}/.cargo"
export RUSTUP_HOME="${PWD}/.rustup"
PATH_add target/debug
PATH_add target/release
source_env_if_exists .envrc.local
```
## Integration Patterns
### With asdf Version Manager
```bash
# .envrc with asdf
use 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-shell
use nix
# Or with flakes
use flake
# With specific nixpkgs
use nix -p python311 nodejs_20
```
### With Docker Compose
```bash
# .envrc for Docker-based development
export COMPOSE_PROJECT_NAME="myapp"
export COMPOSE_FILE="docker-compose.yml:docker-compose.dev.yml"
# Container environment
export DOCKER_BUILDKIT=1
source_env_if_exists .envrc.local
```
## Monorepo Patterns
### Root .envrc
```bash
# /monorepo/.envrc
export MONOREPO_ROOT="${PWD}"
export PATH="${MONOREPO_ROOT}/scripts:${PATH}"
# Shared configuration
export LOG_FORMAT=json
export TZ=UTC
```
### Service .envrc
```bash
# /monorepo/services/api/.envrc
# Inherit from parent
source_env ../.envrc
# Service-specific
export SERVICE_NAME="api"
export PORT=8080
layout python3
```
## Strict Mode Pattern
```bash
# .envrc with strict requirements
strict_env
# Now all required vars must be set
: "${DATABASE_URL:?DATABASE_URL must be set}"
: "${API_KEY:?API_KEY must be set}"
# Or provide defaults
export LOG_LEVEL="${LOG_LEVEL:-info}"
```
## Common Patterns
### Watch and Reload
```bash
# .envrc
watch_file .tool-versions
watch_file requirements.txt
watch_file package.json
# Reload when these files change
```
### Conditional Configuration
```bash
# .envrc with conditional logic
if has python3; then
layout python3
elif has python; then
layout python
fi
if [[ -f "package.json" ]]; then
PATH_add node_modules/.bin
fi
```
### Export Functions
```bash
# .envrc with helper functions
export_function() {
local name=$1
local body=$2
eval "$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 secrets
export API_KEY="sk-live-abc123"
# ✅ Good: Use local overrides
export API_KEY="${API_KEY:-}"
source_env_if_exists .envrc.local
# ❌ Bad: Absolute paths
export VENV_PATH="/Users/john/projects/myapp/.venv"
# ✅ Good: Relative paths
export VENV_PATH="${PWD}/.venv"
# ❌ Bad: Modifying system paths
export PATH="/usr/local/custom:${PATH}"
# ✅ Good: Use PATH_add for project paths
PATH_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 directory
direnv allow
# Reload after changes
direnv reload
# Block .envrc
direnv deny
```Related Skills
bgo
Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.
e2e-test
Run E2E test scenarios against running services. Use for happy path testing, unhappy flows, debugging, or when user says "otestuj", "proved test", "zkus flow".
e2e-generate
Generate end-to-end tests with Playwright browser automation
Dynamics 365 Automation
Dynamics 365 Automation: manage CRM contacts, accounts, leads, opportunities, sales orders, invoices, and cases via the Dynamics CRM Web API
dynamic-application-security-testing
Perform dynamic security testing against running web applications and APIs to discover vulnerabilities through active probing and fuzzing.
dyad:swarm-pr-review
Team-based PR review using Claude Code swarm. Spawns three specialized teammates (correctness expert, code health expert, UX wizard) who review the PR diff, discuss findings with each other, and reach consensus on real issues. Posts a summary with merge verdict and inline comments for HIGH/MEDIUM issues.
dry-principle
This rule enforces the Don't Repeat Yourself principle to avoid code duplication and improve maintainability.
drizzle-patterns
Drizzle ORM patterns for SQLite - queries, relations, and safety guidelines. Use when writing database queries or debugging issues.
draw-io
Generate polished draw.io diagrams for Azure architectures with WAF-aligned design, proper layering, trust boundaries, and professional styling. Use when asked for "draw.io", "architecture diagram", "Azure diagram", "solution diagram", "WAF", "landing zone", "private endpoint", "hub-spoke", or any visual diagram in .drawio format. Outputs XML with Azure color palette, proper z-ordering, and audience-aware structure.
dr-jskill
Creates Java + Spring Boot projects: Web applications, full-stack apps with Vue.js or Angular or React or vanilla JS, PostgreSQL, REST APIs, and Docker. Use when creating Spring Boot projects, setting up Java microservices, or building enterprise applications with the Spring Framework.
dotnet-windbg-debugging
Debugs Windows apps via WinDbg MCP. Crash, hang, high-CPU, and memory triage from dumps or live attach.
dotnet-webapi
Build ASP.NET Core Web APIs with .NET 10 (C# 14.0). Supports project scaffolding, CRUD operations, Entity Framework integration, dependency injection, testing with xUnit, Docker containerization, and following 2025 best practices. Use when creating REST APIs, microservices, backend services, implementing CRUD operations, setting up Entity Framework, adding authentication/authorization, or containerizing .NET applications. Triggers on .NET, ASP.NET Core, C#, Web API, REST API, microservices, dotnet, csharp development tasks.