direnv
Guide for using direnv - a shell extension for loading directory-specific environment variables. Use when setting up project environments, creating .envrc files, configuring per-project environment variables, integrating with Python/Node/Ruby/Go layouts, working with Nix flakes, or troubleshooting environment loading issues on macOS and Linux.
What this skill does
# direnv Skill
This skill provides comprehensive guidance for working with direnv, covering installation, configuration, stdlib functions, and best practices for per-project environment management.
## When to Use This Skill
Use this skill when:
- Installing and configuring direnv on macOS or Linux
- Creating or modifying `.envrc` files for projects
- Setting up per-project environment variables
- Configuring language-specific layouts (Python, Node.js, Ruby, Go, Perl)
- Integrating direnv with Nix or Nix Flakes
- Managing secrets and environment configuration for teams
- Troubleshooting environment loading issues
- Creating custom direnv extensions
## Core Concepts
### What is direnv?
direnv is a shell extension that loads and unloads environment variables based on the current directory. When you `cd` into a directory with a `.envrc` file, direnv automatically loads the environment. When you leave, it unloads the changes.
### Security Model
direnv uses an allowlist-based security approach:
- New or modified `.envrc` files must be explicitly allowed with `direnv allow`
- Prevents automatic execution of untrusted scripts
- Use `direnv deny` to revoke access
### How It Works
1. Shell hook intercepts directory changes
2. Checks for `.envrc` file in current or parent directories
3. If allowed, executes `.envrc` in a bash subshell
4. Captures exported variables and applies them to current shell
## Installation
### macOS (Homebrew - Recommended)
```bash
brew install direnv
```
### Linux
```bash
# Ubuntu/Debian
sudo apt install direnv
# Fedora
sudo dnf install direnv
# Arch
sudo pacman -S direnv
# Binary installer (any system)
curl -sfL https://direnv.net/install.sh | bash
```
### Verify Installation
```bash
direnv version
```
## Shell Configuration
Add the hook to your shell's config file. **This is required for direnv to function.**
### Zsh (~/.zshrc)
```bash
eval "$(direnv hook zsh)"
```
**With Oh My Zsh:**
```bash
plugins=(... direnv)
```
### Bash (~/.bashrc)
```bash
eval "$(direnv hook bash)"
```
**Important:** Place after rvm, git-prompt, and other prompt-modifying extensions.
### Fish (~/.config/fish/config.fish)
```fish
direnv hook fish | source
```
### After Configuration
Restart your shell:
```bash
exec $SHELL
```
## .envrc File Basics
### Creating an .envrc
```bash
# In your project directory
touch .envrc
# Edit with your preferred editor
vim .envrc
```
### Basic Syntax
```bash
# Export environment variables
export NODE_ENV=development
export API_URL=http://localhost:3000
export DATABASE_URL=postgres://localhost/myapp
# The export keyword is required for direnv to capture variables
```
### Allowing the .envrc
```bash
# Allow current directory
direnv allow
# Allow specific path
direnv allow /path/to/project
# Deny/revoke access
direnv deny
```
## Standard Library Functions
direnv includes a powerful stdlib. Always prefer stdlib functions over manual exports.
### PATH Management
```bash
# Prepend to PATH (safer than manual export)
PATH_add bin
PATH_add node_modules/.bin
PATH_add scripts
# Add to arbitrary path-like variable
path_add PYTHONPATH lib
path_add LD_LIBRARY_PATH /opt/lib
# Remove from PATH
PATH_rm "*/.git/bin"
```
### Environment File Loading
```bash
# Load .env file (current directory)
dotenv
# Load specific file
dotenv .env.local
# Load only if exists (no error)
dotenv_if_exists .env.local
dotenv_if_exists .env.${USER}
# Source another .envrc
source_env ../.envrc
source_env /path/to/.envrc
# Search upward and source parent .envrc
source_up
# Source if exists
source_env_if_exists .envrc.local
```
### Language Layouts
**Node.js:**
```bash
# Adds node_modules/.bin to PATH
layout node
```
**Python:**
```bash
# Creates virtualenv in .direnv/python-X.X/
layout python
# Use specific Python version
layout python python3.11
# Shortcut for Python 3
layout python3
# Use Pipenv (reads from Pipfile)
layout pipenv
```
**Ruby:**
```bash
# Sets GEM_HOME to project directory
layout ruby
```
**Go:**
```bash
# Modifies GOPATH and adds bin to PATH
layout go
```
**Perl:**
```bash
# Configures local::lib environment
layout perl
```
### Nix Integration
```bash
# Load nix-shell environment
use nix
# With specific file
use nix shell.nix
# Load from Nix flake
use flake
# Load specific flake
use flake "nixpkgs#hello"
use flake ".#devShell"
```
**For better Nix Flakes support, install nix-direnv:**
```bash
# Provides faster, cached use_flake implementation
# https://github.com/nix-community/nix-direnv
```
### Version Managers
```bash
# rbenv
use rbenv
# Node.js (with fuzzy version matching)
use node 18
use node 18.17.0
# Reads from .nvmrc if version not specified
use node
# Julia
use julia 1.9
```
### Validation
```bash
# Require environment variables (errors if missing)
env_vars_required API_KEY DATABASE_URL SECRET_KEY
# Enforce minimum direnv version
direnv_version 2.32.0
# Check git branch
if on_git_branch main; then
export DEPLOY_ENV=production
fi
if on_git_branch develop; then
export DEPLOY_ENV=staging
fi
```
### File Watching
```bash
# Reload when files change
watch_file package.json
watch_file requirements.txt
watch_file .tool-versions
watch_file config/*.yaml
# Watch entire directory
watch_dir config
watch_dir migrations
```
### Utility Functions
```bash
# Check if command exists
if has docker; then
export DOCKER_HOST=unix:///var/run/docker.sock
fi
# Expand relative path to absolute
expand_path ./bin
# Find file searching upward
find_up package.json
# Enable strict mode (exit on errors)
strict_env
# Load prefix (configures CPATH, LD_LIBRARY_PATH, etc.)
load_prefix /usr/local/custom
# Load remote script with integrity verification
source_url https://example.com/script.sh "sha256-HASH..."
```
## Best Practices
### Recommended .envrc Template
```bash
#!/usr/bin/env bash
# .envrc - Project environment configuration
# Enforce direnv version for team consistency
direnv_version 2.32.0
# Load .env if exists
dotenv_if_exists
# Load local overrides (not committed to git)
source_env_if_exists .envrc.local
# Language-specific layout
layout node # or: layout python3
# Add project bin directories
PATH_add bin
PATH_add scripts
# Development defaults
export NODE_ENV="${NODE_ENV:-development}"
export LOG_LEVEL="${LOG_LEVEL:-debug}"
# Watch for dependency changes
watch_file package.json
watch_file .nvmrc
```
### Git Configuration
**.gitignore:**
```gitignore
# Environment files with secrets
.env
.env.local
.envrc.local
# direnv virtualenv/cache
.direnv/
```
**Commit to repository:**
- `.envrc` (base configuration, no secrets)
- `.env.example` (template for team members)
### Secrets Management
**Never commit secrets.** Use environment variable fallbacks:
```bash
# .envrc (committed)
export DATABASE_URL="${DATABASE_URL:-postgres://localhost/dev}"
export API_KEY="${API_KEY:-}"
# Validate required secrets
env_vars_required API_KEY
# .envrc.local (gitignored)
export DATABASE_URL="postgres://user:secret@prod/app"
export API_KEY="actual-secret-key"
```
### Layered Configuration
```bash
# ~/projects/.envrc (global dev settings)
export EDITOR=vim
# ~/projects/api/.envrc
source_up
export API_PORT=3000
# ~/projects/api/feature/.envrc
source_up
export FEATURE_FLAG=true
```
### Project Structure
```
my-project/
├── .envrc # Base environment (committed)
├── .envrc.local # Local overrides (gitignored)
├── .env # Environment variables (gitignored)
├── .env.example # Template for team (committed)
└── .direnv/ # direnv cache (gitignored)
```
## Custom Extensions
Create `~/.config/direnv/direnvrc` for custom functions:
```bash
#!/usr/bin/env bash
# ~/.config/direnv/direnvrc
# Custom function: Use specific Kubernetes context
use_kubernetes() {
local context="${1:-default}"
export KUBECONFIG="${HOME}/.kube/config"
kubectl config use-context "$context" >/dev/null 2>&1
log_status "kubernetes context: $context"
}
# Custom functioRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.