Skip to content

Microck/opencode-session-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

npm version npm downloads License: MIT


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-backup

that's it. plugin loads automatically.


configuration

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"

debug mode

enable debug logging:

opencode config
{
  "session-backup": {
    "backupPath": "/path/to/backup/folder",
    "debug": true
  }
}
environment variable
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=true

session_backup_status

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

session_backup_restore

restores sessions from backup. requires confirmation because it overwrites current sessions.

session_backup_restore confirm=true

restart opencode after restore to see your sessions.


how it works

  1. plugin hooks into opencode events (message.updated, session.updated, session.deleted)
  2. schedules a sync after 5s delay (debounced)
  3. runs robocopy/rsync with /MIR flag for incremental sync
  4. logs to sync.log in 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-sessions

restore not working

make sure backup folder exists and has data:

session_backup_status

if 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

About

opencode plugin that backs up sessions to google drive or anywhere. stop losing work.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors