Session formats
OpenCode sessions missing? They moved to session_v2
OpenCode 2.x writes new sessions to session_v2, not session. How to check your own database, and what a reader of the old tables misses.
Kifah Abbad Published Last verified 7 min read
The short answer. OpenCode 2.x writes new sessions to the tables session_v2 and session_message, not to the old session, message and part. A tool that reads only the old tables stops seeing anything new. Check which table has recent rows before you trust a reader.

Why this matters. If a tool that reads your OpenCode sessions (an export script, a viewer, a backup) stopped showing anything new, you can lose track of weeks of work without noticing, because the tool still runs and reports no error. This post shows the one check that tells you whether your reader is looking at the right tables.
What you get. A few read-only queries you can run on your own database in a minute, a rule for which tables to read, and what a reader of the old tables misses. You need this when something that worked on OpenCode 1.x seems to have gone quiet on 2.x.
If a tool that reads OpenCode sessions stopped showing anything new after early October 2026, it is probably reading the old tables. In my database, OpenCode 2.x writes new sessions to session_v2 and session_message, and the old session, message and part tables have not been written to since 5 October.
This post shows how to check that on your own machine with a few read-only queries, what a reader of the old tables misses, and what I could not explain. Everything below was run on a copy of my own database on 19 November 2026, against OpenCode 2.3.0 and SQLite 3.50.6. It is one person’s database, so treat the numbers as an example, not a statistic.
Who needs this
Possible scenario. Your team has a small script that lists last week’s agent sessions for a weekly review. After an OpenCode update it keeps running and keeps saying there is nothing new. Nobody notices for a month, because the output is empty rather than wrong.
It is not only a possible scenario. A colleague of mine upgraded to OpenCode 2.x and complained that he had lost some of his older sessions (reported to me; I have not seen his database or his tools, so I do not know whether the sessions are gone or only no longer shown). I asked the same question of my own database on 20 November 2026: all 1,179 sessions in the old session table still have a row in session_v2 (tested, one machine). What I could not match is 152 older messages, described below. So in my data the old sessions survived, and what a reader of the old tables would miss is the new ones.
| Role | What changes for them |
|---|---|
| Junior software engineer | Understands why a tool that worked suddenly shows nothing, and checks the version before assuming a bug of their own. |
| Architect | Treats a tool’s on-disk format as an interface that can change, and wraps it in one place. |
| DevOps or platform engineer | Monitors that a reader still returns recent rows after an upgrade of the tool. |
Table: who gains what, my reasoning, not measured. I did not measure time saved for any role.
The short version
The rule our collector uses is one question about the tables, not a version number:
session_v2.The rest of the post is how to check that on your own machine, and where it stops being true.
Look at a copy, not the file
OpenCode keeps its data in one SQLite file, ~/.local/share/opencode/opencode.db, in write-ahead-log mode, so there are two companion files next to it. The OpenCode troubleshooting guide says the same: make a backup before inspecting the database with other tools. OPENCODE_DB can move the file; if you set it, use that path.
mkdir -p ~/oc-copy && cp ~/.local/share/opencode/opencode.db* ~/oc-copy/
sqlite3 -readonly -header -column ~/oc-copy/opencode.db
The first command copies the database and its -wal and -shm files. Copying while OpenCode is running can catch the files at slightly different moments, so check the copy once with PRAGMA integrity_check; (it should print ok). Mine did.
Which tables do you have?
Paste each query into the sqlite3 prompt that the second command opened.
SELECT name
FROM sqlite_master
WHERE type = 'table'
AND name IN ('session', 'message', 'session_v2', 'session_message')
ORDER BY name;
Mine has all four. I have not checked a fresh 2.x install, so I cannot say whether a new user would see the old two:
name
---------------
message
session
session_message
session_v2
When did each layout stop or start?
SELECT 'message (old)' AS tbl,
datetime(max(time_created)/1000, 'unixepoch') AS last_row,
count(*) AS rows
FROM message
UNION ALL
SELECT 'session_message (v2)',
datetime(max(time_created)/1000, 'unixepoch'),
count(*)
FROM session_message;
The old tables have not been written since 5 October. The new ones are written today:
tbl last_row rows
-------------------- ------------------- -----
message (old) 2026-10-05 22:36:54 39757
session_message (v2) 2026-11-19 07:34:59 43764
The newest row in each layout, and how many rows each holds.
Sessions that exist only in the new tables
SELECT count(*) AS only_in_v2,
datetime(min(time_created)/1000, 'unixepoch') AS first_created,
datetime(max(time_created)/1000, 'unixepoch') AS last_created
FROM session_v2
WHERE id NOT IN (SELECT id FROM session);
Thirty-three sessions, all created from 6 October on, have no row in session at all:
only_in_v2 first_created last_created
---------- ------------------- -------------------
33 2026-10-06 12:02:27 2026-11-18 09:08:48
They come from three OpenCode versions. The first one the database shows creating a session only in the new tables is 2.0.20:
SELECT version,
count(*) AS sessions,
date(min(time_created)/1000, 'unixepoch') AS first_created
FROM session_v2
WHERE id NOT IN (SELECT id FROM session)
GROUP BY version
ORDER BY min(time_created);
version sessions first_created
------- -------- -------------
2.0.20 12 2026-10-06
2.2.5 18 2026-11-07
2.3.0 3 2026-11-17
Sessions that exist only in session_v2, by the OpenCode version that created them.
What a reader of the old tables misses
SELECT
(SELECT count(*) FROM session_message
WHERE session_id NOT IN (SELECT id FROM session))
AS rows_in_new_sessions,
(SELECT count(*) FROM session_message
WHERE session_id IN (SELECT id FROM session)
AND time_created > (SELECT max(time_created) FROM message))
AS later_rows_in_old_sessions,
(SELECT count(DISTINCT session_id) FROM session_message
WHERE session_id IN (SELECT id FROM session)
AND time_created > (SELECT max(time_created) FROM message))
AS old_sessions_continued;
A reader that only looks at session and message would not see 33 sessions and 2,901 rows in them, and it would also lose 118 later rows in three older sessions that were continued after the switch:
rows_in_new_sessions later_rows_in_old_sessions old_sessions_continued
-------------------- -------------------------- ----------------------
2901 118 3
It is not a straight copy
You might hope session_message is the old message table under a new name. It is close, and not identical. Matching rows by id, the old user role is spread over three types in the new table:
SELECT json_extract(m.data, '$.role') AS old_role,
s.type AS v2_type,
count(*) AS n
FROM message m
JOIN session_message s ON s.id = m.id
GROUP BY 1, 2
ORDER BY n DESC;
old_role v2_type n
--------- ---------- -----
assistant assistant 34779
user user 4419
user synthetic 328
user compaction 79
How the roles in the old message table map to types in session_message, matched by message id.
So 328 old “user” messages are now synthetic and 79 are compaction. If you count “my messages” by the old user role, the new table gives you a different number. I did not find OpenCode’s own definition of synthetic. What I can say is what the rows in my database look like: they begin with things such as “Called the Read tool” or a bracketed directive, which reads like text that was injected into the conversation rather than typed by a person. Check yours before you rely on that.
Where I could not explain a gap
SELECT count(*) AS old_messages,
sum(id IN (SELECT id FROM session_message)) AS found_in_v2,
sum(id NOT IN (SELECT id FROM session_message)) AS not_in_v2
FROM message;
Of 39,757 old messages, 152 (0.38 %) have no row with the same id in the new table:
old_messages found_in_v2 not_in_v2
------------ ----------- ---------
39757 39605 152
I checked a few explanations and did not settle on one. This splits the 152 by where they sit:
WITH miss AS (
SELECT id, session_id, time_created
FROM message
WHERE id NOT IN (SELECT id FROM session_message)
),
comp AS (
SELECT session_id, min(time_created) AS first_compaction
FROM session_message
WHERE type = 'compaction'
GROUP BY 1
)
SELECT count(*) AS not_in_v2,
sum(miss.session_id NOT IN (SELECT id FROM session))
AS in_sessions_with_no_session_row,
count(DISTINCT CASE WHEN miss.session_id NOT IN (SELECT id FROM session)
THEN miss.session_id END) AS of_those_sessions,
sum(miss.session_id IN (SELECT id FROM session)
AND miss.time_created >= comp.first_compaction) AS after_a_compaction,
sum(miss.session_id IN (SELECT id FROM session)
AND comp.session_id IS NULL) AS in_sessions_never_compacted
FROM miss
LEFT JOIN comp ON comp.session_id = miss.session_id;
not_in_v2 in_sessions_with_no_session_row of_those_sessions after_a_compaction in_sessions_never_compacted
--------- ------------------------------- ----------------- ------------------ ---------------------------
152 47 12 91 8
The old messages with no matching id in session_message, by where they sit.
Of the 152: 47 belong to 12 sessions that have no row in session either; 91 sit after a compaction in their session; 8 are in sessions that were never compacted; and the remaining 6 sit in compacted sessions but before the first compaction. Compaction may play a part, and the orphaned sessions may too. I do not know. I also cannot tell from the database alone whether OpenCode migrated the old rows or wrote both layouts for a while; for a reader the result is the same.
If you write a reader
The rule that works on this database is the one our collector uses: if session_v2 exists, read the new tables, because they also hold the old sessions. You can read it in the collector’s source (commit abe3f56). Check that it holds for you:
SELECT count(*) AS old_sessions,
sum(id IN (SELECT id FROM session_v2)) AS also_in_session_v2
FROM session;
old_sessions also_in_session_v2
------------ ------------------
1179 1179
Every old session is also in session_v2. The 152 message ids above are the one place where reading only the new tables is not the same as reading the old data.
Windows and Linux
Tested on Linux for the copy commands; Windows documented or assumed, nothing run there. On 20 November 2026, in an Ubuntu 24.04 container (arm64, SQLite 3.45.1), I made a small WAL-mode database and ran the cp line and the sqlite3 -readonly line from above. The glob copied the database and both companion files, and integrity_check printed ok (tested). I did not run OpenCode there.
- Linux. The vendor’s troubleshooting page gives
~/.local/share/opencode/opencode.dbwithOPENCODE_DBas override (documented), so the commands should run unchanged on real data (assumed). - Windows. The same page text has no Windows path; I take
%USERPROFILE%\.local\share\opencode\opencode.dbfrom session formats, which lists its sources. SQLite publishes a Windows command-line shell as a zip,sqlite-tools-win-x64or-arm64(documented: sqlite.org’s download page). A PowerShell copy would beCopy-Itemwith a wildcard path (documented: Microsoft’sCopy-Itempage; I did not run it), and I assume the-waland-shmfiles must be copied with the database, as on macOS. In WSL, use the Linux home (assumed).