Skip to content

OpenCode Integration

Séance integrates with OpenCode through a TypeScript plugin that auto-installs to ~/.config/opencode/plugins/.

How It Works

  1. Plugin auto-installs on Séance startup (if ~/.config/opencode exists)
  2. Plugin hooks into OpenCode's event system, forwarding lifecycle events to Séance
  3. Wrapper script intercepts opencode launches, tracks PID, and fires session-end on exit

Events Handled

OpenCode EventSéance HookWhat It Shows
session.createdsession-startRunning
session.status (busy)prompt-submitRunning
tool.execute.beforepre-tool-useRunning
tool.execute.afterpost-tool-useRunning
permission.askednotificationNeeds input
session.idlestopIdle
session.errorsession-end(cleared)
session.updatedsession-startRunning

Features

  • Per-surface status — each terminal pane tracks its own agent status independently
  • Permission detection — shows "Waiting for permission" when OpenCode asks to run a command
  • Desktop notifications — notifies on completion and permission requests
  • Session directory tracking — OpenCode exposes session directory via SEANCE_OPENCODE_SESSION_DIR environment variable

Configuration

Toggle integration on or off in config.toml:

toml
opencode-hooks = true

Limitations

  • No subagent tracking — OpenCode doesn't emit subagent lifecycle events (unlike MiMo Code)
  • No session directory — session is managed through plugin in-memory state

For Contributors

Integration Approach

OpenCode uses a TypeScript plugin (plugins/seance-opencode/index.ts) auto-installed to ~/.config/opencode/plugins/. A wrapper script (resources/bin/opencode) intercepts launches for PID tracking and session-end on exit.

The plugin exports a SeancePlugin async function receiving $ (shell executor). It subscribes to OpenCode's event system and sends hooks via seance ctl opencode-hook <event> subprocess with JSON payload piped via stdin.

Version: @seance-version 13

Event Mapping

OpenCode EventSeance HookUI Status
session.createdsession-startRunning
session.status (busy)prompt-submitRunning
session.idlestopIdle
session.errorsession-end(cleared)
session.updatedsession-startRunning
tool.execute.beforepre-tool-useRunning
tool.execute.afterpost-tool-useRunning
permission.askednotificationNeeds input
permission.replied(no-op)

Unhandled events: session.deleted, session.compacted, session.diff, all message events, all file events, all LSP events, command.executed, shell.env, todo.updated.

Key Implementation Details

  • Status mode: Per-surface. Status key prefix opencode, mode surface. Each pane tracks independently.
  • clear_status_on_end is true.
  • has_notification_hook is true.
  • Auto-install target: ~/.config/opencode/plugins/seance-opencode.ts
  • Early exit conditions: Plugin returns empty object if SEANCE_SOCKET_PATH not set or SEANCE_OPENCODE_HOOKS_DISABLED=1.
  • Binary discovery: Derives seanceBin from SEANCE_BIN_DIR env var, falling back to "seance".
  • State variables: currentSessionId, sessionIdle, permissionPending, childSessions (Set), completedSessions (Set), subagentCount.
  • Subagent detection via session ID mismatch: When session.created or session.updated fires with a session ID different from currentSessionId, it's tracked as a child session. Uses completedSessions set to avoid re-tracking completed sessions.

Upstream Framework Events

Source: opencode.ai/docs/plugins

OpenCode's full event system includes:

EventDescriptionSéance Handles?
session.createdNew session createdYes
session.updatedSession state changedYes
session.idleSession became idleYes
session.errorSession error occurredYes
session.statusSession status changed (busy/idle)Yes
session.deletedSession was deletedNo
session.compactedSession context was compactedNo
session.diffSession diff availableNo
message.updatedMessage content updatedNo
message.removedMessage removedNo
message.part.updatedMessage part updatedNo
message.part.removedMessage part removedNo
tool.execute.beforeBefore tool executionYes
tool.execute.afterAfter tool executionYes
permission.askedPermission requestYes
permission.repliedPermission responseYes
file.editedFile was editedNo
file.watcher.updatedFile changed on diskNo
lsp.updatedLSP connection state changedNo
lsp.client.diagnosticsLSP diagnostics receivedNo
command.executedSlash command executedNo
shell.envShell environment injectionNo
todo.updatedTodo list changedNo
server.connectedServer connection establishedNo
installation.updatedInstallation state changedNo

Missing Event Coverage

Events that OpenCode can emit but Séance does not currently handle:

EventPotential Use for Séance
session.deletedClear status when session is explicitly deleted
session.compactedShow compaction indicator in status
message.updatedTrack conversation progress
file.editedShow file modification activity
lsp.client.diagnosticsShow error/warning counts in status
todo.updatedTrack task completion progress

Impact: Séance currently only tracks session lifecycle and tool execution. It misses file changes, LSP diagnostics, and task progress that could provide richer status information.

MIT Licensed