Skip to content

OpenCode

Use native session snapshots while keeping permissions, questions and branches explicit.

Read and render a session

Install @opencode-ai/sdk@1.19.5. Use the /v2 client entry with your authenticated OpenCode server. Keep its connection, selected directory/workspace and session owner in the application. Follow view setup.

opencode-session.tsx

This first integration is request/response: load the session, render it, then replace the records after sending. For streaming, subscribe through native client.event.subscribe in the application session owner and update its cache by native session/message/part IDs. Project that cache; do not start a second Ghost event reducer or refetch every child session for each token.

Native controls

opencode-controls.ts

Questions use their native question API; a permission decision is not a question answer or tool output. Application policy decides whether “always” is offered. Fork, revert and unrevert retain session semantics; they are not generic local transcript edits.

Extension and troubleshooting

The projection preserves tool call IDs, errors and native message metadata. Patch, subtask and future parts stay explicit unknown content until you provide a deliberate renderer. Read child sessions only when your product needs them; normalization performs no network reads.

If events from another workspace appear, fix native subscription/cache scope before normalizing. If the UI never streams, confirm you implemented the event owner rather than only the first request/response recipe. See OpenCode SDK documentation for event types and the external-store bridge for connecting an existing cache.