[BUG] CLAUDE_ENV_FILE not sourced after /clear creates new session
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 /clear is executed, a new session is created and the SessionStart hook runs correctly, writing to the new $CLAUDE_ENV_FILE. However, subsequent Bash tool calls
do not have access to the environment variables from this file - they still use the environment from the original session startup.
The docs state: "Claude Code will source this file before each Bash command, making the environment persistent across all commands."
- Hook runs correctly (verified via debug logs)
- New env file is created at new path: ~/.claude/session-env/{new-session-id}/hook-0.sh
- But Bash tool calls still use environment from original session startup
- New env file is never sourced
What Should Happen?
After /clear, $CLAUDE_SESSION_ID should reflect the new session ID (e.g., bbb-222) since:
- SessionStart hook runs with source: "clear"
- Hook writes new session ID to the new $CLAUDE_ENV_FILE
- Docs say env file is sourced before each Bash command
Error Messages/Logs
Steps to Reproduce
- Create a SessionStart hook that captures the session ID:
```json
// hooks/hooks.json
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "echo \"export CLAUDE_SESSION_ID='$(echo | jq -Rr 'fromjson? | .session_id // empty' <<< \"$(cat)\")''\" >> \"$CLAUDE_ENV_FILE\""
}
]
}
]
}
}
2. Start a fresh Claude Code session
3. Run: echo $CLAUDE_SESSION_ID → outputs correct session ID (e.g., aaa-111)
4. Run /clear command
5. Run: echo $CLAUDE_SESSION_ID → still outputs old session ID aaa-111
### Claude Model
Opus
### Is this a regression?
I don't know
### Last Working Version
_No response_
### Claude Code Version
2.0.72
### Platform
Anthropic API
### Operating System
macOS
### Terminal/Shell
Other
### Additional Information
I am using latest version of Ghostty terminal. This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗