VSCode: /clear sets SessionStart hook source to 'startup' instead of 'clear'

Resolved 💬 2 comments Opened Feb 19, 2026 by toyhammered Closed Mar 19, 2026

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 using /clear in the VSCode native UI extension, the SessionStart hook fires with "source":"startup" instead of "source":"clear". This means any hook group using "matcher": "clear" never matches.

The same matcher works correctly in the terminal CLI (confirmed by other issues like #26559 where users successfully use "matcher": "clear").

What Should Happen?

After /clear in the VSCode extension, the SessionStart hook payload should contain "source":"clear", matching the documented behavior and the terminal CLI behavior.

From the hooks documentation:

| Matcher | When it fires |
|---|---|
| startup | New session |
| resume | /resume, --resume, or --continue |
| clear | /clear |
| compact | Auto or manual compaction |

Steps to Reproduce

  1. Add a SessionStart hook config with both a no-matcher hook (to log the payload) and a "clear" matcher hook:
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash -c 'INPUT=$(cat); echo \"$(date -u) $INPUT\" >> /tmp/session-start-debug.log'"
          }
        ]
      },
      {
        "matcher": "clear",
        "hooks": [
          {
            "type": "command",
            "command": "echo 'clear matcher fired' >> /tmp/session-clear-debug.log"
          }
        ]
      }
    ]
  }
}
  1. Open Claude Code in VSCode (native UI, not terminal pane)
  2. Send a message to start a session
  3. Run /clear
  4. Check the debug logs

Actual Result

/tmp/session-start-debug.log shows a new entry with "source":"startup":

{"session_id":"e65b6c8b-...","source":"startup","hook_event_name":"SessionStart",...}

/tmp/session-clear-debug.log is never created — the "matcher": "clear" hook group never fires.

Expected Result

After /clear, the payload should have "source":"clear" and the matcher-based hook group should fire.

Root Cause Analysis

In the VSCode extension's webview code, the clear-conversation action calls createSession() with no arguments — identical to creating a brand new session:

registerAction({id:"clear-conversation", label:"Clear conversation"}, "Context", () => {
    $.createSession()  // no "clear" flag passed
})

The new session starts with sessionId = undefined, and when launchClaude is called, resume is undefined — same as a fresh startup. The CLI has no way to distinguish /clear from a new session, so it defaults to source: "startup".

Environment

  • Claude Code Version: 2.1.47
  • Platform: macOS (Darwin 24.6.0, arm64)
  • IDE: VSCode native UI extension
  • Architecture: The bug is in the webview → extension → CLI pipeline, not in the CLI itself

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗