CodeSeshv1.5.3
Start locally

OpenCode session history: opencode.db, resume & viewer

Locate ~/.local/share/opencode/opencode.db, override paths with OPENCODE_DB, reopen threads via opencode -s, and search OpenCode sessions and costs locally with CodeSesh.

By CodeSeshUpdated

npx codesesh --agent opencode --days 0
Explore live preview
localhost:4521worker-cli
~/.local/share/opencode/opencode.dbSample UI
OpenCodeRead-only index
3.2M tokens$1.94
Migrate SQLite index to WAL batching
27 messages · 1 subagent · recorded cost
bashpnpm test storage18 passed
opencode -s ses_4a9f2c

OpenCode stores local session history in an SQLite database at ~/.local/share/opencode/opencode.db (or $XDG_DATA_HOME/opencode/opencode.db), overridable via OPENCODE_DB. To reopen a session in the terminal, run opencode -s <session-id>. To search prompts, tool output, file changes, and recorded costs across repositories in a local Web UI, run npx codesesh --agent opencode --days 0.

Where OpenCode stores its session database

By default, OpenCode writes sessions, messages, tool calls, reasoning steps, and cost metadata into one local SQLite file:

  • Default database path: ~/.local/share/opencode/opencode.db
  • XDG override: $XDG_DATA_HOME/opencode/opencode.db when XDG_DATA_HOME is set
  • Direct override: OPENCODE_DB (either an absolute path or a filename relative to the OpenCode data directory; :memory: databases are skipped)

CodeSesh supports OpenCode V1 (session) and V2 (session_v2 / session_message) database layouts, including databases mid-way through a V1-to-V2 migration.

Resume an OpenCode session from the terminal

When you already know which session you want to continue, OpenCode’s CLI accepts the session ID directly:

Terminal
opencode -s <session-id>

You can copy the exact opencode -s <session-id> command (with working directory context) from any OpenCode session detail page inside CodeSesh.

Browse and search OpenCode history with CodeSesh

Because OpenCode stores conversations inside SQLite, searching across repositories for an error trace, a shell command, or a file edit requires querying the database directly. CodeSesh opens opencode.db read-only and indexes every conversation into a fast local Web UI.

Scan all local OpenCode sessions:

Terminal
npx codesesh --agent opencode --days 0

Focus on the current repository:

Terminal
npx codesesh --agent opencode --days 0 --cwd .

In the Web UI at http://localhost:4521, you can:

  • Search messages and tool output: Filter across projects, smart tags, and touched file paths in one query.
  • Inspect nested subagent sessions: Keep child sessions grouped under their parent task with rolled-up token totals.
  • Review recorded costs and reasoning: OpenCode records token usage and costs directly, which CodeSesh displays alongside full reasoning and tool-call timelines.
  • Copy resume commands: Jump back into the terminal with opencode -s <session-id> whenever you find the right context.

Troubleshoot missing OpenCode sessions

  • Match OPENCODE_DB and XDG_DATA_HOME. Start CodeSesh from a shell that exports the same environment variables OpenCode uses.
  • Pass --days 0. Plain npx codesesh defaults to the last 7 local calendar days; use --days 0 or switch the UI window to All for older sessions.
  • Check in-memory mode. If OPENCODE_DB is set to :memory:, sessions are not persisted on disk and cannot be indexed.

See also the Claude Code session history guide, Codex session history guide, and token usage and costs guide.

Browse your local history in one Web UI

MIT open source and read-only on your machine. Search conversations, tool calls, file changes, and token costs with one command.

Explore live preview

Installation method

npx codesesh@latest

macOS / Linux / Windows · Node.js 22+

Frequently asked questions

Where does OpenCode store local session history?

OpenCode stores sessions, messages, tool calls, reasoning, and recorded costs in an SQLite database at ~/.local/share/opencode/opencode.db (or $XDG_DATA_HOME/opencode/opencode.db). Set OPENCODE_DB to point to a custom database file.

How do I resume a previous OpenCode session from the CLI?

Run opencode -s <session-id> in your terminal. CodeSesh lets you search past OpenCode conversations across repositories and copy the exact worktree-aware opencode -s command from the session detail view.

Does CodeSesh support both OpenCode V1 and V2 databases?

Yes. CodeSesh reads OpenCode V1 (session), V2 (session_v2 and session_message), and databases mid-way through V1-to-V2 migration in read-only mode.

Can CodeSesh show OpenCode token usage and recorded costs?

Yes. OpenCode records token totals and cost metadata in opencode.db, which CodeSesh surfaces by project, model, and date alongside full conversation replay.

Browse all guides