[BUG] HOME environment variable not set in hook process environment
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?
Hook processes spawned by Claude Code do not have HOME set in their environment (or inherit a wrong/empty value). Any hook that relies on ~ expansion or language-level home-directory resolution (e.g. Python's Path.home(), os.path.expanduser("~"), or shell ~) resolves to an incorrect path. Files written to paths derived from ~ land in the wrong directory with no error.
What Should Happen?
Hook processes should inherit HOME from the Claude Code process (or have it explicitly set), consistent with how other environment variables like PATH are handled.
Error Messages/Logs
Steps to Reproduce
- Add a
SessionEndhook that writes to a path derived from the home directory:
``sh``
"python3 -c \"from pathlib import Path; (Path.home() / 'hook-test.txt').write_text('ran')\""
- Trigger the hook (e.g. close a session).
- Check
~/hook-test.txt— the file does not exist. - Add
"HOME": "/Users/yourname"to theenvblock in~/.claude/settings.jsonand repeat — the file is now written correctly.
Workaround: explicitly set HOME in settings.json's env block:
"env": {
"HOME": "/Users/yourname"
}
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.211
Claude Code Version
2.1.215
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
I'm using Ghostty as my emulator, and zsh as my shell.