Skip to content

Instantly share code, notes, and snippets.

@praeclarum
Last active April 30, 2026 03:33
Show Gist options
  • Select an option

  • Save praeclarum/7426f23e44b0e3707fa83851a0d285ea to your computer and use it in GitHub Desktop.

Select an option

Save praeclarum/7426f23e44b0e3707fa83851a0d285ea to your computer and use it in GitHub Desktop.
Script to copy VS Code AI chats to a backups directory
#!/usr/bin/env bash
# Copy all VS Code chatSessions folders to a backup location, preserving timestamps.
set -euo pipefail
SRC="$HOME/Library/Application Support/Code/User/workspaceStorage"
DEST="$HOME/Dropbox/Backups/VSCodeChatSessions"
if [ ! -d "$SRC" ]; then
echo "Source directory not found: $SRC" >&2
exit 1
fi
mkdir -p "$DEST"
file_count=0
ws_count=0
while IFS= read -r -d '' session_dir; do
ws_count=$((ws_count + 1))
# -p preserves mode, ownership (where allowed), and timestamps.
# On macOS, `cp -p` preserves mtime/atime.
while IFS= read -r -d '' f; do
cp -p "$f" "$DEST/"
file_count=$((file_count + 1))
done < <(find "$session_dir" -mindepth 1 -maxdepth 1 -type f -print0)
done < <(find "$SRC" -type d -name chatSessions -print0)
echo "Backed up $file_count file(s) from $ws_count workspace(s) to: $DEST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment