#23525: fix: include sessionKey in session_start/session_end hook context
size: XS
Cluster:
Gateway and Hooks Enhancements
## Problem
`PluginHookSessionContext` (used by `session_start` and `session_end` hooks) was missing `sessionKey`, while other hook context types like `PluginHookAgentContext` already included it. This made it impossible for plugins to call session-scoped APIs such as `enqueueSystemEvent` from session lifecycle hooks.
## Changes
- Add `sessionKey?: string` to `PluginHookSessionContext` type definition
- Pass `sessionKey` in both `runSessionStart` and `runSessionEnd` calls in `session.ts`
- Update `wired-hooks-session.test.ts` to verify `sessionKey` is forwarded
## Use Case
Plugins that need to inject system messages on session start (e.g., reminding the agent to read context files after `/new` or `/reset`) currently cannot do so because `enqueueSystemEvent` requires a `sessionKey` that the hook context doesn't provide.
## Testing
- `npx vitest run src/plugins/wired-hooks-session.test.ts` — 3/3 passed
- `npx vitest run src/auto-reply/reply/session.test.ts` — 34/34 passed
- `npx tsc --noEmit` — no new errors
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added `sessionKey` to `PluginHookSessionContext` to enable session-scoped API calls like `enqueueSystemEvent` from `session_start` and `session_end` hooks. This aligns session hook contexts with other hook contexts (`PluginHookAgentContext` and `PluginHookToolContext`) which already include `sessionKey`.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change is a straightforward addition of an optional field to a context type with corresponding implementation and test updates. The field aligns with existing patterns in other hook contexts, tests pass, and the use case is well-documented
- No files require special attention
<sub>Last reviewed commit: 2fd6979</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23763: Hooks: require session key prefixes for request override
by bmendonca3 · 2026-02-22
77.5%
#19177: fix: use parseAgentSessionKey instead of fragile split pattern
by El-Patronum · 2026-02-17
76.7%
#21682: fix(heartbeat): propagate sessionKey in exec/hooks to fix async con...
by eviaaaaa · 2026-02-20
76.4%
#7301: fix(hooks): use resolveAgentIdFromSessionKey instead of split(":")[0]
by tsukhani · 2026-02-02
75.5%
#19422: fix: pass session context to plugin tool hooks in toToolDefinitions
by namabile · 2026-02-17
75.1%
#19565: feat: add agent lifecycle hook events (session, message, error)
by tag-assistant · 2026-02-17
73.7%
#13032: feat(hooks): add unified session:before_end hook event
by TGambit65 · 2026-02-10
73.4%
#22283: Plugins: expose resolveMainSessionKey in runtime system
by MegaPhoenix92 · 2026-02-21
73.1%
#9782: feat(hooks): implement session:start and session:end lifecycle events
by kentaro · 2026-02-05
72.8%
#5525: Add plugin hook to resolve canonical RoomKey for session identity a...
by peteclt92 · 2026-01-31
72.7%