Skip to content

Rtiming/claude-local-session-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Local Session Sync

Stop losing your Claude sessions when you switch accounts.

Merge Claude Code & Cowork local history across subscription and API-routing logins — your sessions, all in one place.

MIT License macOS Bash Automatic backups

简体中文 · Quick Start · How It Works · Scripts · Warning


What Is This?

If you switch between Claude's official subscription and third-party API routing (e.g. via ccswitch / CC Switch), you may notice that your local agent-mode sessions (Cowork) and Code-mode sessions (Claude Code) are isolated per account. Each provider login creates a different account ID under ~/Library/Application Support/Claude/, so the app only shows sessions belonging to the currently logged-in account. Your other sessions appear to "vanish" — but they are still on disk, just in a different directory.

This toolkit solves that problem by:

  1. Step 1 (Verify) — Safely copy one session across accounts to confirm cross-account loading works.
  2. Step 2 (Bidirectional Sync) — One-time sync of all historical sessions in both directions.
  3. Real-time Sync (Symlink) — Permanently link the session directories so new sessions automatically appear on both sides.

Scope limit: This only handles local sessions (Cowork local-agent-mode and Claude Code CLI sessions). Cloud-based web chats are stored server-side and cannot be merged locally.


Table of Contents


Prerequisites

  • macOS (tested on macOS 14+)
  • Claude Desktop app installed
  • bash 4+ and standard Unix utilities (cp, mv, ln, find, pgrep)
  • You already use ccswitch or manually switch between subscription and third-party routing
  • Both provider modes have generated at least one local session each (so the directory structure exists)

Quick Start

1. Locate Your Account Directories

Claude stores local sessions at:

~/Library/Application Support/Claude/
├── local-agent-mode-sessions/
│   ├── <SUBSCRIPTION_ACCOUNT_UUID>/
│   │   └── <ORG_ID>/
│   │       └── local_xxxxxx.json
│   └── <ROUTE_ACCOUNT_UUID>/
│       └── <ORG_ID>/
│           └── local_xxxxxx.json
└── claude-code-sessions/
    ├── <SUBSCRIPTION_ACCOUNT_UUID>/
    │   └── <ORG_ID>/
    │       └── local_xxxxxx.json
    └── <ROUTE_ACCOUNT_UUID>/
        └── <ORG_ID>/
            └── local_xxxxxx.json

To find your UUIDs, run:

ls ~/Library/Application\ Support/Claude/local-agent-mode-sessions/
ls ~/Library/Application\ Support/Claude/claude-code-sessions/

You will see one or more UUID directories. The one that appears when you are on subscription mode is your subscription account; the one that appears on routing mode is your route account.

2. Edit the Script Configs

All scripts read variables from the top of each file. Open the scripts and replace the placeholder UUIDs with your actual values:

# In scripts/step1-verify.sh, scripts/step2-bidirectional.sh, scripts/realtime-symlink.sh
SUB_ACCOUNT="<YOUR_SUBSCRIPTION_ACCOUNT_UUID>"
SUB_ORG="<YOUR_SUBSCRIPTION_ORG_ID>"
RT_ACCOUNT="<YOUR_ROUTE_ACCOUNT_UUID>"
RT_ORG="<YOUR_ROUTE_ORG_ID>"

3. Run Step 1 — Verify

Before running: Fully quit Claude Desktop (Cmd+Q). The app must not be running.

bash scripts/step1-verify.sh

This will:

  • Back up your entire local-agent-mode-sessions directory
  • Copy one session from your route account to your subscription account
  • Print instructions to reopen Claude and check if the copied session appears

If the session appears and opens correctly, the sync approach works on your setup.

4. Run Step 2 — Bidirectional Sync

After confirming Step 1 works:

bash scripts/step2-bidirectional.sh

This copies all historical sessions from both accounts into each other. After running, both provider modes will see the full session history.

Note: This is a one-time sync. New sessions created after this point will still be isolated to the account that created them.

5. (Optional) Real-time Sync — Symlink

For a permanent solution where new sessions are automatically shared:

bash scripts/realtime-symlink.sh

This replaces the route-account's org directories with symbolic links pointing to the subscription account's directories. From then on, both accounts read and write the same session data.


How It Works

Account Isolation

Claude Desktop isolates sessions by account UUID:

local-agent-mode-sessions/<ACCOUNT_UUID>/<ORG_ID>/local_*.json

When you log in with different providers, the account UUID changes, so the app looks in a different subdirectory and your previous sessions are "invisible."

The Session File Format

Local session files (local_*.json) do not contain cryptographic ownership checks. The account UUID only appears inside path snapshots (e.g. cwd). This means a session file moved from one account directory to another will generally load correctly, because the app relies on directory structure for ownership, not file contents.

Sync Strategies

Strategy Persistence Safety Use Case
Step 1 Verify One-time copy Safest (1 file, full backup) Confirm feasibility
Step 2 Bidirectional One-time copy Safe (full backup) Migrate history
Real-time Symlink Permanent Medium (backup + symlink) Ongoing dual-mode use

Scripts

scripts/step1-verify.sh

Minimum viable test. Copies a single session from route → subscription. Includes full backup and printed rollback command.

Requires editing: SUB_ACCOUNT, SUB_ORG, RT_ACCOUNT, RT_ORG at the top of the file.

scripts/step2-bidirectional.sh

One-time bidirectional sync of all existing sessions. Copies route → subscription and subscription → route. Safe, non-destructive (skips existing files).

Requires editing: Same UUIDs as Step 1.

scripts/realtime-symlink.sh

Permanent solution using symbolic links. Merges existing files first, then replaces route-account directories with symlinks to subscription-account directories.

Requires editing:

  • CODE_TRUTH — path to your subscription account's Code sessions
  • WORK_TRUTH — path to your subscription account's Cowork sessions
  • CODE_LINKS — array of route-account Code session paths to replace with symlinks
  • WORK_LINKS — array of route-account Cowork session paths to replace with symlinks

scripts/legacy-merge.sh (Deprecated)

An earlier attempt that assumed routing mode used a separate Claude-3p data directory. This premise was incorrect for modern ccswitch. Kept for reference only.


Rollback

Every script prints an exact rollback command at the end. General pattern:

# If you used step1 or step2
rm -rf "$HOME/Library/Application Support/Claude/local-agent-mode-sessions"
mv "$HOME/Library/Application Support/Claude/local-agent-mode-sessions.backup-<TIMESTAMP>" \
   "$HOME/Library/Application Support/Claude/local-agent-mode-sessions"

# If you used realtime symlink
rm -rf "$HOME/Library/Application Support/Claude/claude-code-sessions"
mv "$HOME/Library/Application Support/Claude/claude-code-sessions.bak-<TIMESTAMP>" \
   "$HOME/Library/Application Support/Claude/claude-code-sessions"

Always fully quit Claude Desktop before rolling back.


Warning

⚠️ Read this before using any script.

  1. Quit Claude first. All scripts check for Claude.app and refuse to run if it is active. Concurrent reads/writes may corrupt session data.
  2. Backups are automatic. Each script creates a timestamped backup, but if you have gigabytes of session data, backups will take time and disk space.
  3. Symlinks are permanent. The real-time symlink script modifies your Claude data directory structure. If you later uninstall ccswitch or change provider configurations, you may need to manually rebuild the directory tree.
  4. Session metadata is not sanitized. When you open a cross-account session, the cwd and username fields inside the JSON still reflect the original account. In practice this does not prevent loading, but be aware the metadata is not "translated."
  5. No warranty. These scripts operate on your personal application data. Review the code before running. The authors are not responsible for lost sessions.

FAQ

Q: Will this sync my cloud chat history? A: No. Only local agent-mode (Cowork) and Claude Code sessions are stored locally. Regular web chats live on Anthropic's servers.

Q: Can I use this on Windows? A: Not directly. The scripts use macOS-specific paths (~/Library/Application Support). Windows stores Claude data in %APPDATA%\Claude. You could port the logic but the paths and symlink behavior differ.

Q: What happens if Anthropic changes the directory structure? A: These scripts target the current structure as of mid-2026. If Claude Desktop changes its on-disk layout, the scripts may need updates.

Q: I see claude-code-sessions and local-agent-mode-sessions. Which is which? A: claude-code-sessions = Code tab (terminal agent, workspace-enabled). local-agent-mode-sessions = Cowork tab (local agent with chat UI).


License

MIT

About

Merge Claude Code & Cowork local sessions across subscription and API-routing accounts on macOS. Automatic backups, safe rollback.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages