/clear does not fire SessionStart hook despite assigning a new session ID
Summary
/clear assigns a new session_id (confirmed via /status), but does not fire the SessionStart hook event. This means any SessionStart hooks that set up per-session state — environment variables via $CLAUDE_ENV_FILE, directories, logging — are never re-invoked after /clear.
Reproduction
- Configure a
SessionStarthook that logs to a file:
``json``
{
"hooks": {
"SessionStart": [{
"matcher": "",
"hooks": [{
"type": "command",
"command": "INPUT=$(cat); echo \"$(date +%H:%M:%S) session_id=$(echo $INPUT | jq -r .session_id)\" >> /tmp/hook-debug.log"
}]
}]
}
}
- Launch a session — hook fires, log entry appears
- Run
/status— note the session ID - Run
/clear - Run
/status— session ID has changed - Check
/tmp/hook-debug.log— no new entry after/clear
Expected behavior
/clear should fire SessionStart with the new session ID, since it creates a new session. This would allow hooks to:
- Update environment variables exported via
$CLAUDE_ENV_FILE - Create per-session state directories
- Reset session-scoped logging
Evidence
Tested systematically across 8 conditions (4 launch methods × 2 interaction states), 3 runs each (24 total executions). /clear never fires SessionStart in any case:
| Launch method | /clear (no interaction) | /clear (after interaction) |
|---|---|---|
| claude (fresh) | no hook fired | no hook fired |
| claude --resume | no hook fired | no hook fired |
| claude --continue | no hook fired | no hook fired |
| claude --resume --fork-session | no hook fired | no hook fired |
Impact
Any SessionStart hook that persists the session ID (e.g., via export VAR=... >> $CLAUDE_ENV_FILE) produces a stale value after /clear. The variable in subsequent Bash tool calls still holds the pre-clear session ID.
Environment
- Claude Code v2.1.52
- macOS Darwin 24.6.0
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗