AGENT SKILL

direnv

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.

适用职业开发工程师
License 许可
AGPL-3.0
所属仓库
aaronsb/agent-ways
最近更新
2026-11-14
Stars
★ 26
Forks
13

01 前言 Front Matter

name
direnv
description
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.
allowed-tools
Bash, Read, Write, Edit, Glob

03 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="anthropic.claude-opus-5"

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-5"     # pin a specific model snapshot; update as releases land
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: Claude Code env vars

The full, current list of Claude Code environment variables — providers, model, effort, token limits, config dir — lives in the canonical settings reference. Don't reproduce it here; it drifts:

https://code.claude.com/docs/en/settings.md

The examples above cover the common provider / model / flag cases.

Not for

  • Global, single-account setups — set the env vars normally; direnv earns its keep only when config differs per project.
  • Managing non-Claude-Code environment variables — that's plain direnv usage, not this skill.

04 同仓库更多 Skills

aaronsb
aaronsb/agent-ways

my-skill

A hand-built skill the user keeps in ~/.claude/skills. The fixture asserts it survives the install.

Skill与智能体开发
★ 26
aaronsb
aaronsb/agent-ways

work-skill

A skill in a second Claude Code config directory. The fixture asserts the directory is untouched.

Skill与智能体开发
★ 26
aaronsb
aaronsb/agent-ways

wrap

Wrap up a session at a natural seam — land in-flight work, square the TaskList honestly, write a copy-paste continuation prompt, then hand off to a directed /compact. Use when the user says "wrap up", "wrap this up", "let's wrap", "end of session", "checkpoint and compact", "hand off", or invokes /wrap.

Skill与智能体开发
★ 26
aaronsb
aaronsb/agent-ways

ways-update

Update the agent-ways installation to the latest version — preview the update with `ways manage update --what-if` (versions, release notes, the commits, local changes, the actions, dev links), read it back to the user, then apply it with `ways manage update --commit`, which pulls the app source in $XDG_DATA, refreshes the binaries and corpus, and reprojects ~/.claude. Use when the user wants to update agent-ways, pull the latest ways/hooks, or refresh their ways framework install. Not for editing or authoring individual ways (that is the ways skill) or upgrading project dependencies.

Skill与智能体开发
★ 26
aaronsb
aaronsb/agent-ways

ways-tests

Score way matching via embedding similarity, analyze vocabulary, and validate frontmatter. Use when testing how well a way matches prompts, checking cosine similarity scores, inspecting the embedding engine status, or validating way files.

★ 26
aaronsb
aaronsb/agent-ways

ways-localize

Localize agent-ways into the operator's language — translate every way's matching metadata against the English root, tune it clean, and switch ways (and Claude Code) into that language. Use when the operator asks to run ways in their language ("set up ways in Spanish", "localiza ways al español", "ways auf Deutsch"). Not for authoring or editing individual ways (that is the ways skill), not for English installs (already built), and not for changing Claude Code's language alone (that is a settings.json edit).

★ 26