Skip to main content

ocdbc — OpenCode Database Cleaner

Safely analyze and shrink OpenCode's SQLite database.

OpenCode stores all session history in a single SQLite database (~/.local/share/opencode/opencode.db). Over time, compaction and session archival leave behind freelist pages — free space inside the file that is never returned to the filesystem unless auto_vacuum is enabled and VACUUM is run. Databases routinely bloat to 1–2 GB, with >50% being dead air.

ocdbc provides two commands:

  • analyze — read-only health report (no risk)
  • vacuum — safe VACUUM sequence with backup, integrity checks, and auto_vacuum = INCREMENTAL enablement

Installation

# from PyPI (recommended)
pip install ocdbc

# from GitHub
pip install git+https://github.com/chncaesar/opencode-db-clean.git

# from source
git clone https://github.com/chncaesar/opencode-db-clean.git
cd opencode-db-clean
pip install .

Requires Python 3.8+ (stdlib only, zero pip dependencies).

Usage

Analyze (always safe, read-only)

ocdbc analyze

Shows: DB size, live data vs freelist, table sizes, session age distribution, and the 5 largest messages.

Vacuum (safe sequence)

ocdbc vacuum

The vacuum command performs these steps in order:

  1. fuser check — refuse if OpenCode still has the DB open (unless --skip-fuser)
  2. WAL checkpoint — flush write-ahead log into the main DB
  3. Integrity check — abort if database is corrupt
  4. Backup — timestamped copy, then verify backup integrity
  5. Enable auto_vacuum = INCREMENTAL — prevent future freelist bloat
  6. VACUUM — rebuild the database with progress indication
  7. Re-enable WAL — VACUUM resets journal mode; restore it
  8. Final integrity check — verify the result
# Skip the confirmation prompt
ocdbc vacuum --force

# Skip backup (dangerous — backup is recommended)
ocdbc vacuum --no-backup --force

# Proceed without fuser installed (use with caution)
ocdbc vacuum --skip-fuser --force

# Custom database path
ocdbc vacuum --path /custom/path/opencode.db

Safety

  • Refuses to run if OpenCode has the database open (detected via fuser)
  • Refuses to run if fuser is not installed — pass --skip-fuser to override
  • Checks integrity before and after — abort if anything looks wrong
  • Creates a verified timestamped backup before VACUUM (unless --no-backup)
  • VACUUM uses atomic rename — original DB untouched if the operation fails

Example

$ ocdbc analyze

OpenCode Database Health Report
──────────────────────────────────────────────────────────
  Path:          /home/zjc/.local/share/opencode/opencode.db
  File size:     1.3 GB
  Page size:     4.0 KB
  Journal mode:  wal
  Auto-vacuum:   OFF (NONE)

Storage
──────────────────────────────────────────────────────────
  Live data:     525 MB
  Freelist:      766 MB  (56% of file)
  ↳ VACUUM would reclaim ~766 MB
  ↳ Estimated result:  ~525 MB
$ ocdbc vacuum

  ✓ No process has the database open

  Current size:   1.3 GB
  Live data:      525 MB
  Freelist:       766 MB (56%)

  Proceed with VACUUM? [y/N] y

  ✓ WAL checkpointed
  ✓ Integrity check passed
  ✓ Backup created (1.3 GB)
  ✓ Backup integrity verified
  ✓ auto_vacuum set to INCREMENTAL
  ✓ VACUUM complete
  ✓ journal_mode = wal
  ✓ Integrity check passed

Results
──────────────────────────────────────────────────────────
  Before:   1.3 GB
  After:    578 MB
  Reclaimed: 731 MB

  Backup:   /home/zjc/.local/share/opencode/opencode.db.backup.2026-07-22T...
  (Keep it until you verify OpenCode works correctly)

License

MIT

Metadata

Release files for ocdbc 0.1.1

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

Source distribution (sdist)

Source distribution for ocdbc 0.1.1
File Size Uploaded Provenance Actions
ocdbc-0.1.1.tar.gz 9.7 kB Without provenance Details for ocdbc-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ocdbc 0.1.1
File Interpreter ABI Platform Actions
ocdbc-0.1.1-py3-none-any.whl Python 3 none any Details for ocdbc-0.1.1-py3-none-any.whl

Total release size: 19.8 kB

Release files / ocdbc-0.1.1.tar.gz

Download URL ocdbc-0.1.1.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c211573587ca14a552e7451650b0cb94d17da59ff20ddd340d8f7e0e4919b174
BLAKE2b-256 checksum
How to use checksums
977bc78cd7a7978ef6c313cdd4da532edeacce46a73387109f6343e487ad0e93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / ocdbc-0.1.1-py3-none-any.whl

Download URL ocdbc-0.1.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd5c75f12cc0aef515c979392242ad08295f0bd0821268ee7ec2db7b2abc89b0
BLAKE2b-256 checksum
How to use checksums
62616dfd04220cf720f48fe7f9d8bf97ea22183c56a17311b5907725d58b0a7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Security for ocdbc 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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