feat(session): add session.start lifecycle hook#18007
Open
arawak wants to merge 12 commits intoanomalyco:devfrom
Open
feat(session): add session.start lifecycle hook#18007arawak wants to merge 12 commits intoanomalyco:devfrom
arawak wants to merge 12 commits intoanomalyco:devfrom
Conversation
Fire session.start for startup, resume, and compaction. Persist one-shot context for the next prompt and add local tests.
Regenerate the JS SDK after adding the session resume endpoint.
…an/session-start-hook
This was referenced Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #5409
Related to #12110, #17412
Type of change
What does this PR do?
Adds a
session.startplugin hook withstartup,resume, andcompacttriggers.My immediate use case was getting the
context-modeplugin working cleanly with OpenCode so it can restore one-shot session context automatically. Hook output is stored as pending session context and injected into the next LLM turn.This also wires resume through the server/CLI/TUI path and adds tests around the new behavior, including the fork startup timing edge case.
Known tradeoff: pending context is consumed lazily on the next LLM turn, so resume-triggered context can become stale if a session is resumed but not prompted soon after. I documented that in code rather than trying to redesign the semantics in this PR.
How did you verify your code works?
Ran locally in
packages/opencode:bun test test/server/session-resume.test.ts test/session/start.test.ts test/session/start-edge.test.ts test/session/llm.test.ts test/cli/run-session.test.ts test/cli/tui/session-resume.test.tsbun typecheckI also ran this branch manually for a couple of days with a plugin (context-mode) that uses the hooks before tightening the tests.
Screenshots / recordings
N/A
Checklist