opencode-session-backup
v1.3.0
Published
OpenCode plugin that automatically backs up sessions to Google Drive or any folder
Maintainers
Readme
Session Backup Plugin for Opencode
opencode plugin that backs up your sessions to google drive (or anywhere) so you stop losing work when things crash.
what you get
- auto-backup after every message, session update, and deletion
- incremental sync using robocopy (windows) or rsync (unix)
- debounced so it doesn't hammer your disk (30s minimum between syncs)
- restore tool to get your sessions back after a crash
- status tool to see backup stats
install
cd ~/.opencode
npm install opencode-session-backupthat's it. plugin loads automatically.
configuration
add to your opencode config:
{
"session-backup": {
"backupPath": "/path/to/backup/folder"
}
}export OPENCODE_BACKUP_PATH="/path/to/backup/folder"debug mode
enable debug logging:
{
"session-backup": {
"backupPath": "/path/to/backup/folder",
"debug": true
}
}export OPENCODE_BACKUP_DEBUG="true"default paths
| platform | default destination |
|----------|---------------------|
| windows | ~/Google Drive/opencode-sessions |
| macos | ~/Library/CloudStorage/GoogleDrive/My Drive/opencode-sessions |
| linux | set via config or env var |
tools
session_backup_sync
manual backup. use when you want to force a sync.
session_backup_sync force=truesession_backup_status
shows backup stats: session count, size, last sync time, pending syncs.
session_backup_statusexample output:
Backup path: G:\Mi unidad\opencode-sessions
Sessions backed up: 47
Backup size: 12.3 MB
Last backup: 1/29/2026, 9:15:00 PM
Last sync success: yes
Syncs this session: 3session_backup_restore
restores sessions from backup. requires confirmation because it overwrites current sessions.
session_backup_restore confirm=truerestart opencode after restore to see your sessions.
how it works
- plugin hooks into opencode events (
message.updated,session.updated,session.deleted) - schedules a sync after 5s delay (debounced)
- runs robocopy/rsync with
/MIRflag for incremental sync - logs to
sync.login backup folder
opencode storage ──robocopy/rsync──▶ backup folder
│ │
└── session/ └── session/
└── message/ └── message/
└── part/ └── part/
└── todo/ └── todo/troubleshoot
backup not running
check if destination exists and is writable:
# windows
Test-Path "G:\Mi unidad\opencode-sessions"
# unix
ls -la ~/Library/CloudStorage/GoogleDrive/My\ Drive/opencode-sessionsrestore not working
make sure backup folder exists and has data:
session_backup_statusif Sessions backed up: 0, your backup is empty.
google drive sync conflicts
google drive desktop can lock files during sync. if you see errors, wait for drive to finish syncing or use a local folder instead.
license
MIT
