TUI for managing, recovering, and relocating OpenCode sessions across renamed or moved project directories.
opencode-sm is an interactive terminal companion for OpenCode.
It addresses a long-standing pain point: renaming or moving a project folder makes
all its chat sessions disappear from the OpenCode UI, even though the conversation
history is still safe in the local SQLite database.
0.1.0-alpha.5 — pre-release. The feature set is functional but not yet production-stable. Expect breaking schema changes until 1.0.0.
OpenCode stores each session's working directory as an absolute path at creation
time and never updates it. After a folder rename, the UI filters out sessions whose
directory no longer resolves on disk, even though session.project_id is still
valid (it is derived from the git root commit hash, which is stable across renames).
opencode-sm bridges that gap and adds session management features OpenCode does
not yet ship.
- Browse all sessions in one place, split into Orphans and Active tabs
- Detail preview for any selected session: status, path, agent, timestamps
- Scrollable chat preview with markdown rendering (bold, italic, code, lists, headings, blockquotes) and scrollbar indicator
- Fixed "Chat Preview" header (doesn't scroll away)
- Toggle between orphans/active via tab, shift+tab, left/right arrows
- Live filter via list component
- OpenCode-inspired dark theme (Lipgloss)
- Press
ron any session to attempt automatic re-link via project_id - Auto re-link succeeds when the project's worktree is found in the database (derived from git root commit hash)
- On auto re-link failure, a colored result modal explains the cause and offers "try manual remap instead" as a one-key fallback
- Manual fallback (also bound to
m) lets you browse the filesystem via Bubble filepicker to pick the new directory yourself - Confirmation modal showing old/new path, strategy, and backup info
- Running OpenCode instance detection (Linux) with warning and optional SIGTERM kill before destructive writes
- Press
mon any session to open an intro modal explaining scope - Updates
session.directoryfor every session pointing to the source folder, in a single SQLite transaction with automatic backup - Target folder does not need to be registered in OpenCode
session.project_idis left unchanged
- Press
xon any session to open an intro modal explaining scope - Picks 5 most recent sessions from the source directory and moves them to a target folder that must be registered in OpenCode
- Updates both
session.directoryandsession.project_id
- SQLite layer: list/find/get/update sessions, projects, and messages
- Phase 1 matching algorithm (adapted from bbl21's Python implementation)
- Manual path remap with preview
- Auto-backup (
<dbpath>.opencode-sm-backup) before any write operation - Transactional writes and error-safe rollback
- Cross-platform install scripts (bash + PowerShell)
- Self-uninstall via
opencode-sm uninstallsubcommand - Shell completions for bash, zsh, fish, powershell
- GitHub Actions CI matrix across Ubuntu, macOS, Windows
go install github.com/Khip01/opencode-session-manager/cmd/opencode-sm@latestmake build
./bin/opencode-smopencode-sm # Launch TUI with default DB path
opencode-sm --db-path /path/to/db # Use a specific opencode.db
opencode-sm --version # Print version and exit
opencode-sm --help # Print helpopencode-sm uninstall --dry-run # Preview files to remove
opencode-sm uninstall --prefix ~/.local/bin # Custom prefix
opencode-sm uninstall --purge # Remove config and data too| Key | Mode | Action |
|---|---|---|
j/k, ↑/↓ |
List | Navigate sessions |
tab/→, shift+tab/← |
List | Switch tab |
r |
List | Re-link (auto via project_id, fallback to manual) |
m |
List | Move all sessions in folder (manual filepicker) |
x |
List | Migrate sessions (5 most recent to another project) |
q |
Any | Quit |
esc |
Modal | Cancel / go back |
enter |
Intro | Continue to next step (picker, confirm) |
enter |
Picker | Select the highlighted directory as the new path |
→/← or backspace |
Picker | Enter directory / go to parent |
→/← or backspace |
Picker | Enter directory / go to parent |
y, enter |
Confirm | Confirm destructive write |
n |
Confirm | Reject |
y, enter |
Result | Trigger fallback action (e.g. try manual remap) |
any other key |
Result | Dismiss |
cmd/opencode-sm/main.go — CLI entry, flags, version
internal/
db/ — SQLite queries + helpers
types.go — Session, Project, Message structs
session.go — ListSessions, GetSession, UpdateSessionDirectory
project.go — ListProjects, BuildWorktreeIndex
messages.go — ListMessages, MessagePart types
relinker/ — Core matching algorithm
relinker.go — Phase 1 (project_id match), ApplyAll
manual.go — Manual path remap, preview
backup.go — Backup before write
tui/ — Bubble Tea TUI
app.go — Root model, Init, View, Run
data.go — Session loader (orphan/active split)
keys.go — Keybindings
update.go — Update + modal dispatch
modal.go — Modal state machine
relink_modal.go — Relink flow (Phase 1 / Manual)
apply.go — Apply pending relink
filepicker_modal.go — Directory picker
confirm_modal.go — Yes/no + result dialogs
running_check.go — Linux process detection
process.go — SIGTERM kill
list_view.go — Bubbles list wrapper
detail_view.go — Metadata + chat preview rendering
markdown.go — Lightweight markdown renderer
scrollbar.go — Scrollbar for chat preview
styles.go — Lipgloss theme (OpenCode palette)
util.go — Helpers
The Phase 1 (project_id matching) and Phase 2 (path heuristic) algorithms are
adapted from bbl21/opencode-session-recovery
(MIT License). See NOTICE for full attribution.
The TUI is built with Bubble Tea, Bubbles, and Lipgloss from the Charm ecosystem.
The SQLite driver is modernc.org/sqlite, a pure-Go port of SQLite (no CGO required).
MIT. See LICENSE for the full text and NOTICE for third-party attributions.