direnv
Skill1 starsChanged 7 months agoMITView on GitHub
Set up per-directory environments with direnv for `.envrc` loading, variable management, and nix/devenv/asdf integration.
- Reads credentials
- Deletes or force-pushes
- Installs packages
2 other projects use a version of this.
Adopted by
Most recently taken up by
- Cogni-AI-OU/cogni-ai-agent-skillstheir own version, first seen May 19, 2026
- aaronsb/claude-code-configtheir own version, first seen Feb 6, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- aaronsb/claude-code-config★ 18same name
- Cogni-AI-OU/cogni-ai-agent-skills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository36 other files it gives its agents.
- skills/backend-best-practices/AGENTS.mdAGENTS.md
- adr-writerSkill
- application-healthchecksSkill
- backend-best-practicesSkill
- bspec-prd-discoverySkill
- bspec-story-implementationSkill
- bspec-story-reviewSkill
- bspec-story-syncSkill
- bspec-technical-architectureSkill
- bspec-workflowSkill
- conventional-commitsSkill
- copier-scaffoldSkill
- devenvSkill
- docker-composeSkill
- dockerfileSkill
- docker-setupSkill
- docs-writerSkill
- github-actions-dockerSkill
- gitleaks-setupSkill
- golang-developmentSkill
- golang-slogSkill
- golang-testingSkill
- playwright-devenvSkill
- project-webappSkill
- readme-writerSkill
- release-drafter-setupSkill
- release-drafterSkill
- release-notesSkill
- renovate-pr-triageSkill
- renovate-setupSkill
- structured-loggingSkill
- summarize-articleSkill
- summarize-youtube-videoSkill
- tailwind-v4Skill
- vicinae-extensionsSkill
- zensical-setupSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 4 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 10
Use this skill when working with .envrc files, project-specific environment configuration, or integrating development tools that need …
- Distinctive: line 23
Automatic activation: - No manual sourcing required
- Distinctive: line 46
Add to your shell config:
- Very specific: line 264
Rule: Never commit secrets to .envrc - load from secure stores or use .envrc.local (gitignored).
- Very specific: line 594
If direnv is a binary (not a shell function), the hook is not installed.
- Very specific: line 602
If > 1 second, optimize your .envrc:
- Distinctive: line 604
Use layout directories for caching
- Distinctive: line 605
Add conditional checks to skip unnecessary work
- Very specific: line 623
ALWAYS run
direnv allow: after editing .envrc - it won't activate without approval. - Very specific: line 626
Use
layoutcommands: instead of manual PATH manipulation when available. - Very specific: line 631
Use
hasto check command existence: before using tools that might not be installed.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
direnv - Environment Variable Manager
Use this skill when working with .envrc files, project-specific environment configuration, or integrating development tools that need automatic environment activation.
When to Use
- Creating or updating a
.envrcfile for a project - Setting up automatic environment activation for nix, devenv, asdf, or mise
- Troubleshooting environment variable loading or
direnv allowissues - Optimising
.envrcperformance with caching or watch files
Philosophy
direnv automatically loads and unloads environment variables based on your current directory. Core benefits:
- Automatic activation - No manual sourcing required
- Secure by default - Requires explicit approval before executing
.envrc - Shell-agnostic - Works with bash, zsh, fish, etc.
- Language-neutral - Integrates with nix, asdf, mise, devenv, etc.
- Per-directory isolation - Each project has its own environment
Quick Start
Installation
# macOS
brew install direnv
# Ubuntu/Debian
apt install direnv
# Nix
nix-env -i direnvShell Integration (REQUIRED)
Add to your shell config:
# ~/.bashrc or ~/.bash_profile
eval "$(direnv hook bash)"
# ~/.zshrc
eval "$(direnv hook zsh)"
# ~/.config/fish/config.fish
direnv hook fish | sourceCRITICAL: Restart your shell after adding the hook.
Basic .envrc
# .envrc
export DATABASE_URL="postgres://localhost:5432/myapp"
export API_KEY="dev-key-12345"
export NODE_ENV="development"Allow the .envrc
cd /path/to/project
direnv allowThe environment is now loaded. When you cd away, it's automatically unloaded.
.envrc Patterns
Loading .env files
# .envrc
dotenvLoads .env file in the same directory (dotenv format: KEY=value).
# Load from custom path
dotenv .env.local
dotenv config/.env.productionExtending PATH
# .envrc
PATH_add bin
PATH_add node_modules/.bin
PATH_add scriptsPrepends directories to PATH. Automatically creates absolute paths.
Layout Commands (Language Tools)
direnv provides "layouts" for common language environments:
# .envrc
# Node.js (uses project's node_modules)
layout node
# Python virtualenv
layout python
layout python python3.11
# Ruby
layout ruby
# Go
layout go
# Perl
layout perlCustom Layout Functions
# .envrc
layout_custom() {
export PROJECT_ROOT="$PWD"
export TEMP_DIR="$PWD/.tmp"
mkdir -p "$TEMP_DIR"
PATH_add "$PROJECT_ROOT/bin"
}
layout customNix Integration
# .envrc
use nixLoads packages from shell.nix or default.nix in current directory.
With flakes:
# .envrc
use flakeLoads from flake.nix.
Specific flake output:
# .envrc
use flake .#devShelldevenv Integration
# .envrc
eval "$(devenv direnvrc)"
use devenvIntegrates with devenv.sh (see devenv skill for details).
asdf Integration
# .envrc
use asdfLoads tool versions from .tool-versions.
Specific tools:
# .envrc
use asdf nodejs 20.11.0
use asdf python 3.12.1mise (rtx) Integration
# .envrc
use miseLoads from .mise.toml or .tool-versions.
Conditional Logic
# .envrc
# OS-specific
if [[ "$OSTYPE" == "darwin"* ]]; then
export BROWSER="open"
else
export BROWSER="xdg-open"
fi
# Check file existence
if [ -f .env.local ]; then
dotenv .env.local
fi
# Check command availability
if has docker; then
export DOCKER_AVAILABLE=true
fiSource Other Files
# .envrc
source ./scripts/env-setup.sh
source_env ../shared/.envrc # Relative to current dir
source_env_if_exists .envrc.local # Won't fail if missingWatching Files (Auto-reload on Change)
# .envrc
watch_file config/settings.yaml
watch_file .env.production
# Reload .envrc when these files changeSecrets Management
# .envrc
# Load secrets from 1Password
export OP_SERVICE_ACCOUNT_TOKEN=$(cat ~/.op-token)
export API_KEY=$(op read "op://dev/api-key/password")
# Load from pass (password store)
export DB_PASSWORD=$(pass show myapp/db)
# Load from vault
export VAULT_TOKEN=$(vault print token)Rule: Never commit secrets to .envrc - load from secure stores or use .envrc.local (gitignored).
Working with Multiple Environments
# .envrc
ENV="${ENV:-development}"
case "$ENV" in
production)
source_env .envrc.production
;;
staging)
source_env .envrc.staging
;;
*)
source_env .envrc.development
;;
esacUsage: ENV=staging direnv allow
Project Root Detection
# .envrc
export PROJECT_ROOT="$PWD"
export SRC_ROOT="$PROJECT_ROOT/src"
export BUILD_DIR="$PROJECT_ROOT/build"Strict Mode
# .envrc
strict_env # Exit on errors in .envrc
set -euo pipefailLogging and Debugging
# .envrc
log_status "Loading project environment..."
log_error "Failed to load secrets"
# Debug mode
export DIRENV_LOG_FORMAT="$(date) - %s"stdlib Reference
direnv provides built-in functions in .envrc:
| Function | Purpose |
dotenv [path] | Load .env file (default: .env) |
PATH_add <dir> | Prepend directory to PATH |
path_add <var> <dir> | Prepend to any PATH-like variable |
load_prefix <prefix> | Load include/ lib/ from prefix |
layout <name> | Load predefined layout |
use <integration> | Load integration (nix, asdf, etc.) |
watch_file <path> | Reload .envrc when file changes |
source_env <path> | Source another .envrc |
source_env_if_exists <path> | Source if exists |
source_up [path] | Load parent directory .envrc |
has <cmd> | Check if command exists |
log_status <msg> | Print info message |
log_error <msg> | Print error message |
expand_path <path> | Convert to absolute path |
find_up <filename> | Search up directory tree |
direnv_layout_dir | Get layout dir path (.direnv/) |
user_rel_path <path> | Get path relative to $HOME |
strict_env | Enable strict error handling |
Security Model
Approval Required
direnv requires explicit approval before executing .envrc:
direnv allow # Approve current .envrc
direnv allow /path # Approve specific path
direnv deny # Revoke approvalAfter editing .envrc, you MUST re-approve with direnv allow.
What Gets Checked
- SHA256 hash of
.envrccontents - Stored in
~/.config/direnv/allow/ - Approval is per-directory + content hash
Allowed Paths
# ~/.config/direnv/direnv.toml
[whitelist]
prefix = [ "/home/user/projects" ]
exact = [ "/opt/project" ]Auto-approve paths matching these patterns.
Block List
# ~/.config/direnv/direnv.toml
[global]
hide_env_diff = true
disable_stdin = true
[whitelist]
prefix = [] # Block everything except explicit allowsConfiguration
Global config: ~/.config/direnv/direnv.toml
[global]
# Hide environment diff output
hide_env_diff = false
# Disable reading stdin (security)
disable_stdin = false
# Timeout for direnv execution
load_dotenv = true
# Warn if .envrc takes longer than X seconds
warn_timeout = "5s"
[whitelist]
# Auto-approve these paths
prefix = [ "/home/user/projects", "/opt/work" ]
exact = [ "/etc/myapp" ]Performance Optimization
Cache Layout Directories
# .envrc
layout_dir=$(direnv_layout_dir)
export VENV_DIR="$layout_dir/venv"
if [ ! -d "$VENV_DIR" ]; then
python -m venv "$VENV_DIR"
fiLayout dir: .direnv/ (gitignored, persistent across .envrc reloads)
Lazy Loading
# .envrc
# Don't run expensive operations on every load
if [ ! -f .direnv/initialized ]; then
log_status "First-time setup..."
pnpm install
touch .direnv/initialized
fiConditional Activation
# .envrc
# Skip activation in CI
if [ -n "$CI" ]; then
return
fi
# Skip in containers
if [ -f /.dockerenv ]; then
return
fiwatch_file for Cache Invalidation
# .envrc
layout_dir=$(direnv_layout_dir)
watch_file package.json
if [ ! -f "$layout_dir/.deps-installed" ] || \
[ package.json -nt "$layout_dir/.deps-installed" ]; then
pnpm install
touch "$layout_dir/.deps-installed"
fiReinstalls only when package.json changes.
Integration Examples
With Docker Compose
# .envrc
export COMPOSE_PROJECT_NAME="myapp"
export COMPOSE_FILE="docker-compose.yml:docker-compose.dev.yml"With Terraform
# .envrc
export TF_VAR_environment="dev"
export TF_DATA_DIR="$PWD/.terraform"
export AWS_PROFILE="dev-account"With Kubernetes
# .envrc
export KUBECONFIG="$PWD/kubeconfig.yaml"
export KUBECTL_CONTEXT="dev-cluster"With Make
# .envrc
export MAKEFLAGS="-j$(nproc)"
export BUILD_TYPE="debug"With Homebrew
# .envrc
if [[ "$OSTYPE" == "darwin"* ]] && has brew; then
eval "$(brew shellenv)"
PATH_add "$(brew --prefix)/opt/postgresql@15/bin"
fiMonorepo Patterns
Root .envrc
# /project/.envrc
export PROJECT_ROOT="$PWD"
export WORKSPACE="monorepo"
# Load global deps
PATH_add "$PROJECT_ROOT/bin"Service .envrc
# /project/services/api/.envrc
source_up # Load parent .envrc first
export SERVICE_NAME="api"
export SERVICE_PORT=3001
# Service-specific PATH
PATH_add "$PWD/scripts"
# Load service env
dotenv .env.apiWorkspace .envrc
# /project/.envrc
export WORKSPACE_ROOT="$PWD"
# Detect current service
if [[ "$PWD" == *"/services/"* ]]; then
SERVICE=$(basename "$PWD")
export SERVICE_NAME="$SERVICE"
fiTroubleshooting
Check direnv status
direnv statusShows:
- Current allowed paths
- Found .envrc files
- Whether environment is loaded
Debug mode
direnv exec . env | grep -v '^_' # Show exported vars
direnv export json # JSON outputForce reload
direnv reloadClear all approvals
rm -rf ~/.config/direnv/allow/Check hook installation
echo $DIRENV_DIR # Should be set when in project
type direnv # Should show function, not binaryIf direnv is a binary (not a shell function), the hook is not installed.
Performance profiling
time direnv exec . trueIf > 1 second, optimize your .envrc:
- Remove expensive commands
- Use layout directories for caching
- Add conditional checks to skip unnecessary work
Common Issues
| Problem | Solution |
| Changes not applied | Run direnv allow after editing .envrc |
| "Command not found" after cd | Check shell hook is installed |
| Slow activation | Profile with time direnv exec . true, optimize .envrc |
| Variables remain loaded | Check for conflicting shell configs setting same vars |
| .envrc not found | Ensure no typos, check direnv status |
| Permission denied | Check file permissions, run direnv allow |
Rules
- ALWAYS commit
.envrcto version control (but NOT.envrc.localif it contains secrets). - ALWAYS gitignore
.direnv/- it's a cache directory. - NEVER put secrets directly in
.envrc- load from secure stores or use.envrc.local. - ALWAYS run
direnv allowafter editing.envrc- it won't activate without approval. - ALWAYS test
.envrcchanges by cd-ing in/out of the directory. - Use
source_upin nested directories to inherit parent environment before extending. - Use
layoutcommands instead of manual PATH manipulation when available. - Use
watch_filefor cache invalidation based on file changes. - Use
.envrc.local(gitignored) for personal/secret overrides. - Profile slow
.envrcfiles withtime direnv exec . trueand optimize. - Document non-obvious .envrc logic with comments - future you will thank you.
- Use
hasto check command existence before using tools that might not be installed.
Quick Reference
# Approve .envrc
direnv allow
# Deny/revoke
direnv deny
# Force reload
direnv reload
# Check status
direnv status
# Edit safely (auto-reloads)
direnv edit [path]
# Show current environment diff
direnv export json
# Execute command in environment
direnv exec <path> <cmd>Resources
Inputs
- Project root directory with an existing or new
.envrcfile - Integration target (nix flake, devenv, asdf, mise, or plain env vars)
Outputs
- A
.envrcfile (and optionally a.envrc.localfor personal overrides) that automatically loads the project environment on directory entry
Examples
# .envrc — use a devenv environment
use devenv
# .envrc — load env vars and add local bin to PATH
dotenv .env
PATH_add binDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

