agentleFS
aaronsbaaronsb/claude-code-config/skills/direnv/SKILL.md

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

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
  1. Distinctive:

    Check that direnv is installed and hooked into the shell:

    line 13
  2. Distinctive:

    Check the shell hook is active:

    line 20
  3. Distinctive:

    If the hook is missing, add it:

    line 26
  4. Very specific:

    Ask the user which scenario they need, then generate the .envrc:

    line 32
  5. Very specific:

    After creating the .envrc:

    line 82
  6. Very specific:

    Gitignore it: Verify .envrc is in .gitignore — it may contain secrets

    line 85
  7. Distinctive:

    After setup, verify the environment loads:

    line 95
  8. Very specific:

    No action needed — direnv automatically loads/unloads when you cd.

    line 125

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 platform

Check 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-id

Microsoft 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=99

Security Checklist

After creating the .envrc:

  1. Allow it: direnv allow (required after every edit)
  2. Gitignore it: Verify .envrc is in .gitignore — it may contain secrets
grep -q '.envrc' .gitignore 2>/dev/null || echo '.envrc' >> .gitignore
  1. Never commit API keys — if the project is shared, use direnv allow locally and keep .envrc out 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

VariablePurpose
ANTHROPIC_API_KEYDirect API authentication
ANTHROPIC_MODELModel selection
CLAUDE_CODE_USE_BEDROCKEnable AWS Bedrock provider
CLAUDE_CODE_USE_VERTEXEnable Google Vertex provider
CLAUDE_CODE_USE_FOUNDRYEnable Azure Foundry provider
CLAUDE_CODE_EFFORT_LEVELlow / medium / high
CLAUDE_CODE_MAX_OUTPUT_TOKENSMax output tokens (up to 64000)
CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDEAuto-compaction threshold (1-100)
CLAUDE_CODE_SUBAGENT_MODELModel for subagents
CLAUDE_CODE_SHELLOverride shell detection
CLAUDE_CONFIG_DIRCustom config directory

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.