You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Orphaned opencode-wal-*.db files accumulate in $TMPDIR and can consume hundreds of GB #36831
OpenCode leaves orphaned SQLite WAL (Write-Ahead Log) database files named opencode-wal-<timestamp>.db in the system temp directory ($TMPDIR), and they are never cleaned up. Each file is ~1.4 GB, and they accumulate over time — one new file per session/restart, without any retention or cleanup mechanism. This silently fills the disk.
On my machine (macOS, Apple Silicon), this directory reached 268 GB across 200 files:
$TMPDIR = /var/folders/1m/wh2zy6gn4nx9vqscbl24l9m40000gp/T
$ ls -1 $TMPDIR/opencode-wal-*.db | wc -l
200
$ du -ch $TMPDIR/opencode-wal-*.db | tail -1
268G total
This is the dominant cause of disk exhaustion on my system — it was consuming far more space than everything else combined. The naming pattern (opencode-wal-<epoch-ms>.db) suggests a new WAL file is created per session/instance with a timestamp, but the old ones are never removed when the session ends or on the next startup.
This looks related in spirit to the other unbounded-temp-file leaks already reported (#29694 tool-output spill files, #14811 / #8749 snapshot tmp_pack_*, #27005 Windows temp), but the WAL files are a distinct artifact in a different location ($TMPDIR, not ~/.local/share/opencode) and don't appear to be covered by any existing issue.
Expected behavior
Old opencode-wal-*.db files should be removed automatically on session end and/or on startup, OR
The active WAL should reuse a stable path instead of a per-session timestamped filename, OR
A bounded retention (by age and/or count) should be applied, and/or a documented cleanup command provided.
Current workaround
Delete orphaned WAL files, keeping only the most recently modified one (the active session):
# keep the newest, delete the rest
ls -t "$TMPDIR"/opencode-wal-*.db | tail -n +2 | xargs rm -f
Plugins
No response
OpenCode version
1.17.12
Steps to reproduce
Use OpenCode across multiple sessions / restarts over an extended period.
Inspect the system temp directory:
du -ch "$TMPDIR"/opencode-wal-*.db | tail -1
ls -1 "$TMPDIR"/opencode-wal-*.db | wc -l
Observe that a new ~1.4 GB opencode-wal-<timestamp>.db file is created per session and old ones are never cleaned up, growing without bound.
Confirming this on 1.18.8 (macOS, Apple Silicon). Also reproduced on 1.18.7 — updating does not help.
Hit 214 GB across 106 files in roughly 20 hours, which took a 460 GB disk down to 2 GB free twice in two days.
The files are created on a fixed 5-minute timer, not per session
The report above guesses "one new file per session/restart". That does not match what I measured. I took the epoch-ms timestamps from the 104 orphaned files and computed the deltas between consecutive files:
Interval between files
Occurrences
300 s
60
299 s
27
~600 s / ~1000 s / ~1843 s
6 total
87 of 93 intervals are exactly 300 seconds. The handful of larger values are near-multiples of 300 s, i.e. ticks skipped while the app was closed or idle. This is a periodic checkpoint on a 5-minute timer, independent of session count or restarts. Worth knowing for whoever fixes it — the cleanup hook belongs on the timer, not on session teardown.
Each file is a full copy of opencode.db, byte for byte
They are not SQLite WAL files despite the name — file(1) reports them as complete SQLite 3 databases, and they carry the full schema (session, message, part, event, migrations). The name is misleading enough that users may hesitate to delete them, thinking they hold session history.
Why this hits some users catastrophically and others not at all
The leak rate is DB size / 5 minutes. So it scales with how big opencode.db has grown, which is governed by #33356 (unpruned event table).
My instance:
Metric
Value
opencode.db
2.07 GB
Sessions
1,120 (910 of them sub-agent sessions)
Events
81,396
event table
1,374 MB — 66% of the DB
History retained
~4 months, never pruned
That works out to ~24 GB/hour, or ~600 GB/day if the app stays open. A colleague on the same version saw nothing, because their DB is ~100 MB — the same bug leaks ~1 GB/hour for them and they never notice.
So the two issues compound: #33356 inflates the DB, #36831 copies it every 5 minutes forever. Heavy sub-agent workflows accumulate sessions fast and land squarely in the bad case.
Note on the workaround above
tail -n +2 keeps only the newest file. I'd suggest tail -n +3 instead — keeps two, costs one extra copy, and leaves a recovery point in case the live DB is mid-write:
I verified no process held a handle on any of them before deleting, and the live DB was unaffected.
Possibly related: #37495 describes multiple concurrent SQLite connections preventing WAL checkpointing. If the 5-minute snapshot exists to hand a consistent view to a secondary reader, that would tie the two together — but I haven't confirmed that from the source.
Activity
asanre commentedon Jul 29, 2026
Confirming this on 1.18.8 (macOS, Apple Silicon). Also reproduced on 1.18.7 — updating does not help.
Hit 214 GB across 106 files in roughly 20 hours, which took a 460 GB disk down to 2 GB free twice in two days.
The files are created on a fixed 5-minute timer, not per session
The report above guesses "one new file per session/restart". That does not match what I measured. I took the epoch-ms timestamps from the 104 orphaned files and computed the deltas between consecutive files:
87 of 93 intervals are exactly 300 seconds. The handful of larger values are near-multiples of 300 s, i.e. ticks skipped while the app was closed or idle. This is a periodic checkpoint on a 5-minute timer, independent of session count or restarts. Worth knowing for whoever fixes it — the cleanup hook belongs on the timer, not on session teardown.
Each file is a full copy of opencode.db, byte for byte
They are not SQLite WAL files despite the name —
file(1)reports them as complete SQLite 3 databases, and they carry the full schema (session,message,part,event, migrations). The name is misleading enough that users may hesitate to delete them, thinking they hold session history.Why this hits some users catastrophically and others not at all
The leak rate is
DB size / 5 minutes. So it scales with how bigopencode.dbhas grown, which is governed by #33356 (unprunedeventtable).My instance:
opencode.dbeventtableThat works out to ~24 GB/hour, or ~600 GB/day if the app stays open. A colleague on the same version saw nothing, because their DB is ~100 MB — the same bug leaks ~1 GB/hour for them and they never notice.
So the two issues compound: #33356 inflates the DB, #36831 copies it every 5 minutes forever. Heavy sub-agent workflows accumulate sessions fast and land squarely in the bad case.
Note on the workaround above
tail -n +2keeps only the newest file. I'd suggesttail -n +3instead — keeps two, costs one extra copy, and leaves a recovery point in case the live DB is mid-write:I verified no process held a handle on any of them before deleting, and the live DB was unaffected.
Possibly related: #37495 describes multiple concurrent SQLite connections preventing WAL checkpointing. If the 5-minute snapshot exists to hand a consistent view to a secondary reader, that would tie the two together — but I haven't confirmed that from the source.
github-actions commentedon Sep 29, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.