Skip to main content

opencode-db

Python License

CLI for OpenCode's local database. OpenCode saves every agent session, conversation, token usage, and cost in a local SQLite file. This tool lets you inspect, export, analyze, and clean up that data.

pip install opencode-db

# recommended if your system python3 is older than 3.12:
uv tool install opencode-db

Quick start

opencode-db --version    # installed version
opencode-db list         # recent sessions
opencode-db directories  # launch directories, including missing ones
opencode-db view         # interactive session viewer (colored, scrollable)
opencode-db stats        # database summary
opencode-db health       # SQLite storage health (read-only)
opencode-db backup       # managed, verified snapshot
opencode-db backups list # inspect snapshots
opencode-db schema       # detect v1/v2 schema
opencode-db costs --total  # total token costs
opencode-db export       # export dialog to Markdown (interactive)
opencode-db export --format json  # lossless JSON archive
opencode-db digest <id>  # compaction summaries
opencode-db help         # full reference

Features

  • view — terminal session viewer with ANSI colors, Markdown rendering, and less scrolling
  • list / info / search / tree — browse and search sessions
  • directories (dirs) — every launch directory, including missing ones; list --directory adds the path to each session
  • export — Markdown or lossless JSON; preserves patch, file, compaction, step-*, and unknown part types; unique opencode-<date>-<short_id> filenames
  • digest — compaction summaries for v1 and v2 sessions, with --last N and --json
  • delete / prune — single and bulk cleanup; prune --missing-directories is preview-first and guarded
  • costs / stats — token and cost analytics
  • health — read-only freelist, WAL, auto_vacuum, reclaimable-space, and backup-freshness report
  • backup / backups — managed snapshots with manifest, sha256, gzip, verify, and retention; --from-backup opens a snapshot read-only
  • vacuum — guarded optimization: lock check, verified backup, integrity check, and WAL preservation
  • schema — detects the OpenCode v1/v2 schema, migrations, and capabilities
  • --db-path / OPENCODE_DB — custom database path
  • --from-backup — read-only access to a managed snapshot (.db or .db.gz)

Возможности

  • view — просмотр сессии в терминале с ANSI-цветами, Markdown-рендерингом и прокруткой через less
  • list / info / search / tree — навигация и поиск по сессиям
  • directories (dirs) — все директории запусков, включая отсутствующие; list --directory добавляет путь к сессии
  • export — Markdown или lossless JSON; сохраняет patch, file, compaction, step-* и неизвестные типы частей; уникальные имена opencode-<date>-<short_id>
  • digest — compaction-сводки для v1 и v2, с --last N и --json
  • delete / prune — удаление и массовая очистка; prune --missing-directories работает через preview и guard'ы
  • costs / stats — аналитика токенов и расходов
  • health — read-only отчёт о freelist, WAL, auto_vacuum, reclaimable space и свежести backup
  • backup / backups — управляемые снимки с manifest, sha256, gzip, verify и retention; --from-backup открывает снимок read-only
  • vacuum — безопасная оптимизация: lock check, проверенный backup, integrity check и сохранение WAL
  • schema — определяет v1/v2-схему OpenCode, миграции и доступные операции
  • --db-path / OPENCODE_DB — кастомный путь к БД
  • --from-backup — read-only работа с управляемым снимком (.db или .db.gz)

Optional extras

pip install opencode-db[rich]   # enhanced Markdown rendering (recommended)
pip install opencode-db         # zero external dependencies

Requirements

  • Python 3.12+ — the CLI checks the interpreter at startup and exits with a clear message instead of an ImportError on older versions
  • OpenCode (must have been run at least once)
  • macOS / Linux

Directory support: global is a synthetic project for non-Git directories; directories shows the real session.directory and marks it as Global (no project root). Missing paths are detected with os.path.isdir() at command runtime and can be filtered with --missing.

Schema support: OpenCode 1.19.x (v1) — read and write; OpenCode 2.x preview (v2) — read-only. Run opencode-db schema to check the detected schema. On v2, health and the read-only commands work; delete, prune, and vacuum are refused until write support is implemented.

Metadata

Release files for opencode-db 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opencode-db 0.12.0
File Size Uploaded Provenance Actions
opencode_db-0.12.0.tar.gz 111.1 kB With provenance Details for opencode_db-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for opencode-db 0.12.0
File Interpreter ABI Platform Actions
opencode_db-0.12.0-py3-none-any.whl Python 3 none any Details for opencode_db-0.12.0-py3-none-any.whl

Total release size: 207.4 kB

Release files / opencode_db-0.12.0.tar.gz

Download URL opencode_db-0.12.0.tar.gz
Size 111.1 kB
Tags Source
SHA-256 checksum
How to use checksums
41307f6a9a035ca9a7dd57ba1208d2a9aec28c42b2ffc23eae497dfb63416b74
BLAKE2b-256 checksum
How to use checksums
b8f631ea8548a145111bb2a71d9cafc87439ce42d6ebf52579c5b6a0efb64eb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / opencode_db-0.12.0-py3-none-any.whl

Download URL opencode_db-0.12.0-py3-none-any.whl
Size 96.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79e779c1c3f351662f08ee09176d469d23e331f717b69496e5beeec1d55cd3cb
BLAKE2b-256 checksum
How to use checksums
fa5ca498a5af0030cbc382b3927b569e5f9787388454afaa1c52ffb6687ce2d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for opencode-db 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for opencode_db-0.12.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page