[BUG] SessionStart hook doesn't receive CLAUDE_ENV_FILE when installed by a plugin
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?
The https://code.claude.com/docs/en/hooks#persisting-environment-variables explains that a CLAUDE_ENV_FILE should be available to SessionStart hooks. I can verify this works for project hooks or personal hooks, but this does not work for plugin hooks.
What Should Happen?
The plugin hook should be passed CLAUDE_ENV_FILE
Error Messages/Logs
Steps to Reproduce
Put a repro here: https://github.com/gabelevi/claude_session_start_env_bug (it's basically the test plugin from the docs)
It has two hooks:
- A local hook which does
echo $CLAUDE_ENV_FILE > /tmp/CLAUDE_ENV_FILE_project.txt - A plugin hook which does
echo $CLAUDE_ENV_FILE > /tmp/CLAUDE_ENV_FILE_plugin.txt
If I install the marketplace & plugin and restart claude, I can see that both /tmp/CLAUDE_ENV_FILE_plugin.txt and /tmp/CLAUDE_ENV_FILE_project.txt were created at the same time. But /tmp/CLAUDE_ENV_FILE_plugin.txt is always empty while /tmp/CLAUDE_ENV_FILE_project.txt contains the absolute path of my session's env file (e.g. /Users/username/.claude/session-env/c76b6e6b-25ce-453c-81e0-de5bc413ca2f/hook-0.sh)
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.36
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
3 Comments
Where is quality control? :-)
This is a really stupid bug - but agree its confirmed - all works with the env file but its NOT created when the hook is added as a plugin then the $CLAUDE_ENV_FILE is NOT populated
You can as a workarround take the session id from the json and construct the CLAUDE_ENV_FILE with $CLAUDE_HOME/session-env/CLAUDE_SESSION_ID/hook-0.sh and then do the exports into that file - then it will be called - that works and can confirm it - i had to do it like that - Claude just reads the hook-0.sh when it loads bash sessions after that file is created i also store CLAUDE_SESSION_ID so i can use it later
Im not sure what it breaks but i have no files in my whole session library other than hook-0.sh and ONLY files i created my self i presume each hook will have a unique file numbered so probably it should have a increment if it exists or just use a higher number but dont know how claude reads it :/
Thanks for the report & repro @gabelevi 😄 Fixed in next release.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.