← Back to PRs

#23525: fix: include sessionKey in session_start/session_end hook context

by p697 open 2026-02-22 11:32 View on GitHub →
size: XS
## 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