Support envFile setting to load environment variables from a file

Resolved 💬 3 comments Opened Apr 16, 2026 by baileywickham Closed May 27, 2026

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.json under env (gets stale)
  • Launch Claude Code from a terminal where direnv has loaded (doesn't work for desktop app)

Related

  • #28942 — envFile support in .mcp.json for MCP servers (same problem, different scope)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗