Skip to content

feat(plugin): add session.start hook for session initialization#15224

Open
coalminer1776 wants to merge 3 commits intoanomalyco:devfrom
coalminer1776:dev
Open

feat(plugin): add session.start hook for session initialization#15224
coalminer1776 wants to merge 3 commits intoanomalyco:devfrom
coalminer1776:dev

Conversation

@coalminer1776
Copy link

@coalminer1776 coalminer1776 commented Feb 26, 2026

Issue for this PR

Feature request for session.start hook - addresses similar functionality to Claude Code's SessionStart hook for session initialization.

Type of change

  • New feature

What does this PR do?

Adds a new plugin hook session.start that fires when the first message is sent in a session. This allows plugins to inject custom context into the system prompt at session start.

Changes made:

  1. Added session.start hook type definition in packages/plugin/src/index.ts
  2. Added trigger logic in packages/opencode/src/session/prompt.ts that:
    • Detects first message in a session
    • Triggers prompt is built
    • Injects the hook before system plugin-returned context into the system prompt

Why it works:
The implementation follows the same pattern as existing hooks like experimental.chat.system.transform and other session hooks in the codebase. Plugins can now register a session.start hook that receives session info and returns context strings which are prepended to the system prompt.

How did you verify your code works?

  • TypeScript compilation passes (bun run typecheck)
  • Build succeeds (bun run build)
  • Code follows existing hook patterns in the codebase
  • Manual testing required to fully verify hook fires correctly at runtime

Screenshots / recordings

N/A - no UI changes

Checklist

  • I have tested my changes locally (typecheck, build)
  • I have not included unrelated changes in this PR

coalminer1776 added 3 commits February 26, 2026 09:35
- Add session.start hook type to plugin system
- Trigger hook on first message in session
- Allows plugins to inject context into system prompt
- Plugin demonstrates session.start hook functionality
- Logs when hook fires
- Injects test context into system prompt
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Feb 26, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant