opencode plugin that backs up your sessions to google drive (or anywhere) so you stop losing work when things crash.
- 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
cd ~/.opencode
npm install opencode-session-backupthat's it. plugin loads automatically.
option 1: opencode config (recommended)
add to your opencode config:
{
"session-backup": {
"backupPath": "/path/to/backup/folder"
}
}option 2: environment variable
export OPENCODE_BACKUP_PATH="/path/to/backup/folder"enable debug logging:
opencode config
{
"session-backup": {
"backupPath": "/path/to/backup/folder",
"debug": true
}
}environment variable
export OPENCODE_BACKUP_DEBUG="true"| platform | default destination |
|---|---|
| windows | ~/Google Drive/opencode-sessions |
| macos | ~/Library/CloudStorage/GoogleDrive/My Drive/opencode-sessions |
| linux | set via config or env var |
manual backup. use when you want to force a sync.
session_backup_sync force=true
shows backup stats: session count, size, last sync time, pending syncs.
session_backup_status
example 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: 3
restores sessions from backup. requires confirmation because it overwrites current sessions.
session_backup_restore confirm=true
restart opencode after restore to see your sessions.
- 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/
check if destination exists and is writable:
# windows
Test-Path "G:\Mi unidad\opencode-sessions"
# unix
ls -la ~/Library/CloudStorage/GoogleDrive/My\ Drive/opencode-sessionsmake sure backup folder exists and has data:
session_backup_statusif Sessions backed up: 0, your backup is empty.
google drive desktop can lock files during sync. if you see errors, wait for drive to finish syncing or use a local folder instead.
MIT