Skip to content

Session storage grows unboundedly — add opencode session prune command and auto-cleanup config #22110

Description

@vsixer

Problem

opencode stores all session history, messages, file parts, and diffs in ~/.local/share/opencode/storage/ with no automatic cleanup and no CLI command to reclaim disk space.
After ~5 months of regular use on a single project, my storage has grown to:

~/.local/share/opencode/
├── storage/
│   ├── message/          497 MB   (conversation messages)
│   ├── part/             966 MB   (30,122 files — file content snapshots)
│   ├── session_diff/     989 MB   (session state diffs)
│   └── session/          5.3 MB   (1,324 session index files)
└── tool-output/           52 MB   (Playwright, shell outputs)
Total: ~5.1 GB

Growth rate: ~500 MB/month. At this pace, it will reach 6+ GB within a year for a single project.

What I'd expect

1. CLI command: opencode session prune

# Dry run — show what would be deleted
opencode session prune --older-than 30d --dry-run
# Delete sessions older than 30 days and reclaim disk space
opencode session prune --older-than 30d
# Show current storage usage by category
opencode session stats

2. Config option for automatic cleanup

"session": {
  "retention_days": 30,  // auto-prune sessions older than N days
  "max_storage_mb": 2048 // or cap by total size
}

3. What should be cleaned up

When a session is deleted, all associated data should be removed:

  • storage/session/{project_id}/ses_*.json
  • storage/message/ entries linked to that session
  • storage/part/ entries linked to those messages (the biggest contributor at ~1 GB)
  • storage/session_diff/ses_*.json
  • tool-output/ entries linked to that session

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions