The complete on-disk format of each harness’s session transcripts: every file a session writes, every record type and field, and how to rebuild the conversation from them. Where sessions live and how to resume, export or delete them is on the Transcripts page. Examples use placeholder values.
At a glance
| Question | OpenCode2.3.0 |
|---|---|
| Specification | No published schema; defined by the open-source code |
| Transcript file | ~/.local/share/opencode/ (XDG_DATA_HOME/opencode, also on macOS) |
| Storage | SQLite (WAL): session_v2 and mutable session_message rows. With experimental.part_rows, assistant content lives in session_part; the reader prepends those parts in ordinal order to any remaining inline content. With experimental.media_blob, user/tool media can reference deduplicated blob rows. Both gates default off, but the reader supports mixed historical and gated rows. |
| Record type field | session_message.type, data.status for compaction, and assistant content type from session_part.type or inline data.content[].type; tool state.status selects its lifecycle shape. |
| Size | 23 record types, 23 content blocks |
Records by purpose
| Records | OpenCode2.3.0 |
|---|---|
| Session | |
| Session header | |
| Model, directory and settings | |
| Forks and subagents | |
| Files and workspace state | |
| Conversation | |
| User message | |
| Assistant message | |
| System and injected context | |
| Reasoning | |
| Images, files and attachments | |
| Queued and steered input | |
| Tools | |
| Tool call | |
| Tool result | |
| Tool progress | |
| Turns | |
| Turn starts | |
| Turn ends | |
| Errors | |
| Context and accounting | |
| Compaction | |
| Token usage | |
| Other records | |
OpenCode 2.3.0
No published schema; defined by the open-source code. SQLite (WAL): session_v2 and mutable session_message rows. With experimental.part_rows, assistant content lives in session_part; the reader prepends those parts in ordinal order to any remaining inline content. With experimental.media_blob, user/tool media can reference deduplicated blob rows. Both gates default off, but the reader supports mixed historical and gated rows.
Files
~/.local/share/opencode/ (XDG_DATA_HOME/opencode, also on macOS) | Global data root. |
|---|---|
~/.local/share/opencode/opencode.db (+ -wal, -shm) | SQLite (WAL) shared by all projects: session_v2, session_message, session_part, blob, blob_ref, session_inbox, instruction_*, event, event_sequence, kv, project, workspace, worktree, permission, credential, account*, migration, plus untouched 1.x tables (session, message, part, todo, session_share, ...) on upgraded installs. OPENCODE_DB overrides (relative to data dir; ':memory:' allowed); non-standard channels use opencode-<channel>.db unless OPENCODE_DISABLE_CHANNEL_DB. |
~/.local/share/opencode/opencode-next.db | Pre-release 2.x database imported on first start if present. |
~/.local/share/opencode/tool-output/tool_<26-char id>[.<ext>] | Full text of tool results truncated to 2000 lines / 50 KiB (and saved binary outputs); referenced by tool state metadata.outputPath and the inline marker. Deleted after 7 days. |
~/.local/share/opencode/shell/<project-id>/<sh_id>.out | Combined stdout/stderr capture for shells (Shell.Info.file); retained 7 days. |
~/.local/share/opencode/snapshot/<project-id>/<hash(worktree)>/ | Private git directory whose tree hashes are the snapshot ids in assistant.snapshot.start/end and revert.snapshot; diffs/reverts are computed from it. |
~/.local/share/opencode/storage/ (1.x remnant) | Older JSON storage (migration marker, session_diff) from pre-SQLite builds; not read for 2.x transcripts. on a 1.x install. |
Fields on every record
Record type is chosen by session_message.type, data.status for compaction, and assistant content type from session_part.type or inline data.content[].type; tool state.status selects its lifecycle shape..
| Field | Type | Meaning |
|---|---|---|
id | text | msg_ + 12 hex time + 14 base62 (ascending). Event-derived rows reuse the event id suffix (evt_→msg_); fork copies use msg_<forkEventSuffix>_<seq>. |
session_id | text | FK session_v2.id (cascade delete). |
type | text | Discriminator. |
seq | integer | Durable event seq that inserted the row; unique per session; gaps are normal. |
time_created | integer ms | Mirrors data.time.created (assistant: request start). |
time_updated | integer ms | Last mutation. |
data | json text | — |
Records (23)
session_v2 (row)
One row per session: identity, lineage, location, title, current agent/model, running usage totals and state timestamps.
Written inserted on session.created (or session.forked); columns updated by later events.
| Field | Type | Meaning |
|---|---|---|
id | text ses_<26> | Descending time-sortable id (newest sorts first). |
project_id | text | FK project.id. |
workspace_idoptional | text | — |
parent_idoptional | text | Parent session for subagent/child sessions. |
fork_session_idoptional | text | Source session of a fork (parent_id is null on forks). |
fork_boundaryoptional | json {type:before|through, messageID} | — |
slug | text | — |
directory | text | Absolute working directory. |
pathoptional | text | Subpath relative to project worktree. |
titleoptional | text | Optional since the 2.x split (1.x required). |
version | text | opencode version that created the session. |
share_urloptional | text | Legacy/sharing. |
summary_additions/summary_deletions/summary_filesoptional | integer | Legacy 1.x diff summary. |
summary_diffsoptional | json FileDiff.LegacyInfo[] | Legacy 1.x. |
metadataoptional | json Record<string,Json> | Host annotations; inherited by children/forks. |
cost | real | USD total (steps + title + compaction usage). |
tokens_input/tokens_output/tokens_reasoning/tokens_cache_read/tokens_cache_write | integer | Running totals. |
revertoptional | json Revert {messageID, partID?, snapshot?, files?} | RevertV1 | Staged (uncommitted) revert. |
permissionoptional | json Permission.Ruleset | — |
agentoptional | text | Current agent id. |
modeloptional | json {id, providerID, variant?} | Current model. |
time_created/time_updated | integer ms | — |
time_idleoptional | integer ms | Last terminal execution. |
idle_outcomeoptional | text succeeded|failed|interrupted | — |
time_viewedoptional | integer ms | Read watermark. |
time_compactingoptional | integer | — |
time_archivedoptional | integer | — |
time_suspendedoptional | integer | Execution claim timestamp (historical name). |
resume_attempts | integer | — |
time_busyoptional | integer ms | Session busy timestamp. |
{"id":"ses_8f3a2b1c0d9eAbCdEfGhIjKlMn","project_id":"prj_example","parent_id":null,"slug":"quiet-river","directory":"/workspace/project","title":"Example","version":"2.1.4","cost":0.0123,"tokens_input":1200,"tokens_output":300,"tokens_reasoning":0,"tokens_cache_read":0,"tokens_cache_write":0,"agent":"build","model":{"id":"example-model","providerID":"example"},"time_created":1767261600000,"time_updated":1767261660000}session_message / user
A user prompt with optional inline file attachments, @agent and skill mentions.
Written projected when a queued/steered inbox item of type user is delivered (session.inbox.delivered).
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.text | string | — |
data.filesoptional | (FileAttachment | FileRef)[] | Stored attachment may contain inline base64 data or uri:media:<sha256>; hydrate from blob before decoding the public message shape. |
data.agentsoptional | {name, mention?}[] | — |
data.skillsoptional | {id, name, text?, mention?}[] | — |
{"id":"msg_0a1b2c3d4e5fAbCdEfGhIjKlMn","session_id":"ses_x","type":"user","seq":4,"time_created":1767261601000,"time_updated":1767261601000,"data":{"text":"Hello","time":{"created":1767261601000}}}session_message / synthetic
Host-injected user-role text (e.g. subagent completion notices, plugin input), not typed by the user.
Written session.synthetic events or delivered synthetic inbox items.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.text | string | Model-facing text. |
data.descriptionoptional | string | Short display summary. |
{"type":"synthetic","seq":9,"data":{"text":"<subagent sessionID=\"ses_y\" state=\"completed\" description=\"scan\">done</subagent>","description":"scan","metadata":{"source":"subagent","childID":"ses_y","agent":"explore","state":"completed"},"time":{"created":1767261700000}}}session_message / system
Chronological instruction update shown to the model (e.g. AGENTS.md/instructions changed), frozen at emit time.
Written session.instructions.updated with rendered text (initial baseline has no text and produces no row). Also the V1 migration's tool-rename notice.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.text | string | — |
data.descriptionoptional | string | e.g. 'Instructions updated: <keys>' |
data.metadata.noticeoptional | "instructions" | — |
data.metadata.instructionSourcesoptional | string[] | — |
{"type":"system","seq":2,"data":{"text":"<instructions>...</instructions>","description":"Instructions updated: project/agents.md","metadata":{"notice":"instructions","instructionSources":["project/agents.md"]},"time":{"created":1767261600100}}}session_message / skill
A skill was activated and its text injected.
Written session.skill.activated.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.skill | string (Skill.ID) | — |
data.name | string | — |
data.text | string | Injected skill body. |
{"type":"skill","seq":5,"data":{"skill":"skill_example","name":"example","text":"# Example skill","time":{"created":1767261602000}}}session_message / shell
A user-run shell command (! in the TUI) with status and final output page.
Written inserted on session.shell.started (status running); updated in place on session.shell.ended.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadata.backgroundoptional | boolean | — |
data.shellID | string sh_<26> | — |
data.command | string | — |
data.status | enum(running,exited,timeout,killed) | — |
data.exitoptional | number | — |
data.outputoptional | {output, cursor, size, truncated} | Final page; full capture is in the shell output file. |
data.time.created | number ms | — |
data.time.completedoptional | number ms | — |
{"type":"shell","seq":12,"data":{"shellID":"sh_0a1b2c3d4e5fAbCdEfGhIjKlMn","command":"ls","status":"exited","exit":0,"output":{"output":"README.md\n","cursor":10,"size":10,"truncated":false},"time":{"created":1767261800000,"completed":1767261800200}}}session_message / assistant
One model step. Content is assembled from session_part in ordinal order followed by any inline data.content; usage, state and timing remain on session_message.
Written inserted on session.step.started; mutated in place by text/reasoning/tool/retry/step.streamed/step.ended/step.failed events. A retry of the same step reuses the row (fields reset).
| Field | Type | Meaning |
|---|---|---|
data.agent | string | — |
data.model | {id, providerID, variant?} | — |
data.content | (text|reasoning|tool)[] | See contentBlocks. |
data.snapshotoptional | {start?, end?, files?:string[]} | Git tree hashes in the snapshot repo before/after the step; files changed. |
data.finishoptional | enum(stop,length,tool-calls,content-filter,error,unknown) | Absent while running. |
data.rawFinishoptional | string | Provider-native finish. |
data.nativeoptional | Record<string,unknown> | Step-level provider replay data (was providerState before 2.1). |
data.costoptional | number USD | Set at step end. |
data.tokensoptional | {input, output, reasoning, cache:{read, write}} (all numbers; no total field) | — |
data.erroroptional | {type:string, message:string, status?:100-599, response?:{body}, retryAfterMs?:int} | — |
data.retryoptional | {attempt, at(ms), error} | Pending retry; cleared when the step restarts or the turn idles. |
data.metadataoptional | Record | — |
data.time.created | number ms | Request dispatch time. |
data.time.streamedoptional | number ms | Provider body ended. |
data.time.completedoptional | number ms | Absent = still running or crashed. |
data.time.firstTokenoptional | number ms | First streamed output token, before the response ends. |
{"type":"assistant","seq":6,"data":{"agent":"build","model":{"id":"example-model","providerID":"example"},"content":[{"type":"text","text":"Hi!"}],"finish":"stop","cost":0.0004,"tokens":{"input":100,"output":5,"reasoning":0,"cache":{"read":0,"write":0}},"time":{"created":1767261602000,"streamed":1767261603000,"completed":1767261603000}}}session_message / compaction (running)
Compaction in progress placeholder.
Written session.compaction.started (row id = inbox inputID or msg_ from event).
Stored only transient; left behind if the process dies
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.status | "running" | — |
data.reason | enum(auto,manual) | — |
data.summary | string | Empty while running. |
{"type":"compaction","seq":30,"data":{"status":"running","reason":"auto","summary":"","time":{"created":1767262000000}}}session_message / compaction (completed)
Context checkpoint: history before this row is replaced by the summary (or provider-native window).
Written session.compaction.ended updates the running row (or appends one).
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.status | "completed" | — |
data.reason | enum(auto,manual) | — |
data.modeloptional | {id, providerID, variant?} | — |
data.summary | string | — |
data.nativeoptional | Record; native.messages = provider compaction window | Was providerContext before 2.1. |
data.costoptional | number | Compaction request cost. |
data.tokensoptional | {input, output, reasoning, cache:{read, write}} (all numbers; no total field) | — |
data.metadata.keepIDoptional | msg id | First message kept verbatim after the summary (rows between keepID and this row). |
data.metadata.recentoptional | string | Pre-2.1 / V1-migrated kept text (was top-level recent). |
{"type":"compaction","seq":30,"data":{"status":"completed","reason":"auto","summary":"Goal: ...","cost":0.002,"tokens":{"input":9000,"output":400,"reasoning":0,"cache":{"read":0,"write":0}},"metadata":{"keepID":"msg_0a1b2c3d4e5fAbCdEfGhIjKlMp"},"time":{"created":1767262000000}}}session_message / compaction (failed)
Compaction attempt that failed.
Written session.compaction.failed.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.status | "failed" | — |
data.reason | enum(auto,manual) | — |
data.error | {type:string, message:string, status?:100-599, response?:{body}, retryAfterMs?:int} | — |
data.costoptional | number | — |
data.tokensoptional | {input, output, reasoning, cache:{read, write}} (all numbers; no total field) | — |
{"type":"compaction","seq":31,"data":{"status":"failed","reason":"manual","error":{"type":"provider","message":"overloaded"},"time":{"created":1767262000000}}}session_message / idle
Turn boundary: the session went idle; every step since the previous idle belongs to one turn.
Written session.execution.succeeded/failed/interrupted (not for interrupted reason=shutdown, which resumes the same turn).
Stored always (per completed turn)
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.outcome | enum(succeeded,failed,interrupted) | — |
data.erroroptional | {type:string, message:string, status?:100-599, response?:{body}, retryAfterMs?:int} | — |
{"type":"idle","seq":7,"data":{"outcome":"succeeded","time":{"created":1767261603100}}}session_message / agent-switched
Agent changed.
Written session.agent.selected.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.agent | string | — |
data.previousoptional | string | — |
{"type":"agent-switched","seq":1,"data":{"agent":"plan","previous":"build","time":{"created":1767261600050}}}session_message / model-switched
Model changed.
Written session.model.selected.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.model | {id, providerID, variant?} | — |
data.previousoptional | {id, providerID, variant?} | — |
{"type":"model-switched","seq":3,"data":{"model":{"id":"example-model","providerID":"example"},"time":{"created":1767261600060}}}session_message / location-switched
Session moved to another directory/workspace/project.
Written session.moved (also updates session_v2 location columns).
Stored conditional
| Field | Type | Meaning |
|---|---|---|
data.metadataoptional | Record<string,unknown> | Free-form metadata (event metadata, e.g. notice/source tags). |
data.time.created | number (epoch ms) | — |
data.location | {directory, workspaceID?} | — |
data.projectIDoptional | string | — |
data.subpathoptional | string | — |
data.previousoptional | {location, projectID?, subpath?} | — |
{"type":"location-switched","seq":20,"data":{"location":{"directory":"/workspace/other"},"time":{"created":1767261900000}}}session_inbox (row)
Queued or steering input admitted but not yet delivered to the transcript (user, synthetic, compaction request, move).
Written session.inbox.enqueued inserts; delivered/cancelled deletes; delivery.changed flips steer/queue. Revert deletes rows with enqueued_seq >= boundary.
Stored only transient
| Field | Type | Meaning |
|---|---|---|
id | text msg_ | Becomes the session_message id on delivery. |
session_id | text | — |
type | enum(user,synthetic,compaction,move) | — |
payload | json UserPayload|SyntheticPayload|{}|MovePayload | — |
delivery | enum(steer,queue) | — |
enqueued_seq | integer | Event seq at admission. |
time_created | integer ms | — |
{"id":"msg_0a1b2c3d4e5fAbCdEfGhIjKlMq","session_id":"ses_x","type":"user","payload":{"text":"also check tests"},"delivery":"queue","enqueued_seq":15,"time_created":1767261650000}instruction_entry / instruction_state / instruction_blob (rows)
Per-session instruction state: API-managed key/value entries, the current and epoch-initial instruction key→hash maps, and content-addressed instruction bodies.
Written instructions.updated, forks, compaction epochs, revert rewinds.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
instruction_entry.(session_id,key) | pk | — |
instruction_entry.valueoptional | json | <=256 KiB |
instruction_entry.removed | boolean | — |
instruction_state.epoch_start/through_seq | integer | — |
instruction_state.initial_values/current_values | json Record<key,sha256> | — |
instruction_blob.hash | text sha256 hex | — |
instruction_blob.valueoptional | json | Instruction body. |
{"session_id":"ses_x","epoch_start":0,"through_seq":2,"initial_values":{"project/agents.md":"aaaaaaaa..."},"current_values":{"project/agents.md":"aaaaaaaa..."}}event (row)
Durable event log (event-sourcing input for the projections above), stored as type '<event>.<version>' with per-aggregate seq.
Written only when the server runs with events.persist=true (set by the Cloudflare workerd host). The CLI does not set it, so locally the table stays empty and only event_sequence advances.
Stored only events.persist only
| Field | Type | Meaning |
|---|---|---|
id | text evt_<26> | — |
aggregate_id | text (session id) | — |
seq | integer | — |
created | integer ms | — |
type | text e.g. session.tool.success.2 | — |
data | json | Event payload. |
{"id":"evt_0a1b2c3d4e5fAbCdEfGhIjKlMn","aggregate_id":"ses_x","seq":6,"created":1767261602000,"type":"session.step.started.1","data":{"sessionID":"ses_x","assistantMessageID":"msg_y","agent":"build","model":{"id":"m","providerID":"p"},"started":1767261602000}}Durable event types (52 definitions; ephemeral deltas/progress never stored): session.created, agent.selected, model.selected, moved, renamed, metadata.updated, permissions, viewed, archived, unarchived, deleted(v2), forked(v2), inbox.delivered, inbox.enqueued, inbox.cancelled, inbox.delivery.changed, execution.started/succeeded/failed/interrupted, instructions.updated(v2), synthetic, skill.activated, shell.started/ended, step.started/streamed/ended/failed, text.started/ended, reasoning.started/ended, tool.input.started/ended, tool.called, tool.success(v2), tool.failed(v2), retry.scheduled, compaction.started/ended/failed, revert.staged/cleared/committed, usage.recorded (internal), message.content.updated (replay-only), worktree.resolved
Ephemeral (never persisted): session.usage.updated, text.delta, reasoning.delta, tool.input.delta, tool.progress, compaction.delta.
event_sequence (row)
Last committed event seq per aggregate (session); session_message.seq values come from it.
Written every durable event commit.
| Field | Type | Meaning |
|---|---|---|
aggregate_id | text | — |
seq | integer | — |
owner_idoptional | text | — |
{"aggregate_id":"ses_x","seq":42,"owner_id":null}kv (row)
Key/value state; key migration.v1-v2 records the in-place 1.x to 2.x import.
Written migration and misc.
Stored conditional
| Field | Type | Meaning |
|---|---|---|
key | text | — |
value | text | — |
time_created/time_updated | integer | — |
{"key":"migration.v1-v2","value":"{...}","time_created":1767261600000,"time_updated":1767261600000}legacy message (1.x row)until 2.0.0
1.x message row (role user|assistant) left in the old message table after upgrade; the 2.x reader ignores it once imported.
Written written by 1.x only; remains after the V1→V2 import (tables are not dropped).
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text msg_ | — |
session_id | text | FK legacy session table. |
time_created/time_updated | integer | — |
data.role | enum(user,assistant) | — |
data (user)optional | {time.created, format?, summary?{title?,body?,diffs}, agent, model{providerID,modelID,variant?}, system?, tools?} | — |
data (assistant)optional | {time{created,completed?}, error?{name,data}, parentID, modelID, providerID, mode, agent, path{cwd,root}, summary?, cost, tokens{total?,input,output,reasoning,cache{read,write}}, structured?, variant?, finish?} | — |
{"id":"msg_x","session_id":"ses_x","data":{"role":"assistant","parentID":"msg_u","modelID":"m","providerID":"p","mode":"build","agent":"build","path":{"cwd":"/p","root":"/p"},"cost":0,"tokens":{"input":1,"output":1,"reasoning":0,"cache":{"read":0,"write":0}},"time":{"created":1767261600000}}}session_part (row)
Optional split storage of an assistant text, reasoning or tool block; mutable during streaming.
| Field | Type | Meaning |
|---|---|---|
message_id | text | Owning assistant message; composite primary key with ordinal. |
session_id | text | Owning session. |
ordinal | integer | Content order within the message, not session event seq. |
type | text|reasoning|tool | Assistant content discriminator. |
call_idoptional | text|null | Tool call identity when applicable. |
time_created/time_updated | integer ms | Storage timestamps. |
data | json | Assistant content block. |
blob (row)
Deduplicated raw attachment bytes stored in SQLite when experimental.media_blob is enabled.
| Field | Type | Meaning |
|---|---|---|
hash | text sha256 | Primary key; lowercase hash of raw bytes. |
mime | text | Media type. |
bytes | integer | Byte count. |
width/heightoptional | integer|null | Optional image dimensions. |
data | BLOB | Raw bytes, not base64. |
time_created | integer ms | Creation time. |
blob_ref (row)
Tracks media ownership for session/message cleanup and fork/revert handling.
| Field | Type | Meaning |
|---|---|---|
session_id/message_id/hash | text | Composite primary key. |
seq | integer | Owning event sequence. |
Content blocks (23)
assistant.content / text
Assistant visible text segment.
Written session.text.started pushes empty text; text.ended fills it.
| Field | Type | Meaning |
|---|---|---|
type | "text" | — |
text | string | — |
nativeoptional | Record | Provider replay data (was state before 2.1). |
{"type":"text","text":"Done."}assistant.content / reasoning
Model reasoning segment.
Written reasoning.started/ended.
| Field | Type | Meaning |
|---|---|---|
type | "reasoning" | — |
text | string | — |
nativeoptional | Record | Encrypted/signature data. |
timeoptional | {created, completed?} | — |
{"type":"reasoning","text":"Check the config first.","time":{"created":1767261602100,"completed":1767261602500}}assistant.content / tool
A tool call and its result live in one block whose state advances streaming → running → completed | error.
Written tool.input.started creates it; input.ended, called, success/failed update it.
| Field | Type | Meaning |
|---|---|---|
type | "tool" | — |
id | string | Provider call id. |
name | string | e.g. shell, read, edit, write, patch, glob, grep, subagent, skill, todo, question, webfetch, websearch, mcp tools. |
executedoptional | boolean | true when OpenCode ran it (false for provider-executed tools). |
nativeoptional | Record | Call native data merged with result native data. |
state | ToolState | See tool state entries. |
time | {created, ran?, completed?} | — |
{"type":"tool","id":"call_1","name":"shell","executed":true,"state":{"status":"completed","input":{"command":"ls"},"content":[{"type":"text","text":"README.md"}],"metadata":{"truncated":false}},"time":{"created":1767261602600,"ran":1767261602700,"completed":1767261602900}}tool.state / streaming
Arguments are still streaming (1.x called this pending).
Written session.tool.input.started; input.ended sets the raw string.
Stored only only if interrupted mid-stream
| Field | Type | Meaning |
|---|---|---|
status | "streaming" | — |
input | string | Raw argument text. |
{"status":"streaming","input":"{\"command\":\"l"}tool.state / running
Parsed input, executing.
Written session.tool.called.
Stored only in-flight or crashed
| Field | Type | Meaning |
|---|---|---|
status | "running" | — |
input | object | — |
metadata | Record<string,Json> | Progress metadata is ephemeral; stored value is {} unless later terminal. |
{"status":"running","input":{"command":"ls"},"metadata":{}}tool.state / completed
Successful result.
Written session.tool.success (v2).
| Field | Type | Meaning |
|---|---|---|
status | "completed" | — |
input | object | — |
content | non-empty (text|file)[] | Model-facing result. |
metadataoptional | Record<string,Json> | UI metadata; truncated:boolean and outputPath when output was spilled to tool-output/. |
{"status":"completed","input":{"path":"a.txt"},"content":[{"type":"text","text":"hello"}],"metadata":{"truncated":false}}tool.state / error
Failed or interrupted tool.
Written session.tool.failed (v2).
| Field | Type | Meaning |
|---|---|---|
status | "error" | — |
input | object | {} if failure happened while streaming. |
error | {type:string, message:string, status?:100-599, response?:{body}, retryAfterMs?:int} | e.g. type tool.execution, tool.interrupted (V1 import). |
contentoptional | (text|file)[] | Partial output. |
metadataoptional | Record | — |
{"status":"error","input":{"command":"false"},"error":{"type":"tool.execution","message":"exit 1"}}tool.content / text
Text item in a tool result.
Written inside state.content.
| Field | Type | Meaning |
|---|---|---|
type | "text" | — |
text | string | — |
{"type":"text","text":"ok"}tool.content / file
File/media item in a tool result, by URI.
Written inside state.content.
| Field | Type | Meaning |
|---|---|---|
type | "file" | — |
uri | string | data: URI or other URI. |
mime | string | — |
nameoptional | string | — |
{"type":"file","uri":"data:image/png;base64,iVBORw0KGgo=","mime":"image/png"}user.files[]
Prompt attachment stored inline.
Written user message data.files.
| Field | Type | Meaning |
|---|---|---|
data | uri | base64 | media:<sha256> | Inline bytes or a stored blob reference; API media references are a separately negotiated capability. |
mime | string | — |
source | {type:inline}|{type:uri,uri} | — |
nameoptional | string | — |
descriptionoptional | string | — |
mentionoptional | {start,end,text} | — |
{"data":"aGVsbG8=","mime":"text/plain","source":{"type":"inline"},"name":"a.txt"}user.agents[] / user.skills[]
@agent and skill mentions in the prompt.
Written user message data.agents / data.skills.
| Field | Type | Meaning |
|---|---|---|
agents[].name | string | — |
skills[].id/name | string | — |
skills[].textoptional | string | — |
*.mentionoptional | {start,end,text} | — |
{"name":"explore","mention":{"start":0,"end":8,"text":"@explore"}}legacy part / textuntil 2.0.0
1.x part row of type text (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "text" | — |
data | object | {text, synthetic?, ignored?, time?{start,end?}, metadata?} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "text"}}legacy part / reasoninguntil 2.0.0
1.x part row of type reasoning (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "reasoning" | — |
data | object | {text, metadata?, time{start,end?}} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "reasoning"}}legacy part / fileuntil 2.0.0
1.x part row of type file (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "file" | — |
data | object | {mime, filename?, url (data: or file:), source?{type:file|symbol|resource,...}} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "file"}}legacy part / tooluntil 2.0.0
1.x part row of type tool (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "tool" | — |
data | object | {callID, tool, state:{status:pending{input,raw}|running{input,title?,metadata?,time.start}|completed{input,output,title,metadata,time{start,end,compacted?},attachments?}|error{input,error,metadata?,time}}, metadata?} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "tool"}}Import mapping: text/reasoning/tool → assistant content; user text/file/agent → user fields; synthetic text → synthetic row; compaction+summary assistant → compaction row; step-start/snapshot/patch/step-finish → assistant.snapshot; subtask and its task tool call dropped; tool renames bash→shell, task→subagent, apply_patch→patch; pending/running tools become error tool.interrupted.
legacy part / step-startuntil 2.0.0
1.x part row of type step-start (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "step-start" | — |
data | object | {snapshot?} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "step-start"}}legacy part / step-finishuntil 2.0.0
1.x part row of type step-finish (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "step-finish" | — |
data | object | {reason, snapshot?, cost, tokens{total?,input,output,reasoning,cache{read,write}}} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "step-finish"}}legacy part / snapshotuntil 2.0.0
1.x part row of type snapshot (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "snapshot" | — |
data | object | {snapshot} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "snapshot"}}legacy part / patchuntil 2.0.0
1.x part row of type patch (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "patch" | — |
data | object | {hash, files[]} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "patch"}}legacy part / agentuntil 2.0.0
1.x part row of type agent (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "agent" | — |
data | object | {name, source?{value,start,end}} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "agent"}}legacy part / subtaskuntil 2.0.0
1.x part row of type subtask (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "subtask" | — |
data | object | {prompt, description, agent, model?{providerID,modelID}, command?} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "subtask"}}legacy part / retryuntil 2.0.0
1.x part row of type retry (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "retry" | — |
data | object | {attempt, error(APIError), time{created}} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "retry"}}legacy part / compactionuntil 2.0.0
1.x part row of type compaction (legacy table; migrated into 2.x shapes on first 2.x start).
Written written by 1.x only.
Stored legacy (1.x databases only)
| Field | Type | Meaning |
|---|---|---|
id | text prt_ | — |
message_id | text | — |
session_id | text | — |
data.type | "compaction" | — |
data | object | {auto, overflow?, tail_start_id?} |
{"id": "prt_x", "message_id": "msg_x", "session_id": "ses_x", "data": {"type": "compaction"}}Rebuilding the conversation
- ordering
- ORDER BY seq within session_id. seq is the per-session durable event sequence, so it has gaps; do not use id or time_created as the primary order (assistant time_created is reset on retry).
- message parent links
- None in 2.x: the transcript is a flat seq-ordered list (1.x assistant.parentID pointed at the user message; it is not carried over).
- tool call ↔ result
- Call and result are the same assistant content block (type tool, keyed by id); the result is state.content when status=completed/error. Find the latest block with matching id in the step.
- turns
- A turn = rows after the previous idle row up to and including the next idle row (steered prompts mid-turn included). Each assistant row is one LLM step; finish=tool-calls means another step follows.
- subagents
- The subagent tool creates a child session_v2 row with parent_id = parent session; the tool result text/metadata carries the child sessionID; background completions arrive in the parent as synthetic rows with metadata {source:subagent, childID, agent, state}.
- forks
- A fork is a new session_v2 row with parent_id NULL, fork_session_id = source and fork_boundary {before|through, messageID}; settled rows up to the boundary are physically copied with new ids msg_<evt>_<seq> and the same seq; compaction metadata.keepID is remapped.
- compaction
- Model history starts at the latest completed compaction row (status=completed): summary replaces everything before it; rows from metadata.keepID up to the compaction are re-rendered as 'recent' text; a provider-native compaction (native.messages) replays only on the same model. Raw rows before the compaction remain in the table.
- branches/rewind
- Revert: session_v2.revert holds a staged revert (messageID, snapshot, files); on commit all session_message rows with seq >= the target row's seq (and inbox rows) are DELETED and instruction state rewound. No branches are kept.
- resume
- Resume continues the same session id; an assistant row with no time.completed is an interrupted/in-flight step and is superseded by the next step.started.
- sidecar references
- tool state.metadata.outputPath → tool-output file; shell rows → shell/<project>/<sh_id>.out; assistant.snapshot.start/end and session_v2.revert.snapshot → git trees in snapshot/<project>/<hash>/.
- session settings
- Current agent/model are session_v2.agent/model; history of changes is the agent-switched/model-switched rows; each assistant row records the agent and model it used.
- split assistant content
- history.withParts joins session_part by message_id, orders by ordinal, and appends remaining inline data.content after those parts. Decode only after this join; empty inline content does not mean an empty reply.
- stored media
- After withParts, hydrate media:<sha256> from blob. blob_ref scopes ownership; missing blob bytes become explicit unavailable placeholders. API clients can negotiate experimental-media-uri and fetch /api/experimental/media/:hash; this is not the on-disk representation.
Token usage
assistant data.tokens {input, output, reasoning, cache.read, cache.write}- Per-step usage from step.ended (or step.failed when reported). No total; reasoning is a separate bucket.
assistant data.cost- Per-step USD computed by OpenCode.
compaction data.cost/tokens- Cost of the compaction request (accounted via internal usage.recorded).
session_v2.cost and tokens_*- Running totals consume usage.recorded, including auxiliary model work such as title generation, compaction and session.generate/cache warming. These costs need not have a visible transcript row.
Versions
No per-row schema version. session_v2.version records the creating opencode version; the migration table lists applied migration ids (seeded from __drizzle_migrations on old installs); kv migration.v1-v2 records the 1.x import. Readers upgrade older 2.x row shapes on decode (SessionLegacy): before 2.1 native data was named state/providerState/resultState/providerResultState, compaction stored kept text in recent and provider windows in providerContext; window media before 2.0.15 used {mediaType,data}. 1.x (session/message/part tables, role+parts model) is imported in place on first 2.x start into session_v2/session_message; the 1.x tables and rows are left behind, and persisted 1.x events are deleted. A pre-split 2.x DB (marker 20260730195856_optional_session_title) had its session table renamed to session_v2 in migration 20260804233008_loose_psylocke. At 2.3.0, session_part and blob/blob_ref are present with gated writers and unconditional backwards-compatible hydration. Migration ids include 20261025123711_blob and 20261029002625_session_part. The obsolete session_pending definition has been removed. No per-row schema version is added.
Parsing pitfalls
- Rows are mutable: assistant, shell and compaction rows are rewritten in place while streaming; read time.completed / status before trusting content.
- Tool calls and results are one block; there is no separate tool_result row.
- seq has gaps and equals the event sequence; forks reuse parent seq values.
- Revert physically deletes rows; there is no history of abandoned branches.
- Upgraded 1.x databases still contain the old session/message/part tables; reading them gives stale pre-import data and misses all 2.x activity.
- A failed provider step and its retry reuse the same assistant row id; fields are reset on restart.
- Older 2.x rows use legacy key names (providerState, state, recent, providerContext); apply the SessionLegacy renames before decoding.
- Large tool output is truncated in the DB and the full text lives in tool-output/ files that are deleted after 7 days.
- Source audit 2026-11-15: version and commit identify inspected release source, not a passing runtime probe or a compatibility guarantee. Earlier source pins and observations are retained in the audit evidence manifest.
- experimental.part_rows and experimental.media_blob default off; their tables and read compatibility still matter when flags change or builds share a database.
- The normal local event bus defaults persist:false; the workerd host registers persist:true. Transcript projection rows remain the local history surface even without an event replay ledger. Do not generalize one host to every OpenCode deployment.
- Session totals also include auxiliary usage.recorded events (for example title, compaction and session.generate/cache warming); summing visible transcript rows can undercount.
- Storage ref media:<sha256> names a blob identity, not a filesystem path or HTTP route. Older rows can remain inline.
- part_rows is read directly from experimental config and defaults false; media_blob uses the Flag service, defaults off in release channels and on in local/dev channels, with config/environment overrides. Import/copy paths may create parts independently of the streaming adapter selection.
Sources
OpenCode
- opencode source: packages/cli/src/database-path.ts, Source code, checked 2026-10-26
- opencode source: packages/cli/src/server-process.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/bus.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/database/database.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/database/v1-migration.bun.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/event/sql.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/kv/sql.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/session/history.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/session/inbox.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/session/message-updater.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/session/projector.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/session/sql.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/session/subagent-completion.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/shell.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/snapshot.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/tool-output.ts, Source code, checked 2026-10-26
- opencode source: packages/core/src/tool/plugin/subagent.ts, Source code, checked 2026-10-26
- opencode source: packages/schema/src/instruction.ts, Source code, checked 2026-10-26
- opencode source: packages/schema/src/prompt.ts, Source code, checked 2026-10-26
- opencode source: packages/schema/src/session-inbox.ts, Source code, checked 2026-10-26
- opencode source: packages/schema/src/session-message.ts, Source code, checked 2026-10-26
- opencode source: packages/schema/src/shell.ts, Source code, checked 2026-10-26
- opencode source: packages/schema/src/tool.ts, Source code, checked 2026-10-26
- opencode source: packages/schema/src/v1/session.ts, Source code, checked 2026-10-26
- opencode source: packages/server/src/workerd.ts, Source code, checked 2026-10-26
- opencode source: packages/util/src/global-roots.ts, Source code, checked 2026-10-26
- Transcript audit 2.3.0: packages/core/src/session/sql.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/schema/src/session-message.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/event/sql.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/database/v1-migration.bun.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/schema/src/v1/session.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/schema/src/tool.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/schema/src/prompt.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/util/src/global-roots.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/session/blob.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/session/stored.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/session/history.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/session/projector.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/session.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/flag.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/schema/src/config/flag.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/database/migration/20261025123711_blob.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/database/migration/20261029002625_session_part.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/cli/src/commands/handlers/session/export.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/cli/src/server-process.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/server/src/workerd.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/cli/src/database-path.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/cli/src/commands/commands.ts, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/tui/src/prompt/history.tsx, Source code, checked 2026-11-15
- Transcript audit 2.3.0: packages/core/src/tool/plugin/subagent.ts, Source code, checked 2026-11-15