Feature request: reason-based filtering for SessionEnd hook matchers

Open 💬 0 comments Opened Jun 30, 2026 by yannick-opg

Currently, SessionEnd hooks fire on all session-end events including /clear and /compact. There's no way to opt out of specific reasons at the config level — the only workaround is to inspect the $REASON env var inside the hook script and exit early.

It would be useful to support reason-based filtering in the matcher field, e.g.:

"SessionEnd": [{
  "matcher": "reason!=clear",
  "hooks": [{ "type": "command", "command": "bash session-close.sh" }]
}]

This would allow hooks that do expensive work (git squash, push, Slack notification) to cleanly opt out of /clear and /compact firings without guard logic scattered across hook scripts.

Current workaround: check [[ "$REASON" == "clear" ]] at the top of the hook script and exit 0.

View original on GitHub ↗