Exporting OpenCode History to Obsidian

scripts/export-opencode-history.mjs provides a deterministic, one-way mirror from the local OpenCode SQLite session database (~/.local/share/opencode/opencode.db) into Obsidian markdown notes under 05 - Conversations/<Project>/.

bun run export:history [options]
bun scripts/export-opencode-history.mjs --dry-run --limit 5
bun scripts/export-opencode-history.mjs --project-dir ~/vivera

Safety and Content Guarantees

ConcernHow it is handled
Read-Only SQLite AccessThe database is opened with readonly: true (openReadonly()). No query touches the credential table; there is no code path capable of writing to the database.
Inlined AttachmentsInline session images and binary attachments are hashed with sha256 and unpacked into .attachments/. Timestamps are preserved across runs (restoreUnchangedAttachmentTimes) so obsidian-git avoids false-positive commits on unchanged images.
Spill ContainmentLarge tool execution outputs spilled to disk are read safely within an allowed root. Path traversal (.. and symlinks pointing outside the root) is strictly refused, and output exceeding maxBytes is truncated with a clear visible marker.
Secret Redaction8 distinct secret signatures are redacted from messages before writing: AWS access keys, GitHub classic & fine-grained PATs, PEM private keys, JWTs, Bearer tokens, TOTP codes, and generic API key assignments.
Change Detectionsync-writer.mjs checks note contents before writing. A re-run against an unchanged database performs zero disk writes.
Failure ContainmentWrites are buffered: individual broken sessions are logged and skipped, but if more than half of the batch fails, the run exits non-zero having written nothing.

CLI Options

FlagPurpose
--dry-runRender and resolve sessions without writing notes or attachments to disk.
--limit NProcess at most N sessions, oldest first (0 processes none).
--vault PATHDestination Obsidian vault root (defaults to $OPENCODE_EXPORT_VAULT, else the vaultRoot key in local.config.json; see local.config.example.json).
--db PATHPath to the OpenCode SQLite database (defaults to ~/.local/share/opencode/opencode.db).
--project-dir PATHFilter to export only sessions associated with PATH or its subdirectories.