Shell functions for syncing and backing up Claude Code project context across machines.
cc-sync (or cc-sync from) syncs the context for the CWD in ~/.claude/projects from a remote.
cc-sync to syncs context for the CWD to a remote.
Since the remote path is determined relative to $HOME, the CWD must be within $HOME.
The remote OS is taken into account when determining the context directory; context for ~/code/catbutt would be in
~/.claude/projects/-home-username-code-catbutton Linux and~/.claude/projects/-Users-username-code-catbutton macOS.
Context for the same relative path on the remote is assumed:
~/code/catbutt$ cc-sync xicamatl
# same as:
~/code/catbutt$ cc-sync xicamatl:code/catbuttThe remote relative path can be specified if different:
~/code/catbutt$ cc-sync xicamatl:projects/catbuttA relative path can be used with localhost to retrieve the context of a renamed project:
~/code/cul-de-chat$ cc-sync localhost:code/catbuttTo sync the local context to a remote:
~/code/catbutt$ cc-sync to xicamatlAs with cc-sync [from], the remote relative path can be specified.
cc-sync [from] and cc-sync to are rsync wrappers. By default rsync commands are additive, consolidating context across machines. Using the --delete option (without --find-args, see below) will clobber the destination with the source.
A backup of existing destination context is created before syncing when files would be transferred, except with --dry-run.
--find-args '<expression>'invokesrsync --files-from <list>with the output offind <expression>--modified-within <days>is an alias for--find-args '-type f -mtime -<days>'- Combining
--deletewith either will not delete unselected destination files.
Examples:
~/code/catbutt$ cc-sync --modified-within 3 xicamatl
~/code/catbutt$ cc-sync to --find-args "-type f -name '*.jsonl'" --dry-run xicamatlcc-sync list shows the local context directory for the CWD with ls -l -t.
cc-sync list host shows the matching remote context directory with ls -l -t.
cc-sync ls and cc-sync ls host are aliases for the same commands.
-
cc-sync [from|to] [rsync-options] <host[:path]>- Wraps
rsync -avwith passthrough of the following options:--dry-run,-n: preview what would be transferred--delete: clobber the destination, removing context not present in the source-z,--compress: compress data during transfer
- File selection options:
--modified-within <days>: select regular files matchingfind . -type f -mtime -<days>--find-args '<expression>': select files usingfind . <expression>
- Local context directory determined by CWD
- Remote context determined by the same relative path unless
:pathis specified - If
fromortois omitted,fromis assumed cc-sync tocreates the remote context directory if it doesn't exist
- Wraps
-
cc-sync backup- Creates a context backup for current working directory
- Backups are stored in
~/.claude/backups/projects/as{context-dir}_{timestamp}.tar.gz
-
cc-sync restore- Restores the most recent backup for current working directory without deleting the backup
-
cc-sync pop- Restores the most recent backup for current working directory and deletes the backup file
-
cc-sync [list|ls] [host[:path]]- Lists the local or remote context directory for the current working directory
- Uses
ls -l -tto show newest entries first - If
host[:path]is omitted, lists the local context directory
- Claude Code (
~/.claude/projects/directory must exist) - Read/write access to
~/.claude/projects/and~/.claude/backups/projects/
- Passwordless SSH access to remote machine
rsyncinstalled on both machines
- Source
claude-context.shpath in.zshrcor.bashrcetc.