Currently Available: Need a skilled Software Developer for your next project?
Categories
Claude Code

Migrate Claude Code Sessions to a New Computer

Moving to a new computer or switching from WSL to native Linux? Here's how to preserve all your Claude Code conversation history and make it accessible on your new setup.

Why You Can't Just Copy

After copying your .claude folder to your new computer, you might find that some sessions appear in your history but throw errors when you try to resume them:

No conversation found with session ID: abc123-def456-...

This happens because Claude Code organizes conversation transcripts by project path, and your paths have changed.

Understanding Claude Code's Storage Structure

Claude Code stores your conversations in a specific directory structure:

~/.claude/
├── history.jsonl              # List of all sessions (metadata only)
├── projects/                  # Actual conversation transcripts
│   ├── -home-olduser-project-a/
│   │   ├── session-id-1.jsonl
│   │   └── session-id-2.jsonl
│   └── -home-newuser-project-a/
│       └── session-id-3.jsonl
├── session-env/               # Session environment data
├── todos/                     # Todo lists per session
└── ...

When you move from one machine to another, your username or project paths might change:

  • Old machine: /home/olduser/project-a~/.claude/projects/-home-olduser-project-a/
  • New machine: /home/newuser/project-a~/.claude/projects/-home-newuser-project-a/

Sessions from your old machine exist in the old path structure, making them invisible to Claude Code on your new machine.

The Solution: Copy Sessions to New Paths

Step 1: Identify Your Path Mapping

First, check what project directories exist:

ls ~/.claude/projects/

You'll see directories like:

  • -home-olduser-project-a (from your old computer)
  • -home-newuser-project-a (from your new computer)

Step 2: Copy Session Files

Copy all session transcripts from old paths to new paths without overwriting existing files:

cd ~/.claude/projects

# For each project, copy old sessions to new location
# The -n flag prevents overwriting existing files
cp -n ./-home-olduser-project-a/*.jsonl ./-home-newuser-project-a/
cp -n ./-home-olduser-project-b/*.jsonl ./-home-newuser-project-b/
cp -n ./-home-olduser-project-c/*.jsonl ./-home-newuser-project-c/

Important: Use the -n flag (or --no-clobber) to preserve any new sessions you've already created on your new computer.

Step 3: Verify the Migration

Count sessions before and after:

# Count old sessions
find ~/.claude/projects/-home-olduser-* -name "*.jsonl" -not -name "agent-*" | wc -l

# Count new sessions (should include both old and new)
find ~/.claude/projects/-home-newuser-* -name "*.jsonl" -not -name "agent-*" | wc -l

The second number should be roughly the sum of old sessions + any new sessions you created.

Step 4: Test Session Resumption

Try resuming one of your old sessions:

claude resume abc123-def456-...

It should now work! 🎉

Complete Migration Checklist

When moving Claude Code to a new computer:

  • [ ] Copy entire ~/.claude/ directory to new computer
  • [ ] Identify old vs new project path structures
  • [ ] Copy session files from old paths to new paths
  • [ ] Verify session counts
  • [ ] Test resuming an old session
  • [ ] Clean up old path directories (optional)

Automation Script

If you have many projects, create a script to automate the migration:

#!/bin/bash

# Map old paths to new paths
declare -A path_mapping
path_mapping["-home-olduser-project-a"]="-home-newuser-project-a"
path_mapping["-home-olduser-project-b"]="-home-newuser-project-b"
path_mapping["-home-olduser-project-c"]="-home-newuser-project-c"

cd ~/.claude/projects

for old_dir in "${!path_mapping[@]}"; do
    new_dir="${path_mapping[$old_dir]}"

    if [ -d "$old_dir" ]; then
        echo "Migrating: $old_dir -> $new_dir"
        mkdir -p "$new_dir"
        cp -n "$old_dir"/*.jsonl "$new_dir/" 2>/dev/null || true
    fi
done

echo "Migration complete!"

Save this as migrate-claude-sessions.sh, make it executable, and run it:

chmod +x migrate-claude-sessions.sh
./migrate-claude-sessions.sh

Common Scenarios

WSL to Native Linux

Moving from Windows WSL to native Linux often changes your username:

  • WSL: /home/ubuntu/projects/
  • Native Linux: /home/john/projects/

Follow the steps above to copy from -home-ubuntu-* to -home-john-*.

Different Username on New Machine

Your old computer used alice, new one uses alice-work:

  • Old: /home/alice/my-app/
  • New: /home/alice-work/my-app/

Copy from -home-alice-my-app/ to -home-alice-work-my-app/.

Keeping Old Sessions as Backup

Instead of copying, you can create symbolic links:

cd ~/.claude/projects
ln -s ./-home-olduser-project-a/* ./-home-newuser-project-a/

However, this may cause issues if you create new sessions, so copying is recommended.

Troubleshooting

"No such file or directory" when copying

The source directory might not exist. List available directories:

ls -la ~/.claude/projects/

Some sessions still don't work

Check if the session file actually exists in the new location:

find ~/.claude/projects -name "your-session-id.jsonl"

If it only appears in the old directory, repeat the copy command for that specific project.

Too many project directories

Claude Code creates a directory for every working directory you've used. You might have:

  • -home-olduser (home directory sessions)
  • -home-olduser-projects-app1
  • -home-olduser-projects-app2
  • etc.

Map each one individually to its new counterpart.

Why This Happens

Claude Code uses the working directory path as a unique identifier for organizing conversations. This design allows you to:

  • Work on multiple projects simultaneously
  • Keep conversations contextual to specific projects
  • Maintain separate conversation histories per project

However, it means that path changes require manual migration of session files.

After Migration

Once migration is complete, you can optionally:

  1. Archive old directories: Move them outside .claude/projects/ for safekeeping
  2. Leave them: They don't hurt anything, just take up disk space
  3. Delete them: Only after confirming all sessions work

I recommend keeping them for a while until you're certain everything works correctly.

Real-World Example

Here's what a typical migration looks like:

Before migration:

  • Old computer sessions: 179 (in -home-olduser-* directories)
  • New computer sessions: 131 (in -home-newuser-* directories)
  • Accessible sessions on new computer: 131

After migration:

  • Total sessions in new paths: 278
  • Accessible sessions on new computer: 278 ✅

All conversation history from both computers is now accessible!

Conclusion

Migrating Claude Code sessions between computers is straightforward once you understand the path-based storage structure. The key is copying session files from old project paths to new ones while preserving any sessions you've already created on the new machine.

With this guide, you can maintain years of valuable Claude Code conversation history across computer migrations, OS changes, or username updates.

Pro tip: Consider backing up your entire ~/.claude/ directory regularly to avoid losing conversation history. It's a treasure trove of problem-solving context and development history!

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *