Back up your Claude Code setup in a private repo

A private online copy of your Claude Code rules, skills and settings, with logins and keys left out.

1. Your .claude folder
  • Copy what you builtCLAUDE.md, settings, skills, rules, agents, commands, hooks
  • Leave behindLogin file, chat history, keys
2. Check, then your yes
  • Scan every file for secrets
  • Show you the file list
  • Push only after you say yes
3. Private repo online
  • claude-config-backup
PrivateNew laptop: clone it, copy files back, sign in again.
  1. From your .claude folder you copy only what you built: CLAUDE.md, settings, and the skills, rules, agents, commands and hooks folders. Your login file, chat history and keys stay behind.
  2. Before anything is saved, Claude scans every copied file for secrets, shows you the list of files, and pushes only after you say yes.
  3. The copy goes to a private repository online. On a new laptop you clone it, copy the files back and sign in again.
15 minNo code

You need

  • Claude Code
  • Git
  • A free GitHub account
  • The GitHub command-line tool (gh), signed in

Every rule, skill and setting you have built for Claude Code sits in one folder on one computer. If that laptop dies, all of it goes with it.

That folder is called .claude, in your home folder. On Windows it is C:\Users\YOUR-NAME\.claude. Anthropic's docs say it holds the files you write, such as CLAUDE.md, settings.json, skills and rules. They also say it holds what Claude Code writes while you work: your login credentials in .credentials.json and full conversation transcripts under projects/. The docs state that transcripts and prompt history are plaintext, with only file permissions protecting them. So you never copy the whole folder. You copy only the parts you built. On a Mac, your login is kept in the macOS Keychain, not in the .claude folder, so it is not in the folder you copy either way.

01 / 07

What goes in and what stays out

In (the parts you built):

  • CLAUDE.md and settings.json
  • the skills, rules, agents and commands folders
  • the hooks folder, if you have one

Out (never copy these):

  • .credentials.json, your login
  • projects/, your chat transcripts and Claude's auto-memory notes
  • history.jsonl, stats-cache.json, backups/, shell-snapshots/ and caches
  • any .env file and any file with a key, token or password in it
  • ~/.claude.json, which sits outside the folder

Claude's own memory notes live inside projects/, so they stay out. To keep some, type /memory, read them, and copy the ones you want into the repo by hand.

02 / 07

The backup prompt

You need Git, a free GitHub account, and the GitHub command-line tool gh signed in. You sign in yourself with gh auth login. This prompt never asks for your password. Open Claude Code and paste it.

Back up my Claude Code setup
I want to back up the parts of my Claude Code setup that I built, in a PRIVATE GitHub repository. Work in a NEW folder called claude-config-backup in my home folder (not inside .claude). Do not change anything inside my real .claude folder. Step 1. Copy these from my .claude folder into claude-config-backup, if they exist: CLAUDE.md, settings.json, and the folders skills, rules, agents, commands, hooks. Copy files only; do not move or delete the originals. Step 2. Create a .gitignore in claude-config-backup that excludes at least: .credentials.json, projects/, history.jsonl, stats-cache.json, cache/, backups/, shell-snapshots/, todos/, *.jsonl, .env, .env.*, *.key, *.pem, node_modules/, and anything named like secrets or credentials. Step 3. Before committing, scan every file you copied for things that look like secrets: API keys, tokens, passwords, long random strings, connection strings, private keys, lines like KEY=, TOKEN=, SECRET=, PASSWORD=. Show me the list of what you found with file name and line number (hide the values, show only the first 4 characters). If you find any, stop and ask me what to do. Do not commit until I answer. Also check settings.json for hard-coded keys in env or MCP server settings. Step 4. Run git init, make the first commit with the message "Initial backup of my Claude Code setup", and show me the list of files that will be in the commit BEFORE you commit. Wait for my yes. Step 5. Tell me the repo name and that it will be PRIVATE, and wait for my yes. Then create it with the GitHub CLI (gh repo create claude-config-backup --private --source . --push). Confirm with gh repo view that it says private. If gh is not signed in, tell me to run gh auth login myself and wait. Step 6. Write a short README.md in the repo explaining what is in it and how to restore it (clone the repo, copy the files into the new computer's .claude folder, restart Claude Code, sign in again and re-enter keys by hand). Step 7. Explain in plain words how I save a new version after I change something: I ask you "save my setup", and you copy changed files from .claude into the repo, show me the diff, and commit and push only after I say yes. Offer to write that as a skill called backup-setup. Rules: never copy credentials, chat history or keys. Never make the repo public. Never push without my yes. If anything is unclear, ask.

Download the ZIP for the prompt and the new-computer steps in one folder.

03 / 07

After it runs

  1. Open the repo page on GitHub and check the badge says Private.

  2. Scroll through the files. If you see a key or a password, see the section on a committed key below.

  3. From now on, after you change a rule or a skill, type "save my setup". That is your new version.

04 / 07

On a new laptop

  1. Install Claude Code, run it once so it creates its .claude folder, and sign in again. Your login is never in the backup.

  2. Sign in to GitHub yourself with gh auth login.

  3. Download the repo into a scratch folder, not into .claude: gh repo clone claude-config-backup.

  4. Ask Claude Code: "Compare the folder claude-config-backup with my .claude folder. Show me which files are new and which would overwrite an existing file. Copy over only what I approve. Never touch .credentials.json, projects/ or history.jsonl."

  5. Restart Claude Code, type /memory to confirm your CLAUDE.md is listed, and type a skill name to confirm it shows up.

  6. Put your keys back by hand from your password manager. Passwords and API keys never go in the repo. Reconnect any tools that need a login and check them with /mcp.

Paths in settings.json and hooks often mention your old username. Fix any that do.

05 / 07

If a key was committed by mistake

  1. Deleting the file in a new commit is not enough. The key stays in the history.

  2. Treat the key as leaked: make a new one at the service that issued it and turn off the old one.

  3. Ask Claude to help remove it from the repo history, or delete the repo and make a fresh one from clean files.

06 / 07

Test it safely

  1. Run the prompt and stop at step 4. Read the file list. It should hold only files you recognise, and no .credentials.json, projects/ or .env.

  2. Say yes. Check on GitHub that the repo is Private.

  3. Change one rule, type "save my setup", and confirm Claude shows you the difference before it pushes.

Where was this tested? The author ran steps 1 to 4 on a made-up home folder with a fake token planted in settings.json and decoy login, history and cache files. The secret scan stopped the run and showed only the first 4 characters, only the built parts were copied, and Claude waited for a yes before the commit. Not tested: creating the real GitHub repo, pushing, the README, the "save my setup" skill, and the new-laptop steps on a second computer. You still read the file list before you say yes.

Common mistakes

  1. Copying the whole folder. That includes your login and chat history in plain text.

  2. Making the repo public. Check the Private badge on the repo page.

  3. Committing a key. Read the scan results, and rotate any key that got in.

  4. Never saving a new version. A backup from last month will not have your newest skill.

Why a private repo and not a public one?

Your rules and skills may describe your business or contain details you would not publish. Private means only you can see it.

Where do my keys go?

They never go in the repo. Carry them to a new computer by hand from your password manager.

Does this back up Claude's memory notes?

No. They live inside the projects folder with your chat transcripts, which stays out. Copy the ones you want by hand.

Do I need to code?

No. You paste one prompt and read the list of files before you say yes.

Finish line

What to do next

  1. Run the prompt and read the file list before you say yes.

  2. Check the repo says Private on GitHub.

  3. Next time you change a skill, type "save my setup".

Back to all the free guides. Two that pair well with this one: undo a Claude Code mistake and Claude Code hooks that block pushes, deletes and secrets.

You reached the end of the guide