Harness Notes

Transcript format

Updated 2026-11-22,

On this page

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

QuestionOpenCode2.3.0
SpecificationNo published schema; defined by the open-source code
Transcript file~/.local/share/opencode/ (XDG_DATA_HOME/opencode, also on macOS)
StorageSQLite (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 fieldsession_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.
Size23 record types, 23 content blocks

Records by purpose

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.dbPre-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>.outCombined 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..

FieldTypeMeaning
idtextmsg_ + 12 hex time + 14 base62 (ascending). Event-derived rows reuse the event id suffix (evt_→msg_); fork copies use msg_<forkEventSuffix>_<seq>.
session_idtextFK session_v2.id (cascade delete).
typetextDiscriminator.
seqintegerDurable event seq that inserted the row; unique per session; gaps are normal.
time_createdinteger msMirrors data.time.created (assistant: request start).
time_updatedinteger msLast mutation.
datajson 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.

FieldTypeMeaning
idtext ses_<26>Descending time-sortable id (newest sorts first).
project_idtextFK project.id.
workspace_idoptionaltext—
parent_idoptionaltextParent session for subagent/child sessions.
fork_session_idoptionaltextSource session of a fork (parent_id is null on forks).
fork_boundaryoptionaljson {type:before|through, messageID}—
slugtext—
directorytextAbsolute working directory.
pathoptionaltextSubpath relative to project worktree.
titleoptionaltextOptional since the 2.x split (1.x required).
versiontextopencode version that created the session.
share_urloptionaltextLegacy/sharing.
summary_additions/summary_deletions/summary_filesoptionalintegerLegacy 1.x diff summary.
summary_diffsoptionaljson FileDiff.LegacyInfo[]Legacy 1.x.
metadataoptionaljson Record<string,Json>Host annotations; inherited by children/forks.
costrealUSD total (steps + title + compaction usage).
tokens_input/tokens_output/tokens_reasoning/tokens_cache_read/tokens_cache_writeintegerRunning totals.
revertoptionaljson Revert {messageID, partID?, snapshot?, files?} | RevertV1Staged (uncommitted) revert.
permissionoptionaljson Permission.Ruleset—
agentoptionaltextCurrent agent id.
modeloptionaljson {id, providerID, variant?}Current model.
time_created/time_updatedinteger ms—
time_idleoptionalinteger msLast terminal execution.
idle_outcomeoptionaltext succeeded|failed|interrupted—
time_viewedoptionalinteger msRead watermark.
time_compactingoptionalinteger—
time_archivedoptionalinteger—
time_suspendedoptionalintegerExecution claim timestamp (historical name).
resume_attemptsinteger—
time_busyoptionalinteger msSession 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).

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.textstring—
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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.textstringModel-facing text.
data.descriptionoptionalstringShort 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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.textstring—
data.descriptionoptionalstringe.g. 'Instructions updated: <keys>'
data.metadata.noticeoptional"instructions"—
data.metadata.instructionSourcesoptionalstring[]—
{"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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.skillstring (Skill.ID)—
data.namestring—
data.textstringInjected 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

FieldTypeMeaning
data.metadata.backgroundoptionalboolean—
data.shellIDstring sh_<26>—
data.commandstring—
data.statusenum(running,exited,timeout,killed)—
data.exitoptionalnumber—
data.outputoptional{output, cursor, size, truncated}Final page; full capture is in the shell output file.
data.time.creatednumber ms—
data.time.completedoptionalnumber 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).

FieldTypeMeaning
data.agentstring—
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.finishoptionalenum(stop,length,tool-calls,content-filter,error,unknown)Absent while running.
data.rawFinishoptionalstringProvider-native finish.
data.nativeoptionalRecord<string,unknown>Step-level provider replay data (was providerState before 2.1).
data.costoptionalnumber USDSet 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.metadataoptionalRecord—
data.time.creatednumber msRequest dispatch time.
data.time.streamedoptionalnumber msProvider body ended.
data.time.completedoptionalnumber msAbsent = still running or crashed.
data.time.firstTokenoptionalnumber msFirst 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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.status"running"—
data.reasonenum(auto,manual)—
data.summarystringEmpty 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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.status"completed"—
data.reasonenum(auto,manual)—
data.modeloptional{id, providerID, variant?}—
data.summarystring—
data.nativeoptionalRecord; native.messages = provider compaction windowWas providerContext before 2.1.
data.costoptionalnumberCompaction request cost.
data.tokensoptional{input, output, reasoning, cache:{read, write}} (all numbers; no total field)—
data.metadata.keepIDoptionalmsg idFirst message kept verbatim after the summary (rows between keepID and this row).
data.metadata.recentoptionalstringPre-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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.status"failed"—
data.reasonenum(auto,manual)—
data.error{type:string, message:string, status?:100-599, response?:{body}, retryAfterMs?:int}—
data.costoptionalnumber—
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)

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.outcomeenum(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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.agentstring—
data.previousoptionalstring—
{"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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (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

FieldTypeMeaning
data.metadataoptionalRecord<string,unknown>Free-form metadata (event metadata, e.g. notice/source tags).
data.time.creatednumber (epoch ms)—
data.location{directory, workspaceID?}—
data.projectIDoptionalstring—
data.subpathoptionalstring—
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

FieldTypeMeaning
idtext msg_Becomes the session_message id on delivery.
session_idtext—
typeenum(user,synthetic,compaction,move)—
payloadjson UserPayload|SyntheticPayload|{}|MovePayload—
deliveryenum(steer,queue)—
enqueued_seqintegerEvent seq at admission.
time_createdinteger 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

FieldTypeMeaning
instruction_entry.(session_id,key)pk—
instruction_entry.valueoptionaljson<=256 KiB
instruction_entry.removedboolean—
instruction_state.epoch_start/through_seqinteger—
instruction_state.initial_values/current_valuesjson Record<key,sha256>—
instruction_blob.hashtext sha256 hex—
instruction_blob.valueoptionaljsonInstruction 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

FieldTypeMeaning
idtext evt_<26>—
aggregate_idtext (session id)—
seqinteger—
createdinteger ms—
typetext e.g. session.tool.success.2—
datajsonEvent 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.

FieldTypeMeaning
aggregate_idtext—
seqinteger—
owner_idoptionaltext—
{"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

FieldTypeMeaning
keytext—
valuetext—
time_created/time_updatedinteger—
{"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)

FieldTypeMeaning
idtext msg_—
session_idtextFK legacy session table.
time_created/time_updatedinteger—
data.roleenum(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.

FieldTypeMeaning
message_idtextOwning assistant message; composite primary key with ordinal.
session_idtextOwning session.
ordinalintegerContent order within the message, not session event seq.
typetext|reasoning|toolAssistant content discriminator.
call_idoptionaltext|nullTool call identity when applicable.
time_created/time_updatedinteger msStorage timestamps.
datajsonAssistant content block.

blob (row)

Deduplicated raw attachment bytes stored in SQLite when experimental.media_blob is enabled.

FieldTypeMeaning
hashtext sha256Primary key; lowercase hash of raw bytes.
mimetextMedia type.
bytesintegerByte count.
width/heightoptionalinteger|nullOptional image dimensions.
dataBLOBRaw bytes, not base64.
time_createdinteger msCreation time.

blob_ref (row)

Tracks media ownership for session/message cleanup and fork/revert handling.

FieldTypeMeaning
session_id/message_id/hashtextComposite primary key.
seqintegerOwning event sequence.

Content blocks (23)

assistant.content / text

Assistant visible text segment.

Written session.text.started pushes empty text; text.ended fills it.

FieldTypeMeaning
type"text"—
textstring—
nativeoptionalRecordProvider replay data (was state before 2.1).
{"type":"text","text":"Done."}

assistant.content / reasoning

Model reasoning segment.

Written reasoning.started/ended.

FieldTypeMeaning
type"reasoning"—
textstring—
nativeoptionalRecordEncrypted/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.

FieldTypeMeaning
type"tool"—
idstringProvider call id.
namestringe.g. shell, read, edit, write, patch, glob, grep, subagent, skill, todo, question, webfetch, websearch, mcp tools.
executedoptionalbooleantrue when OpenCode ran it (false for provider-executed tools).
nativeoptionalRecordCall native data merged with result native data.
stateToolStateSee 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

FieldTypeMeaning
status"streaming"—
inputstringRaw argument text.
{"status":"streaming","input":"{\"command\":\"l"}

tool.state / running

Parsed input, executing.

Written session.tool.called.

Stored only in-flight or crashed

FieldTypeMeaning
status"running"—
inputobject—
metadataRecord<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).

FieldTypeMeaning
status"completed"—
inputobject—
contentnon-empty (text|file)[]Model-facing result.
metadataoptionalRecord<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).

FieldTypeMeaning
status"error"—
inputobject{} 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.
metadataoptionalRecord—
{"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.

FieldTypeMeaning
type"text"—
textstring—
{"type":"text","text":"ok"}

tool.content / file

File/media item in a tool result, by URI.

Written inside state.content.

FieldTypeMeaning
type"file"—
uristringdata: URI or other URI.
mimestring—
nameoptionalstring—
{"type":"file","uri":"data:image/png;base64,iVBORw0KGgo=","mime":"image/png"}

user.files[]

Prompt attachment stored inline.

Written user message data.files.

FieldTypeMeaning
data | uribase64 | media:<sha256>Inline bytes or a stored blob reference; API media references are a separately negotiated capability.
mimestring—
source{type:inline}|{type:uri,uri}—
nameoptionalstring—
descriptionoptionalstring—
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.

FieldTypeMeaning
agents[].namestring—
skills[].id/namestring—
skills[].textoptionalstring—
*.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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"text"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"reasoning"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"file"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"tool"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"step-start"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"step-finish"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"snapshot"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"patch"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"agent"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"subtask"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"retry"—
dataobject{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)

FieldTypeMeaning
idtext prt_—
message_idtext—
session_idtext—
data.type"compaction"—
dataobject{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