OpenCode Garbage Collector — analyze and reclaim storage used by OpenCode sessions, diffs, and snapshots
Project description
ocgc
Analyze and reclaim storage used by OpenCode sessions, diffs, and snapshots.
OpenCode stores sessions in a SQLite file that grows without limit and has no built-in cleanup. It also writes session diffs and git snapshots to disk. ocgc shows where the space goes and reclaims it.
Install
uv tool install ocgc
Or with pip:
pip install ocgc
Usage
# Dashboard: DB size, session breakdown, storage by part type
ocgc status
# List sessions sorted by size
ocgc sessions --sort size --limit 20
# Deep analysis: top sessions, growth rate, root vs subagent
ocgc analyze
# Preview what a purge would do
ocgc purge --older-than 14d --dry-run
# Delete subagent sessions older than a week
ocgc purge --subagents --older-than 7d
# Strip reasoning tokens only (biggest space win, ~77% of storage)
ocgc purge --strip-reasoning
# Other purge options
ocgc purge --larger-than 50M
ocgc purge --keep-latest 50
ocgc purge --session ses_abc123
# Clean up orphan session diff files (no matching session in DB)
ocgc purge --clean-orphans
# Delete all snapshot directories
ocgc purge --clean-snapshots
# Reclaim disk space after purging
ocgc vacuum
Multiple purge flags combine with AND. --strip-reasoning changes the action from deleting sessions to removing reasoning parts (from matching sessions, or all sessions if no other filters are given). --clean-orphans and --clean-snapshots run independently before any session purge. --dry-run previews without touching anything. --force skips the confirmation prompt.
Filesystem storage
Beyond the SQLite database, OpenCode stores data on the filesystem:
- Session diffs (
~/.local/share/opencode/storage/session_diff/): one JSON file per session containing full file contents. Cleaned automatically when sessions are purged. - Snapshots (
~/.local/share/opencode/snapshot/): git object packs for each project. Use--clean-snapshotsto delete. - Tool output (
~/.local/share/opencode/tool-output/): small files from tool invocations. Shown in stats but no cleanup needed.
ocgc status and ocgc analyze show sizes for all three directories. analyze also reports orphan session diff files (files with no matching session in the DB).
Safety
status, sessions, and analyze are read-only. purge asks for confirmation before deleting. ocgc warns if OpenCode is running.
Custom database path
export OCGC_DB_PATH=/path/to/opencode.db
ocgc status
Default: ~/.local/share/opencode/opencode.db
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ocgc-0.1.0.tar.gz.
File metadata
- Download URL: ocgc-0.1.0.tar.gz
- Upload date:
- Size: 35.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83ff2de86a0bf12ddac40ff993660240fd1ed9853a954c0f0d9368eda0274b7f
|
|
| MD5 |
3d2a0c19366063c0672a32a13af59bb8
|
|
| BLAKE2b-256 |
b5fa5c854b1b4b0b34ddeb366ffc89794b4b61ce65422b30387e70ce0914c3c0
|
Provenance
The following attestation bundles were made for ocgc-0.1.0.tar.gz:
Publisher:
publish.yml on whtsky/ocgc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocgc-0.1.0.tar.gz -
Subject digest:
83ff2de86a0bf12ddac40ff993660240fd1ed9853a954c0f0d9368eda0274b7f - Sigstore transparency entry: 1308071455
- Sigstore integration time:
-
Permalink:
whtsky/ocgc@18201990f1cce95b1c3f3b5cf6180418fad4345b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/whtsky
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@18201990f1cce95b1c3f3b5cf6180418fad4345b -
Trigger Event:
push
-
Statement type:
File details
Details for the file ocgc-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ocgc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61ed60fab46e9fd484b59dc98584e983ef0446c1c7ee643c36207e859a20dd7d
|
|
| MD5 |
c97c2cb77187d5c9b3d76213776f3399
|
|
| BLAKE2b-256 |
e566f298fbd80be5107078d90a0b4e77a1b7e9ba5c3e43301b5b11366e3a903e
|
Provenance
The following attestation bundles were made for ocgc-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on whtsky/ocgc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocgc-0.1.0-py3-none-any.whl -
Subject digest:
61ed60fab46e9fd484b59dc98584e983ef0446c1c7ee643c36207e859a20dd7d - Sigstore transparency entry: 1308071589
- Sigstore integration time:
-
Permalink:
whtsky/ocgc@18201990f1cce95b1c3f3b5cf6180418fad4345b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/whtsky
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@18201990f1cce95b1c3f3b5cf6180418fad4345b -
Trigger Event:
push
-
Statement type: