A CLI plugin for OpenCode V2 that adds a Session History panel to the sidebar. Click a previous session to resume it — in the same tab if it's already open, in a new tab otherwise.
- Sidebar panel that lists sessions across every project, newest-first (or
scoped to the current project with
showAllProjects: false). - Compact by default: three session rows are visible and the rest scroll
(
maxVisibleSessions). Long titles end in...instead of wrapping (truncateSessionTitles), so each row keeps a predictable height. Arrow navigation keeps the highlighted row in view. - Also shown on the home screen (before any session is open) as a right-hand panel, width permitting — the CLI's own sidebar only exists inside a session.
- Search filter by title, id, project, or directory. Click the field to focus
it (OpenCode does not focus plugin content automatically);
escapeclears the query, then blurs back to the prompt. - Click-to-resume:
- If the session is already open in a tab → focus that tab.
- Otherwise → open a new tab and focus it.
- When session tabs are disabled → falls back to
router.navigate({ type: "session" }).
- Sessions whose working directory is gone on the server are dimmed and prefixed
with a red
✗. Clicking one warns first (a short, dismissible toast that never navigates); clicking it again opens it anyway. This is distinct from a deleted session (the record itself), which never appears in the list. - Subscribes to session lifecycle events (
created,renamed,metadataandusageupdates,deleted) for live refresh.
Requires OpenCode V2.
opencode plugin add opencode-session-historyOr add it to opencode.jsonc (project or ~/.config/opencode/opencode.jsonc):
The CLI loads the sidebar panel automatically from the package's ./tui export — you do not need to add it to cli.json.
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["github:ypxcs/opencode-session-history"]
}This does not work on OpenCode 2.0.32. It fails before the plugin is downloaded, with
NpmInstallFailedError (cause: Error: git dep preparation failed).npm installs a Git package in two steps: download the repo, then prepare it by running the npm CLI as a child process (
process.execPath+npm-cli.js). OpenCode ships its own npm, so that child process is the OpenCode binary itself — it receives npm's arguments, prints its own help text, and exits non-zero. npm reports "git dep preparation failed" and nothing is installed. Revisions whose prepared tarball is already in~/.npm/_cacachestill install because the preparation step is skipped; anything new (including#mainafter a push) does not.Registry (npm) installs never run that path — they just download a tarball — which is why the npm install above is the supported route. If you need a specific commit, load it by path from a checkout instead (
"package": "/path/to/opencode-session-history/src", see below).
-
Copy this directory to
.opencode/plugins/session-history/in your project (V2 discoversindex.ts+tui.tsxpackage directories there automatically). -
Or reference it explicitly:
{ "plugins": [ { "package": "./src", "options": { "limit": 100, "maxVisibleSessions": 3, "truncateSessionTitles": true, "showMetrics": true, "showAllProjects": true } } ] }
| Option | Type | Default | Description |
|---|---|---|---|
limit |
number |
100 |
Maximum number of sessions included in the list. |
maxVisibleSessions |
number |
3 |
Sessions visible before the list scrolls. |
truncateSessionTitles |
boolean |
true |
Keep titles on one line with .... Set to false to word-wrap them. |
showMetrics |
boolean |
true |
Show the "Xm ago · $Y.YY" line under the title. |
showAllProjects |
boolean |
true |
When true, list sessions from every project. When false, only the current project's sessions are shown. |
With
truncateSessionTitles: true,maxVisibleSessionsmaps to a fixed row height. With wrapping enabled, a long title can make a row taller and reduce the number of fully visible sessions.
How options are delivered. OpenCode passes a plugin's config
optionsto its server half but not to its TUI half, which receives{}for a plugin declared inopencode.json(c). The TUI reads the values back over the plugin's ownsettingsRPC, so the table above works fromopencode.json(c). Wrong-typed values are ignored rather than coerced. If the options are also declared incli.jsonunderplugins, those take precedence in the TUI.
- OpenCode V2 (
@opencode/pluginv2.x). - For "open in new tab" behavior, enable session tabs:
When tabs are
// ~/.config/opencode/cli.json { "tabs": { "mode": "on" } }
auto/off, the click handler usesrouter.navigateinstead, which replaces the current session view.
OpenCode compiles plugin JSX through OpenTUI's own Bun plugin, but that plugin
only touches files whose path does not contain node_modules:
/^(?!.*[/\\]node_modules[/\\]).*\.[cm]?[jt]sx?(?:[?#].*)?$/Every package install — npm or Git — lands the plugin in node_modules, so a
raw .tsx TUI entry never gets that transform. Bun's own JSX transform then
compiles it against @opentui/solid/jsx-runtime, which is a static runtime:
props are plain values, not getters. Each signal read happens once, at mount, so
the panel lists only the session cached at mount (1 session), never refreshes,
and the slot it was appended to is laid out from the same stale snapshot. The
identical source loaded from a checkout path sits outside node_modules, gets
the real transform, and works — which is why the bug followed the install tree.
So bun run build precompiles src/** into dist/** with the transform
OpenCode would have applied (babel-preset-solid,
{ moduleName: "@opentui/solid", generate: "universal" }), and
package.json#exports points at dist/. The compiled entry imports
@opentui/solid and solid-js by bare name, which OpenCode rewrites to its own
runtime — the plugin shares the host's single Solid instance instead of
installing a second one.
dist/ is committed on purpose: package installs do not run a build step.
The TUI plugin asks the server, via the bundled session-history.check RPC, which session directories no longer exist. One batched call covers every distinct directory, and it runs on the server (node:fs), so it also works against a remote server and for sessions from every project. It fails open: only ENOENT/ENOTDIR count as missing, so protected paths (macOS EPERM) and transient errors never mark a live session.
Rows whose directory is gone are dimmed and prefixed with a red ✗. Activating one (click or Enter) warns first instead of opening: a 3-second, dismissible toast that never navigates. Activating the same row again within a few seconds opens it anyway — the CLI then handles the missing directory itself. The warning state resets on a timer and whenever the filter changes.
This is deliberately not called "deleted": a missing directory and a deleted session are different states. Deleted sessions are removed from the server and never reach the list.
Note: When the TUI is connected to a remote OpenCode server, "missing" reflects the server's filesystem, not your local machine.
bun install
bun run build
bun run typecheck
bun run tests/run.ts
bun run auditPackaging constraints — all asserted by
bun run tests/run.ts:
dist/must be committed and up to date. The test rebuildssrc/into a temp directory and compares it byte for byte, so runbun run buildafter touching anything insrc/. Package installs never run a build.- The build must not use
babel-plugin-module-resolver. The compiled entry has to import@opentui/solidandsolid-jsby bare name so OpenCode can redirect them to its own runtime; baked-inopentui:runtime-module:ids only resolve inside the host process.- Keep the
/** @jsxImportSource @opentui/solid */pragma at the top ofsrc/tui.tsx. That raw file is still loaded when the plugin is configured by path from a checkout, where notsconfig.jsonsits next to it; without the pragma Bun compiles JSX against thereactruntime (Cannot find package 'react').- Keep
@opentui/core,@opentui/solidandsolid-jsas non-optionalpeerDependencies. They must be installed alongside the package or loading fails withCannot find package '@opentui/solid'.
scripts/
└── build.ts # Compiles src/ → dist/ (babel-preset-solid, universal)
src/
├── rpc.ts # SessionHistory RPC contract (check + settings)
├── index.ts # Server plugin: registers the check + settings RPCs
├── directory.ts # Server-side directory existence check
├── options.ts # Pure config-option merge + defaults (unit-tested)
├── sessions.ts # Pure session list/filter helpers (unit-tested)
└── tui.tsx # CLI plugin: sidebar slot + filter + click + keymap
tests/
└── run.ts # RPC contract + option/session helper + packaging tests
dist/ # Committed build output; what package installs load
- Bugs and feature requests: https://github.com/ypxcs/opencode-session-history/issues
- Security issues: report privately, not in a public issue — see SECURITY.md.
MIT.
{ "$schema": "https://opencode.ai/config.json", "plugins": [ { "package": "opencode-session-history", "options": { "limit": 100, "maxVisibleSessions": 3, "truncateSessionTitles": true, "showMetrics": true, "showAllProjects": true } } ] }