feat: add SlashCommand hook event for local/built-in slash commands

Resolved 💬 3 comments Opened Feb 28, 2026 by thkt Closed Mar 4, 2026

Summary

Local slash commands (/help, /clear, /compact, /fork, etc.) are handled
entirely by the CLI layer and leave no trace in JSONL transcripts or hook events.
This makes them invisible to plugins and session-analytics tools that rely on the
hook ecosystem.

Current Behavior

| Event source | JSONL transcript | Hook fires |
| --- | --- | --- |
| AI tool call | yes | yes |
| /think slash cmd (isMeta user msg) | yes | no |
| /clear, /compact, /fork, /help | no | no |

Custom slash commands that resolve to isMeta user messages are detectable, but
built-in local commands are completely invisible to the extension layer.

Proposed Solution

Add a new hook event type — SlashCommand (or UserCommand) — that fires
whenever a slash command is executed, including built-in CLI-layer commands.

Hook input schema

{
  "hook_event_name": "SlashCommand",
  "command": "clear",
  "args": [],
  "timestamp": "2026-03-01T12:00:00.000Z"
}

Hook output (optional)

A non-zero exit code or {"decision": "block"} response could allow hooks to
intercept or cancel a command before execution, consistent with PreToolUse
semantics.

Use Case

Session analytics plugins that parse JSONL transcripts to track tool/skill usage
patterns and costs cannot detect local command invocations because they never
appear in the transcript. While commands like /commit and /audit are
detectable via isMeta user messages, local commands (/clear, /compact,
/fork) are entirely invisible.

A SlashCommand hook would allow:

  • Session-level analytics (e.g., how often /compact is used per project)
  • Audit trails for organizational compliance tooling
  • Extension authors to react to context-management events (e.g., log before /clear)

Current Workaround

None. Local commands are completely invisible to the plugin/hook ecosystem.

Alternatives Considered

  • JSONL-only approach: Emit a JSONL record on each local command without a

hook. Simpler, but loses the ability to intercept or block commands.

  • Expose via PostToolUse: Reuse an existing hook type with a synthetic

tool name (e.g., tool_name: "__slash_clear"). Avoids a new event type but
is semantically misleading.

Related

  • Hooks documentation
  • Existing hook types: PreToolUse, PostToolUse, Stop, Notification, SubagentStop

View original on GitHub ↗

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