claude-code - 💡(How to fix) Fix VSCode extension: /clear does not fire SessionEnd hook [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#50808Fetched 2026-04-20 12:12:29
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

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).

Root Cause

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).

RAW_BUFFERClick to expand / collapse

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.json under SessionEnd (no matcher, so it should fire for any reason).

Reproduction

  1. Configure a global SessionEnd hook in ~/.claude/settings.json that simply appends a line to a log file when it receives stdin.
  2. Open Claude Code inside the VSCode native extension, send a prompt, wait for a reply.
  3. Run /clear.
  4. Check the hook log — no new line written. Also the next SessionStart payload carries source: "startup" instead of source: "clear".
  5. Repeat the same procedure in a plain terminal (claude CLI, not VSCode). The hook log now shows a SessionEnd entry, and the next SessionStart carries source: "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)

  • SessionEnd hook is not invoked on /clear.
  • SessionStart fires for the new session but reports source: "startup" instead of source: "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) ```

extent analysis

TL;DR

The /clear command in the VSCode native extension of Claude Code does not trigger the SessionEnd hook, unlike in the standalone CLI, suggesting a potential issue with how the extension handles session clearance.

Guidance

  • Verify that the SessionEnd hook is correctly registered in ~/.claude/settings.json and that it works as expected in the CLI version of Claude Code.
  • Check the documentation for any specific requirements or limitations for hooks within the VSCode extension that might differ from the CLI.
  • Compare the environment and configuration between the VSCode extension and the CLI to identify any discrepancies that could cause the difference in behavior.
  • Consider filing a bug report with the developers of the VSCode extension for Claude Code, as the behavior seems inconsistent with the documented hook lifecycle.

Example

No specific code example is provided due to the nature of the issue, which seems to be related to the integration of Claude Code with the VSCode extension rather than a code snippet.

Notes

The issue seems specific to the interaction between Claude Code and the VSCode native extension. The fact that the CLI version behaves as expected suggests that the problem might be isolated to how the extension handles the /clear command or how it integrates with the hook system.

Recommendation

Apply a workaround by using the CLI version of Claude Code for tasks that depend on the SessionEnd hook being triggered by the /clear command, until the issue with the VSCode extension is resolved.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

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).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING