VSCode extension: /clear does not fire SessionEnd hook
Summary
When running Claude Code inside the VSCode native extension, the /clear command does not trigger the SessionEnd hook. In the standalone CLI the same command correctly fires SessionEnd with reason: "clear" and then SessionStart with source: "clear".
This breaks any hook-based workflow that depends on transcript capture at /clear time (e.g. dumping transcripts for archival before the context is cleared).
Environment
- Claude Code:
2.1.114 - OS: Windows 11 Home (10.0.26200)
- Shell: bash (Git Bash)
- Hook registered in
~/.claude/settings.jsonunderSessionEnd(no matcher, so it should fire for anyreason).
Reproduction
- Configure a global
SessionEndhook in~/.claude/settings.jsonthat simply appends a line to a log file when it receives stdin. - Open Claude Code inside the VSCode native extension, send a prompt, wait for a reply.
- Run
/clear. - Check the hook log — no new line written. Also the next
SessionStartpayload carriessource: "startup"instead ofsource: "clear". - Repeat the same procedure in a plain terminal (
claudeCLI, not VSCode). The hook log now shows aSessionEndentry, and the nextSessionStartcarriessource: "clear".
Expected behavior
/clear should fire SessionEnd with reason: "clear" and subsequent SessionStart with source: "clear" in both the CLI and the VSCode extension — consistent with the documented hook lifecycle (https://docs.claude.com/en/docs/claude-code/hooks).
Actual behavior (VSCode extension only)
SessionEndhook is not invoked on/clear.SessionStartfires for the new session but reportssource: "startup"instead ofsource: "clear", making it impossible to distinguish a fresh launch from a/clear-induced restart.
Observed log diff
Same cwd, same \settings.json\, same hook script. Only the invocation surface differs.
VSCode extension (\/clear\ → new session, no SessionEnd):
\\\\
19:24:10 session-start: unassigned cwd=d:\...\Бодя сайт (sid=468c0b09, source=resume)
19:39:19 session-start: unassigned cwd=d:\...\Бодя сайт (sid=6e44c44d, source=startup)
\\
CLI (\/clear\ → SessionEnd fires, source=clear):
\\\\
19:45:36 session-start: unassigned cwd=D:\...\Бодя сайт (sid=982e74ee, source=startup)
19:46:07 sessionend: OK unassigned=Бодя сайт sid=982e74ee
19:46:07 session-start: unassigned cwd=D:\...\Бодя сайт (sid=3c268ce4, source=clear)
\\
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗