Support envFile setting to load environment variables from a file
Problem
There's no way to load environment variables from a file (like .envrc or .env) into Claude Code sessions via settings. The only option is the inline env key in settings.json, which requires manually duplicating every variable and keeping it in sync when the source file changes.
This is especially painful for users of direnv / .envrc who rely on automatic environment loading in their shell. The Claude Code desktop app doesn't inherit shell environment, so direnv never runs.
Proposed Solution
Add an envFile setting to settings.json that accepts a path (or array of paths) to env files:
{
"envFile": ".envrc"
}
Or with multiple files:
{
"envFile": [".env", ".env.local"]
}
Claude Code would parse the file(s) at session start and inject the variables into the process environment, similar to how VS Code handles envFile in launch.json.
For .envrc files that contain shell logic beyond simple export KEY=VALUE, an option to evaluate via direnv export json would be ideal.
Workarounds Today
- Manually duplicate all env vars into
settings.local.jsonunderenv(gets stale) - Launch Claude Code from a terminal where
direnvhas loaded (doesn't work for desktop app)
Related
- #28942 —
envFilesupport in.mcp.jsonfor MCP servers (same problem, different scope)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗