Garbage collecting OpenCode's 2.4 GB session database

Dev.to / 4/15/2026

💬 OpinionDeveloper Stack & InfrastructureTools & Practical Usage

Key Points

  • OpenCode’s local SQLite session database (opencode.db) can grow rapidly because it stores full “thinking”/reasoning output and tool results for every turn, leading to multi-GB disk usage even with light usage.
  • The article notes OpenCode lacks built-in cleanup/garbage collection for these stored sessions, so the database may grow indefinitely and eventually become a storage “black hole.”
  • It benchmarks storage growth against Claude Code (about 86 MB) and Codex (about 95 MB) over the same period, highlighting that OpenCode’s approach is comparatively heavier.
  • The author introduces “ocgc” (OpenCode Garbage Collector) with commands like `ocgc status` and `ocgc analyze` to inspect where space is going and identify the largest sessions.
  • The proposed workflow is to run the garbage collector to reclaim disk space by cleaning up old/unneeded session data, mitigating the uncontrolled growth of the opencode.db file.

I've been using OpenCode from time to time for about a month, mainly working on a single side project in a tiny VPS. The disk free space is getting less and less so I decided to do some cleanup, then this caught my eye:

$ ls -lh ~/.local/share/opencode/opencode.db
-rw-r--r-- 1 ubuntu ubuntu 2.4G Apr 15 03:25 opencode.db

One month, non-heavy usage, single project, 2.4 GB of session database. That seems crazy.

What's eating the space

I asked an agent to give me more background and it turns out, OpenCode stores the full thinking & reasoning output for every turn in a single SQLite database. In my case, most of my 2.4 GB database is reasoning tokens and tool results, only less than 1% is actual conversation text. I'm not sure what's the real value of keeping them all, especially in a single SQLite database (credit to the strong SQLite), and I'm surprised to see OpenCode has no built-in cleanup for this. So this will just keep growing forever, until it becomes a black hole larger than node_modules.

For reference, Claude Code stores 86 MB for the same period. Codex uses 95 MB.

Let's garbage collect OpenCode session database

So I ( actually claude code ) built ocgc (OpenCode Garbage Collector).

uv tool install ocgc

ocgc status tells you where the space goes:

ocgc status showing OpenCode database size breakdown

ocgc analyze shows your heaviest sessions and how fast the database is growing:

ocgc analyze showing top OpenCode sessions by size

For the actual garbage collect part, ocgc purge:

ocgc purge --subagents --older-than 7d

ocgc purge removing 809 sessions and freeing 1.9 GB after vacuum

809 sessions, 1.8 GB. Gone. Then ocgc vacuum to actually reclaim the disk space, from 2.3 GB down to 438 MB.

After cleaning up the database, I also noticed OpenCode's snapshot/ and session_diff/ directories can take up quite some space too, so ocgc cleans those as well.

Go check your ~/.local/share/opencode/opencode.db. Disk space doesn't grow on trees.