[PR #12631] feat(cli): add session prune command for cleanup #14302

Open
opened 2026-02-16 18:19:06 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12631

State: open
Merged: No


Summary

Adds opencode session prune <duration> command to delete old sessions and free disk space.

After heavy usage, the ~/.local/share/opencode/storage/ directory can grow to 10+ GB with thousands of old sessions. This command provides a safe way to clean up old data.

Features

  • Duration format: 1d, 7d, 2w, 1m (days/hours/weeks/months)
  • --dry-run: Preview what would be deleted without making changes
  • --force/-f: Skip confirmation prompt
  • --all/-a: Prune sessions from all projects (not just current)
  • --logs: Also prune old log files
  • --snapshots: Also prune orphaned snapshot directories

Usage Examples

# Preview cleanup of sessions older than 7 days
opencode session prune 7d --dry-run

# Clean up sessions older than 1 month with logs
opencode session prune 1m --logs

# Clean up everything older than 2 weeks, including orphaned snapshots
opencode session prune 2w --logs --snapshots --force

Output

Shows a summary of sessions to be deleted with age, estimated space savings, and asks for confirmation before proceeding.

Testing

Tested manually with --dry-run on a storage directory with 400+ sessions.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12631 **State:** open **Merged:** No --- ## Summary Adds `opencode session prune <duration>` command to delete old sessions and free disk space. After heavy usage, the `~/.local/share/opencode/storage/` directory can grow to 10+ GB with thousands of old sessions. This command provides a safe way to clean up old data. ## Features - **Duration format**: `1d`, `7d`, `2w`, `1m` (days/hours/weeks/months) - `--dry-run`: Preview what would be deleted without making changes - `--force/-f`: Skip confirmation prompt - `--all/-a`: Prune sessions from all projects (not just current) - `--logs`: Also prune old log files - `--snapshots`: Also prune orphaned snapshot directories ## Usage Examples ```bash # Preview cleanup of sessions older than 7 days opencode session prune 7d --dry-run # Clean up sessions older than 1 month with logs opencode session prune 1m --logs # Clean up everything older than 2 weeks, including orphaned snapshots opencode session prune 2w --logs --snapshots --force ``` ## Output Shows a summary of sessions to be deleted with age, estimated space savings, and asks for confirmation before proceeding. ## Testing Tested manually with `--dry-run` on a storage directory with 400+ sessions.
yindo added the pull-request label 2026-02-16 18:19:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14302