opencode-db
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, andlessscrollinglist/info/search/tree— browse and search sessionsdirectories(dirs) — every launch directory, including missing ones;list --directoryadds the path to each sessionexport— Markdown or lossless JSON; preservespatch,file,compaction,step-*, and unknown part types; uniqueopencode-<date>-<short_id>filenamesdigest— compaction summaries for v1 and v2 sessions, with--last Nand--jsondelete/prune— single and bulk cleanup;prune --missing-directoriesis preview-first and guardedcosts/stats— token and cost analyticshealth— read-only freelist, WAL,auto_vacuum, reclaimable-space, and backup-freshness reportbackup/backups— managed snapshots with manifest, sha256, gzip, verify, and retention;--from-backupopens a snapshot read-onlyvacuum— guarded optimization: lock check, verified backup, integrity check, and WAL preservationschema— 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 (.dbor.db.gz)
Возможности
view— просмотр сессии в терминале с ANSI-цветами, Markdown-рендерингом и прокруткой черезlesslist/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и--jsondelete/prune— удаление и массовая очистка;prune --missing-directoriesработает через preview и guard'ыcosts/stats— аналитика токенов и расходовhealth— read-only отчёт о freelist, WAL,auto_vacuum, reclaimable space и свежести backupbackup/backups— управляемые снимки с manifest, sha256, gzip, verify и retention;--from-backupоткрывает снимок read-onlyvacuum— безопасная оптимизация: lock check, проверенный backup, integrity check и сохранение WALschema— определяет 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
ImportErroron 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)
| 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)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 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 logRelease 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 logSecurity 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.
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 logA 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.