AI engineering

Claude Code on Multiple Computers: What to Sync

What I commit, merge, and keep local to run Claude Code on three machines, macOS and Linux, x86 and Apple Silicon. Plus the guard hook I forgot to track.

In this post
  1. Why not just symlink all of ~/.claude to a repo?
  2. The global CLAUDE.md is a symlink
  3. settings.json is merged, never linked
  4. What goes in each project’s .claude folder
  5. Memory: where the machines actually share state
  6. What stays on each machine
  7. The one thing that broke my rule
  8. A checklist for your own setup

TL;DR: I run Claude Code on three machines, macOS and Omarchy Linux, x86 and Apple Silicon. The rule: everything I need to work travels by git, and nothing important may live only in one machine’s ~/.claude. Each piece of config falls into one of four buckets.

Bucket What goes in it How it moves
Symlink Global CLAUDE.md, hook scripts, statusline Public dotfiles repo, linked by install.sh
Merge ~/.claude/settings.json A small script merges a tracked base file into the live one
Commit per repo .claude/settings.json, agents/, hooks/, skills/ Lives in each project’s own git history
Never sync Credentials, settings.local.json, per-machine permissions Stays on the machine

Copying files is the easy part. Deciding which files should be copied at all took me longer. Some of what Claude Code keeps on disk is yours to share across machines. Some of it is written by Claude Code itself while you work, and some of it is a secret. If you sync the whole folder you get all three.

This is the split I landed on, and the hook I found while writing this that broke it.

Because Claude Code writes to settings.json while you use it. Run /model and it saves your choice there. The settings docs say the same: it writes ~/.claude/settings.json the first time you change an option in /config, and /model saves your pick as the default for new sessions.

If that file is a symlink into a git repo, every toggle becomes an uncommitted change in your dotfiles. I keep my dotfiles in a public repo. A symlinked settings.json would put my plugin list, my model choices and whatever else gets written there into the diff, and sooner or later into a commit I didn’t read closely.

So the dotfiles repo splits Claude Code’s files by who writes them:

  • Files I write and Claude Code only reads get symlinked. That is the global CLAUDE.md, hook scripts and a statusline script.
  • Files Claude Code writes get merged.
  • Files that are secrets or per-machine state never go in.

install.sh links shared/ on every machine plus one of macos/ or linux/, picked by uname -s. Almost all of ~/.claude sits in shared/.

~/.claude/CLAUDE.md points at shared/claude/CLAUDE.md in the dotfiles repo. Edit it on any machine, commit, pull on the others, done. There is no copy to drift.

One thing install.sh does that I’d recommend copying. On a machine that already has a real ~/.claude/CLAUDE.md, a naive ln -s either fails or overwrites it. My script moves the real file aside with a timestamp (CLAUDE.md.pre-dotfiles-20261028T...) and prints a reminder to diff it for lines worth keeping. Nothing gets deleted. The old file on my Mac had imports pointing at absolute /Users/jsmith/... paths. Those resolved on no Linux machine, and Claude Code dropped the imports with no complaint. The shared copy imports through ~/ instead, so the same line works on all three.

The global file stays short. Most of its content is @import lines pointing at small rule files in a private markdown vault that I also keep in git: a model routing table, a few reasoning rules, a rule about /tmp. I wrote about the routing table in the one file where your model names live, and about the vault in AIOS. I won’t retell either here. For sync, the shape is the point: the public repo holds the pointers and the private repo holds the content. Clone both on a new machine and every @import resolves.

settings.json is merged, never linked

Everything in settings.json that I want on every machine lives in claude/settings.base.json in the dotfiles repo. A script, claude/setup.sh, merges that file into the live ~/.claude/settings.json. The header comment in the script states the rules:

  • settings.base.json wins on the keys it names.
  • Every other key in the live file passes through untouched.
  • Nothing is ever deleted.

The merge is one jq call, jq -s '.[0] * .[1]', and before it replaces anything it saves a timestamped backup of the live file. If the result is identical to what’s already there, it says “already merged” and stops. So I run install.sh every time I pull, on any machine. It runs this merge and then my vault’s installer, which puts the vault’s own hooks back.

The base file names 14 keys: model, effort level, enabled plugins, marketplaces, permissions, hooks, status line and a few UI settings. The keys that show up only on one machine, or that Claude Code adds as I work, aren’t in the base, so they survive the merge.

The hook array gotcha

This one cost me real time. jq’s * operator merges objects recursively but replaces arrays. A hook event in settings.json (PreToolUse, PostToolUse, SessionStart) is an array. So when my base file defines PreToolUse, its array replaces whatever array was in the live file. Any hook another tool had added to that event is gone after the next merge, with no error.

My setup.sh comment blames Claude Code for this. It’s jq. Claude Code itself combines list keys like permissions.allow across settings files.

The fix is in the script and in a habit. The merge runs last, after the plugin and integration installers, so the base file’s hook arrays are the final word. And if a hook doesn’t show up after a re-run, the first place I look is whether it’s in settings.base.json. If you want a rundown of which hooks are worth having in that file, the four hooks I run on every project is that list, and my plugin stack covers what the enabledPlugins key is carrying.

Skills, from a plain text file

Third-party skills don’t get copied. claude/skills.tsv lists them, one per line, as a GitHub repo and a skill name separated by a tab. It has 15 lines. setup.sh reads the file and installs each one. A new machine gets the same skills as the old ones by running the script, and I never have to carry a folder of someone else’s code around in my own repo.

What goes in each project’s .claude folder

Per-repo config is simpler, because the repo already travels by git. What I commit in each project:

  • .claude/settings.json (shared hooks, permissions, plugins for that project)
  • .claude/agents/
  • .claude/hooks/
  • .claude/skills/

What I ignore: settings.local.json, worktrees/, and Python’s __pycache__ under hooks. This is the actual block from this site’s .gitignore:

/.claude/*
!/.claude/settings.json
!/.claude/agents/
!/.claude/hooks/
!/.claude/skills/
/.claude/hooks/__pycache__/

The first line ignores everything under .claude/. The next four re-include the pieces that make up the project’s working setup. This site’s content pipeline (drafting agent, editorial reviewer, SEO check hook) lives there, so any of my three machines can draft, check and ship a post. Ignore all, then un-ignore specific paths. Git won’t let you re-include a file when its parent directory is excluded, which is why the pattern is /.claude/* and not /.claude/.

Two rules for what goes in those tracked files. No secrets, and no absolute /Users/... paths, since the same repo gets checked out on a Linux machine where that path doesn’t exist. Use $HOME or ~/ in anything a shell or an import will read.

The precedence is worth knowing, because it decides which file to put a setting in. Per the settings docs, the order from lowest to highest is user (~/.claude/settings.json), shared project (.claude/settings.json), then project local (.claude/settings.local.json). A key in the local file overrides the same key in the committed one, so a per-machine exception never needs a commit. The same docs say Claude Code adds settings.local.json to your global git excludes the first time it writes the file. I ignore it in the repo as well, because the file may have been created by hand, and then nothing excludes it for you.

Memory: where the machines actually share state

Claude Code’s auto memory, the notes it writes to itself about your corrections and preferences, defaults to a folder under ~/.claude/projects/ on each machine. Three machines means three separate sets of notes, and each machine slowly forgets what the others learned. Two accounts on one machine have the opposite problem: both logins share one brain by default.

I point all of them at the private vault instead, using the autoMemoryDirectory setting. The docs describe it as a way to store auto memory in a directory you choose. That moves memory into a git repo, so it syncs the same way my notes do. The longer argument for keeping memory outside any one tool is in building an AI memory that outlives any single agent.

Where I put the setting is the odd part. My vault installer has this comment: the setting is ignored in a committed .claude/settings.json. That is what I found when I wired it up in September, and it is why the installer writes the key into each repo’s untracked .claude/settings.local.json instead. The current memory docs say something different: that it is read from any settings scope, project included, once you’ve trusted the folder. I haven’t re-tested, so I’m leaving the installer as it is. The local file works either way.

The consequence is that this setting can’t travel with the repo. It has to be installed on each machine, once per repo. So the vault has an idempotent installer that writes it, dry run by default. The dotfiles install.sh calls it with --apply at the end, after cloning the vault if I pass the vault’s remote, so a fresh machine gets wired in one run.

What stays on each machine

Two things never go in either repo:

  1. Credentials and auth. Login state, tokens, API keys. Each machine signs in on its own, so revoking one doesn’t touch the others.
  2. settings.local.json. This is the per-machine layer. Standing approvals (“Yes, and don’t ask again”) end up here, and macOS and Omarchy don’t have the same commands installed, so I want each approval made on the machine it’s for.

Plugins sit in between. The list of enabled plugins is in my base file, so it syncs. The plugin files themselves are installed per machine by the script. I don’t commit them.

The one thing that broke my rule

While I was writing this, I checked each piece against the rule that nothing important lives on only one machine. One thing failed.

I have a guard hook, ~/.claude/hooks/no-heavy-tmp.sh. It’s a PreToolUse hook that blocks a command when it pairs an install, a clone or a worktree add with a path under /tmp. On Omarchy, /tmp is RAM, and at the time my machine had no swap, so a stray npm install there eats memory. I wrote the rule down in a vault file that every session imports. The hook that enforces the rule was a file in ~/.claude/hooks/, and I checked both repos: it wasn’t tracked in either one. It existed on one machine. Worse, it wasn’t registered there either. No PreToolUse entry pointed at it, because it was never in settings.base.json and a merge had replaced the array.

So the rule that explains the guard syncs everywhere, and the guard doesn’t. The fix is a few lines: put the script in claude/hooks/ in the dotfiles repo, where setup.sh already links the hook scripts that live there, and add it to PreToolUse in settings.base.json. Given the array behavior above, it has to go in the base file or the next merge drops it. I’ve now done both, and the hook blocks again.

Running the merge to pick it up showed the same bug from the other side. Two SessionStart hooks that a separate installer adds for my vault were not in the base file, and the merge dropped them. I restored settings.json from the backup the merge writes and added the one new entry by hand. If you merge settings with jq '.[0] * .[1]', every hook has to be in the base file or in an installer that runs after the merge. Anything else disappears on the next run.

A checklist for your own setup

If you’re setting this up for yourself, here is the order I’d go in:

  1. List what’s in your ~/.claude. Mark each item: you write it, Claude Code writes it, or it’s a secret.
  2. Symlink the first group from a dotfiles repo. Keep the global CLAUDE.md short and use ~/ in every path.
  3. Merge the second group from a base file. Decide up front that hook arrays in the base file replace the live ones.
  4. Leave the third group alone.
  5. In each project, commit the working setup in .claude/ and ignore the local layer.
  6. Point memory somewhere that syncs, and install that setting per machine.
  7. List the real ~/.claude folder against what your repos track. Anything only on the machine is a gap.

If you run Claude Code for a team, or you’re an AI startup trying to make a coding-agent setup reproducible for new hires, this is the same split with more people on the other end. I help with that on my consulting page.