claude-code - 💡(How to fix) Fix Support envFile setting to load environment variables from a file [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48873Fetched 2026-04-16 06:48:37
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
labeled ×2commented ×1

Fix Action

Fix / Workaround

Workarounds Today

Code Example

{
  "envFile": ".envrc"
}

---

{
  "envFile": [".env", ".env.local"]
}
RAW_BUFFERClick to expand / collapse

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)

extent analysis

TL;DR

To address the issue of loading environment variables from a file into Claude Code sessions, consider adding an envFile setting to settings.json that accepts a path to env files.

Guidance

  • Evaluate the proposed solution of adding an envFile setting to settings.json to parse env files at session start and inject variables into the process environment.
  • For .envrc files with shell logic, consider using direnv export json to evaluate the file contents.
  • Review the related issue #28942 for potential insights on implementing envFile support.
  • Assess the trade-offs of the current workarounds, such as manually duplicating env vars or launching Claude Code from a terminal where direnv has loaded.

Example

{
  "envFile": ".envrc"
}

or

{
  "envFile": [".env", ".env.local"]
}

Notes

The implementation details of the proposed solution, such as handling multiple env files or evaluating shell logic, require further consideration.

Recommendation

Apply the proposed workaround of adding an envFile setting to settings.json, as it addresses the core issue of loading environment variables from a file into Claude Code sessions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING