pnpm test storage18 passedopencode -s ses_4a9f2cOpenCode 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.dbwhenXDG_DATA_HOMEis 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:
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:
npx codesesh --agent opencode --days 0Focus on the current repository:
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_DBandXDG_DATA_HOME. Start CodeSesh from a shell that exports the same environment variables OpenCode uses. - Pass
--days 0. Plainnpx codeseshdefaults to the last 7 local calendar days; use--days 0or switch the UI window to All for older sessions. - Check in-memory mode. If
OPENCODE_DBis 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.
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.
Related guides
- Start locally
Install CodeSesh and browse AI coding sessions
Read - Start locally
How to find AI coding session history locally
Read