direnv
Skill18 starsChanged 10 months agoMITView on GitHub
Set up direnv/.envrc for per-project Claude Code environments — switch API keys, providers, models, and feature flags automatically when entering a directory. Use when the user wants to manage multiple Claude accounts, switch between Anthropic/Bedrock/Vertex per project, or configure per-directory environment variables.
- Reads credentials
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
- brpaz/agent-skillstheir own version, first seen May 17, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- Cogni-AI-OU/cogni-ai-agent-skills★ 4same name
- brpaz/agent-skills★ 1same 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 repository14 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adrSkill
- context-statusSkill
- governance-citeSkill
- project-pulseSkill
- shipSkill
- think-consistencySkill
- think-reactSkill
- thinkSkill
- think-stepbackSkill
- think-treeSkill
- think-trilemmaSkill
- ways-testsSkill
- wormholeSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 4 are distinctive, and 4 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.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Check that direnv is installed and hooked into the shell:
- Distinctive: line 20
Check the shell hook is active:
- Distinctive: line 26
If the hook is missing, add it:
- Very specific: line 32
Ask the user which scenario they need, then generate the .envrc:
- Very specific: line 82
After creating the .envrc:
- Very specific: line 85
Gitignore it: Verify .envrc is in .gitignore — it may contain secrets
- Distinctive: line 95
After setup, verify the environment loads:
- Very specific: line 125
No action needed — direnv automatically loads/unloads when you cd.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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 — Per-Project Claude Code Environments
Set up .envrc files so Claude Code automatically loads the right API keys, provider, model, and feature flags when you cd into a project directory.
Prerequisites
Check that direnv is installed and hooked into the shell:
which direnv && direnv version
# If missing: suggest installation for their platformCheck the shell hook is active:
grep -q 'direnv' ~/.zshrc ~/.bashrc 2>/dev/null && echo "hook found" || echo "hook missing"If the hook is missing, add it:
- zsh:
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc - bash:
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
Creating a .envrc
Ask the user which scenario they need, then generate the .envrc:
Direct API Key (personal/hobby)
# .envrc
export ANTHROPIC_API_KEY="sk-ant-..."AWS Bedrock
# .envrc
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_PROFILE=my-bedrock-profile
export AWS_REGION=us-east-1
# Optional: override model
# export ANTHROPIC_MODEL="us.anthropic.claude-sonnet-4-20250514-v1:0"Google Vertex AI
# .envrc
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=us-east5
export ANTHROPIC_VERTEX_PROJECT_ID=my-project-idMicrosoft Azure Foundry
# .envrc
export CLAUDE_CODE_USE_FOUNDRY=1
export ANTHROPIC_FOUNDRY_BASE_URL="https://my-resource.services.ai.azure.com/api"
export ANTHROPIC_FOUNDRY_API_KEY="..."Feature Flags / Tuning
# .envrc — append to any of the above
export ANTHROPIC_MODEL="claude-opus-4-6"
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000
export CLAUDE_CODE_EFFORT_LEVEL=high
export CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE=99Security Checklist
After creating the .envrc:
- Allow it:
direnv allow(required after every edit) - Gitignore it: Verify
.envrcis in.gitignore— it may contain secrets
grep -q '.envrc' .gitignore 2>/dev/null || echo '.envrc' >> .gitignore- Never commit API keys — if the project is shared, use
direnv allowlocally and keep.envrcout of version control.
Verifying
After setup, verify the environment loads:
cd /path/to/project
direnv allow
env | grep -E 'ANTHROPIC|CLAUDE_CODE|AWS_PROFILE|CLOUD_ML'Then start claude and confirm the right provider/model is active.
Common Patterns
Layered configs with .envrc.local
# .envrc (committed, non-secret defaults)
export CLAUDE_CODE_EFFORT_LEVEL=high
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000
# Source local overrides if present
source_env_if_exists .envrc.local# .envrc.local (gitignored, secrets)
export ANTHROPIC_API_KEY="sk-ant-..."Switching between projects
No action needed — direnv automatically loads/unloads when you cd. Just set up each project's .envrc once.
Reference: Key Claude Code Env Vars
| Variable | Purpose |
ANTHROPIC_API_KEY | Direct API authentication |
ANTHROPIC_MODEL | Model selection |
CLAUDE_CODE_USE_BEDROCK | Enable AWS Bedrock provider |
CLAUDE_CODE_USE_VERTEX | Enable Google Vertex provider |
CLAUDE_CODE_USE_FOUNDRY | Enable Azure Foundry provider |
CLAUDE_CODE_EFFORT_LEVEL | low / medium / high |
CLAUDE_CODE_MAX_OUTPUT_TOKENS | Max output tokens (up to 64000) |
CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE | Auto-compaction threshold (1-100) |
CLAUDE_CODE_SUBAGENT_MODEL | Model for subagents |
CLAUDE_CODE_SHELL | Override shell detection |
CLAUDE_CONFIG_DIR | Custom config directory |
Does 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.

