Dev
How I Brought My Claude Code Chat History With Me to a New Linux Install
November 15, 2026 · 13 min read
I recently moved from Ubuntu to Fedora KDE Plasma. Before wiping the disk, I copied my ~/.claude folder to an external drive. That folder holds everything Claude Code knows about my past work: every conversation, per-project memories, custom skills and settings.
After installing Fedora and Claude Code, I copied the backup back… and none of my old chats showed up. Running /resume inside a project only listed that day’s sessions.
This post explains why that happens, how Claude Code organizes its history on disk, and the careful, step-by-step way I restored everything so each project shows its own past chats again. Personal details like usernames, project names and accounts are replaced with placeholders like olduser, newuser and my-project.
Table of Contents
- The Setup
- How Claude Code Stores Your History
- Why Copying the Backup Back Didn’t Work
- What Is Possible and What Is Not
- What to Be Cautious About
- The Restore, Step by Step
- Moving Projects to New Locations
- Cleaning Up Afterwards
- How This Is Helpful
- What I Learned
- Quick Checklist
The Setup
- Old system: Ubuntu, username
olduser, home at/home/olduser - New system: Fedora KDE Plasma, username
newuser, home at/home/newuser - Backup: a full copy of the old
~/.claudedirectory (around 800 MB, mostly chat transcripts) - Goal: open any project on the new machine, run
/resume, and see that project’s old conversations, even for projects I haven’t cloned back yet
The username change turns out to matter a lot. More on that below.
How Claude Code Stores Your History
Everything lives in ~/.claude/ (plus one config file, ~/.claude.json, next to it). These are the parts that matter:
| Path | What it is | Worth restoring? |
|---|---|---|
projects/ |
One folder per project, holding every chat as a .jsonl file plus a memory/ folder |
Yes, this is the main thing |
history.jsonl |
Your prompt history (what the up-arrow scrolls through) | Yes |
file-history/ |
Snapshots of files Claude edited, used by rewind/checkpoints | Yes |
skills/ |
Custom skills you created or installed | Yes |
plans/ |
Saved plan-mode plans | Optional |
paste-cache/ |
Large text you pasted, referenced from prompt history | Optional |
settings.json |
Your preferences, plugins, voice and so on | Merge selectively |
.credentials.json |
Your login token | No. Log in fresh |
sessions/, daemon/, jobs/, state/, ide/ |
Runtime state from the old machine | No |
backups/, ~/.claude.json |
Machine-specific config and its backups | No, let it rebuild |
The key detail: project folders are named after paths
Claude Code doesn’t keep a “project database”. It finds a project’s history by taking the full path of the directory you launched it in and turning it into a folder name. Every character that isn’t a letter or digit becomes a dash:
/home/olduser/Documents/my-project
↓
~/.claude/projects/-home-olduser-Documents-my-project/
When you run claude --resume in /home/olduser/Documents/my-project, it looks in exactly that folder. No match, no history.
Inside each .jsonl transcript, every message also records a "cwd" field with the real working directory, for example "cwd":"/home/olduser/Documents/my-project".
Why Copying the Backup Back Didn’t Work
My new username was different, so my project paths changed:
Old: /home/olduser/Documents/my-project → -home-olduser-Documents-my-project
New: /home/newuser/Documents/my-project → -home-newuser-Documents-my-project
Claude on the new machine looks for -home-newuser-..., but my backup only had -home-olduser-... folders. The history was all there; Claude just didn’t know it belonged to my projects.
If your username and folder layout are identical on the new system, you can usually copy the backup back as-is (after reading the cautions below). The rest of this post is for when something changed.
What Is Possible and What Is Not
✅ Possible
- Restoring history for projects that don’t exist yet. The history folder just waits. When you later clone or create the project at the matching path,
/resumeshows its old chats. - Merging old and new chats. Each chat is its own file with a unique ID, so old chats can be added next to ones you created on the new system without conflict.
- Moving a project’s history to a different location, for example from
~/Documents/xto~/Music/x, by renaming its folder and updating paths inside the files. - Restoring per-project memories, custom skills, prompt history, checkpoints and most settings.
- Choosing what to restore. You can skip old experiments and throwaway sessions.
❌ Not possible (or not worth it)
- Reusing old login credentials. Just log in again; copying tokens between machines is a bad idea anyway.
- History following a project automatically. It’s tied to the exact path. If you move a project folder later, you need to rename its history folder again.
- Reliably reconstructing a path from the folder name alone. The encoding is lossy:
my_project,my projectandmy-projectall becomemy-project. Check the"cwd"field inside the transcripts to see the real path. - Restoring temporary-directory sessions in a useful way. Sessions started in
/tmp/...scratch folders point at paths that no longer exist. - Carrying runtime state over. Background daemons, running jobs and IDE connections belong to the old machine.
What to Be Cautious About
These are the things that can quietly cost you data. Read this section even if you skip everything else.
1. Automatic cleanup can delete your old chats
Claude Code deletes transcripts older than a set number of days when it starts. The default is 30 days. My old config had raised it, but my fresh install hadn’t.
If you copy months of history into a fresh install, the next launch can delete everything older than 30 days.
Fix: set this in ~/.claude/settings.json before copying any history in:
{
"cleanupPeriodDays": 3650
}
2. Back up the new install before touching it
Even a fresh install has your login and maybe a few new chats. Take a snapshot first:
cd ~ && tar czf ~/claude-pre-restore.tar.gz .claude .claude.json
If anything goes wrong, you can extract it and you’re back where you started.
3. Never overwrite, only add
If you’ve already used Claude on the new system, some project folders may exist on both sides. Use no-clobber copies (cp -an) so existing files are never replaced. Since chat files have unique names, merging just puts both sets side by side.
4. Preserve timestamps
/resume sorts sessions by time, and cleanup uses file age. A naive sed -i sets every file’s modified time to “now”, which scrambles the order. Use cp -a to keep timestamps when copying, and restore the original time after editing a file (shown below).
5. Validate after editing
Each line of a .jsonl file is one JSON object. After a find-and-replace, parse every line to make sure you didn’t break anything. In my case, one line was already broken in the original backup, so it’s worth comparing against the source before blaming your edit.
6. Be careful what you replace
Only replace path-shaped strings such as /home/olduser and -home-olduser. Your old username may appear elsewhere (git identity, terminal prompts in pasted output, usernames on websites), and those should stay as they are.
7. Don’t restore secrets or machine state
Skip .credentials.json, daemon keys and session/runtime folders. Also check old settings.json entries before merging; some, like environment descriptions or trusted-repo notes, can contain old absolute paths.
8. Moving actual project folders is a bigger step
Renaming history folders is easy to undo. Moving your real project directories affects other tools too (IDEs, scripts, virtualenvs with hard-coded paths). Do it on purpose, one at a time.
The Restore, Step by Step
Examples assume the backup is at ~/Downloads/claude-backup, with olduser → newuser. Adjust to match your setup.
Step 0: Look before you leap
List each project folder, how many chats it has and its real path:
cd ~/Downloads/claude-backup
for d in projects/*/; do
n=$(ls "$d"*.jsonl 2>/dev/null | wc -l)
cwd=$(grep -ho '"cwd":"[^"]*"' "$d"*.jsonl 2>/dev/null | head -1)
echo "$n | $d | $cwd"
done
This tells you which projects matter, which are empty (some contain only a memory/ folder) and where each actually lived.
Step 1: Snapshot the current install
cd ~ && tar czf ~/claude-pre-restore.tar.gz .claude .claude.json
Step 2: Raise the cleanup period
Add "cleanupPeriodDays": 3650 to ~/.claude/settings.json, merging it in rather than replacing the file. A small Python one-off is safest:
python3 -c '
import json, os
p = os.path.expanduser("~/.claude/settings.json")
s = json.load(open(p))
s["cleanupPeriodDays"] = 3650
json.dump(s, open(p, "w"), indent=2)
'
Step 3: Stage the renamed projects in a scratch folder
Never edit the backup directly; work on a copy:
SRC=~/Downloads/claude-backup/projects
STAGE=~/claude-stage
mkdir -p "$STAGE"
for d in "$SRC"/-home-olduser-Documents-*; do
b=$(basename "$d")
cp -a "$d" "$STAGE/${b/-home-olduser-/-home-newuser-}"
done
Step 4: Fix paths inside the transcripts, keeping timestamps
find "$STAGE" -name '*.jsonl' | while read -r f; do
touch -r "$f" "$f.ts" # remember original time
sed -i -e 's#/home/olduser#/home/newuser#g' \
-e 's#-home-olduser#-home-newuser#g' "$f"
touch -r "$f.ts" "$f"; rm "$f.ts" # put the time back
done
Step 5: Validate every line
python3 - "$STAGE" <<'EOF'
import sys, os, json
bad = total = 0
for root, _, files in os.walk(sys.argv[1]):
for f in files:
if f.endswith(".jsonl"):
for line in open(os.path.join(root, f), encoding="utf-8", errors="replace"):
if line.strip():
total += 1
try: json.loads(line)
except Exception: bad += 1
print("lines:", total, "bad:", bad)
EOF
If you see bad lines, run the same check on the original backup. If the count matches, the damage was already there; Claude simply skips lines it can’t read.
Step 6: Merge into the live folder without overwriting
cp -an "$STAGE"/. ~/.claude/projects/
Step 7: Restore the supporting pieces
B=~/Downloads/claude-backup; C=~/.claude
cp -an $B/file-history/. $C/file-history/
cp -an $B/plans/. $C/plans/
cp -an $B/paste-cache/. $C/paste-cache/
cp -an $B/skills/<your-custom-skill> $C/skills/ # repeat per skill
Merge prompt history with old entries first and paths fixed:
sed 's#/home/olduser#/home/newuser#g' $B/history.jsonl > /tmp/history.new
cat $C/history.jsonl >> /tmp/history.new
# validate it like in Step 5, then:
cp /tmp/history.new $C/history.jsonl && chmod 600 $C/history.jsonl
Step 8: Merge settings selectively
Copy over only the keys you want (plugins, plugin marketplaces, voice, notifications) instead of replacing the whole file. Plugins download on the next start; if one doesn’t, install it again with /plugin.
Step 9: Verify
Check the cwd values in the restored folders. They should all point at the new home:
cd ~/.claude/projects
for d in -home-newuser-*; do
echo "$d -> $(grep -ho '"cwd":"[^"]*"' -- "$d"/*.jsonl 2>/dev/null | sort | uniq -c | sort -rn | head -1)"
done
Then open a project and run claude --resume. 🎉
Moving Projects to New Locations
A new OS is a good time to reorganize. I decided some projects would live in a different top-level folder than before. For each one, the history folder name and the paths inside it need to change together:
P=~/.claude/projects
name=my-project
mv "$P/-home-newuser-Documents-$name" "$P/-home-newuser-Music-$name"
# then, inside that folder, rewrite with the same timestamp-safe loop:
# /home/newuser/Documents/my-project → /home/newuser/Music/my-project
# -home-newuser-Documents-my-project → -home-newuser-Music-my-project
Also update the "project" field in history.jsonl so the up-arrow history follows the project.
Notes from doing this:
- Names are exact. Capitals, underscores and spaces in the real folder name must match where you put the project later.
- Spaces turn into dashes. A project in a folder like
~/Local Sites/apphas history under...-Local-Sites-app. - Watch for duplicates. I had the same session recorded under two different paths because I had once moved the project. Pick one location instead of merging both.
- Trust prompts reappear. The first launch in a moved folder asks you to trust it again. That’s expected.
It’s also a good time to leave things behind. I skipped a handful of old experiments and sessions started from my home folder. Nothing forces you to restore everything.
Cleaning Up Afterwards
Once you’ve opened a few projects and seen your history:
- Delete the staging folder. Everything in it has already been merged.
- Delete the pre-restore snapshot, once you’re sure you won’t need to undo.
- Delete the original backup last, deliberately. It may be the only copy of chats you chose not to restore, and it contains your old login token. Keep it until you’re sure, then delete it yourself.
How This Is Helpful
Losing chat history doesn’t sound dramatic, but in practice that history is where a lot of project knowledge lives:
- Context you’d otherwise rebuild. Why a design decision was made, which approaches failed, what a strange error turned out to be.
- Per-project memories. Notes Claude saved about each project’s conventions and goals, which shape future sessions.
- Resumable work. Unfinished tasks can be picked up with
/resumeinstead of re-explaining everything. - Checkpoints. File snapshots that let you rewind edits made in earlier sessions.
- Your tooling. Custom skills and plugin setup that took time to build.
Restoring it properly made the new OS feel like the same workspace on a fresh system, not a fresh start.
What I Learned
- The path is the project ID. Once you know that, everything else follows: why history disappears, how to fix it, and why moving folders later needs care.
- Look at the default settings before importing data. The 30-day cleanup default could have silently deleted months of history on the first launch.
- Stage, validate, merge. Never edit the backup or the live folder directly. Make a copy, change it, check it, then add it in without overwriting.
- Timestamps are data. Keeping file modification times intact keeps your session list in the right order.
- Folder names aren’t reliable; the content is. The path encoding loses information, but the
cwdfield inside each transcript tells you exactly where a session ran. - Some damage predates you. When validation fails, compare against the original before assuming your edit caused it.
- Restore selectively. Credentials, runtime state and machine-specific config should stay behind. Old experiments can too.
- Make destructive steps deliberate. Take a snapshot first, and decide on deletions one at a time, in order from least to most important.
Quick Checklist
- Back up
~/.claude(and~/.claude.json) before reinstalling the OS - On the new system, install Claude Code and log in fresh
- Snapshot the new
~/.claudebefore changing anything - Set
cleanupPeriodDayshigh before copying history in - List the backup’s projects and their real
cwdpaths - Copy project folders to a staging area, renamed for the new paths
- Rewrite paths inside
.jsonlfiles, keeping timestamps - Validate every JSON line (and compare with the original if anything fails)
- Merge into
~/.claude/projects/with no-clobber copies - Restore
file-history/,skills/,plans/,paste-cache/and the mergedhistory.jsonl - Merge settings key by key; skip credentials and runtime folders
- Remap any projects that are moving to a new location
- Verify with
claude --resumeinside a few projects - Clean up: staging folder → snapshot → original backup (last, deliberately)
Fair warning: these are internal storage details of Claude Code as they work today, not an official migration feature. Folder layouts can change between versions, so look at your own ~/.claude before running any of the commands above.