[BUG] HOME environment variable not set in hook process environment

Status Open
Reported on v2.1.211
Maintainer reply None cached
Activity 0 comments · opened Jul 20, 2026

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

  1. Add a SessionEnd hook 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')\""
``

  1. Trigger the hook (e.g. close a session).
  2. Check ~/hook-test.txt — the file does not exist.
  3. Add "HOME": "/Users/yourname" to the env block in ~/.claude/settings.json and 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.

View original on GitHub ↗