[BUG] CLAUDE_ENV_FILE with ~ expansion fails when $HOME is /root
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When using CLAUDE_ENV_FILE in \~/.claude/settings.json, the tilde (~)
character is not expanded to the actual $HOME path. This causes the
env file to not be found when $HOME is /root (common in containers).
Actual: File not found, variables not loaded
Workaround: Use absolute path like "/root/.claude_gogs_env.sh"
Environment:
Container with $HOME=/root
Claude Code 2.1.22
Linux 6.8.0-90-generic #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 x86_64 GNU/Linux
What Should Happen?
Expected: ~ should expand to $HOME
env settings should be available in Claude Code
Error Messages/Logs
Steps to Reproduce
- Create \~/.claude_gogs_env.sh with environment variables
- Set in \~/.claude/settings.json: "CLAUDE_ENV_FILE": "\~/.claude_gogs_env.sh"
- Start Claude Code
- Run: env | grep GOGS
- Variables are not present
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.22
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Xterm
Additional Information
There are a lot of reports of settings.json not being found. This may be part of other issues especially in LXC/LXD/Container environment as many tend to run as root.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗