[BUG] Environment Variables from SessionStart Hooks are not cleared on /clear
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?
I have a SessionStart Hook which sets a SESSION_ID environment variable so it can be used to create and find state files in .claude/planning/{$SESSION_ID}
After running /clear the SessionStart Hook is run again and correctly sets the new SESSION_ID in the passed CLAUDE_ENV_FILE but claude-code continues to use the SESSION_ID environment variable from the previous session
What Should Happen?
After running /clear the environment variables from the previous session should be gone.
Or at the very least the SESSION_ID from the newly run hook should replace the old one.
Error Messages/Logs
❯ please run `echo $SESSION_ID_PROJECT`
● Bash(echo $SESSION_ID_PROJECT)
⎿ 425df70f-01ea-4c34-bf27-800a41367a21
❯ /clear
⎿ (no content)
❯ please run `echo $SESSION_ID_PROJECT`
● Bash(echo $SESSION_ID_PROJECT)
⎿ 425df70f-01ea-4c34-bf27-800a41367a21
● The value is 425df70f-01ea-4c34-bf27-800a41367a21.
This appears to be from a previous session - the system-reminder shows the new session ID
should be 791755fa-b4c3-45dc-a4d8-a931403fb4ff. This confirms the /clear command isn't
properly clearing/resetting environment variables.
Steps to Reproduce
I created https://github.com/vonAffenfels/claude-code-clean-does-not-clear-env to show the behaviour.
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.76 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
IntelliJ IDEA terminal
Additional Information
_No response_
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗