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
| Concern | How it is handled |
| Read-Only SQLite Access | The 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 Attachments | Inline 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 Containment | Large 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 Redaction | 8 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 Detection | sync-writer.mjs checks note contents before writing. A re-run against an unchanged database performs zero disk writes. |
| Failure Containment | Writes 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
| Flag | Purpose |
--dry-run | Render and resolve sessions without writing notes or attachments to disk. |
--limit N | Process at most N sessions, oldest first (0 processes none). |
--vault PATH | Destination Obsidian vault root (defaults to $OPENCODE_EXPORT_VAULT, else the vaultRoot key in local.config.json; see local.config.example.json). |
--db PATH | Path to the OpenCode SQLite database (defaults to ~/.local/share/opencode/opencode.db). |
--project-dir PATH | Filter to export only sessions associated with PATH or its subdirectories. |