Skip to content

feat(session): add session.start lifecycle hook#18007

Open
arawak wants to merge 12 commits intoanomalyco:devfrom
arawak:sean/session-start-hook
Open

feat(session): add session.start lifecycle hook#18007
arawak wants to merge 12 commits intoanomalyco:devfrom
arawak:sean/session-start-hook

Conversation

@arawak
Copy link
Copy Markdown

@arawak arawak commented Mar 17, 2026

Issue for this PR

Closes #5409

Related to #12110, #17412

Type of change

  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a session.start plugin hook with startup, resume, and compact triggers.

My immediate use case was getting the context-mode plugin 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.ts
  • bun typecheck

I 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

arawak added 6 commits March 15, 2026 10:20
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.
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.

[FEATURE]: SessionStart hook for session lifecycle events

1 participant