anomalyco / anomalyco/opencode
[FEATURE]: Expose read-only persisted session history APIs to v2 plugins
@nexxeln is already working on this.
Since Aug 19, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Feature hasn't been suggested before.
- I searched existing issues first. #34957 and #35443 are related, but neither requests read-only enumeration of persisted sessions, children, and messages.
Describe the enhancement you want to request
Please expose the host's read-only persisted session APIs through the native v2 plugin context:
ctx.session.list({ project?, directory?, parentID?, cursor?, limit? })
ctx.session.children({ sessionID, cursor?, limit? })
ctx.session.messages({ sessionID, cursor?, limit? })
A plugin can currently inspect a known session, but after an OpenCode restart it cannot rediscover that session's persisted child tree or read the retained message usage records. Event tracking only works for children observed during the current process lifetime.
One concrete use case is a local usage report that totals a root session and all delegated descendants, grouped by agent and model, and also provides project-level history. Without these APIs, a plugin must either read OpenCode's SQLite database directly or spawn a CLI/API subprocess. Both couple plugins to implementation details outside the supported plugin boundary.
The host already exposes equivalent persisted session data through its session routes, and the dev branch has a useful stats CLI. This request complements those user-facing features: plugins need typed, structured access so they can build scoped tools and reports.
The host should enforce the same project, directory, and authorization boundaries as the existing session APIs, with bounded pagination. A minimal version could expose only list, children, and messages.
Tested against OpenCode 2 beta 17639 on macOS using the native @opencode-ai/plugin promise interface.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.