Created
June 7, 2026 23:50
-
-
Save ajmeese7/934e88ad053cced15790457d6e8aec56 to your computer and use it in GitHub Desktop.
Store Claude Code's memory in version control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Point Claude Code's auto memory at the repo's committed memory directory. | |
| # | |
| # Claude stores per-project auto memory under ~/.claude/projects/<repo>/memory by | |
| # default, which lives outside the repo and does not travel across machines. This | |
| # repo commits its memory to .claude/memory instead. The official `autoMemoryDirectory` | |
| # setting (https://code.claude.com/docs/en/memory) redirects auto memory there. | |
| # | |
| # That setting must be an absolute path, so it cannot be committed (the repo path | |
| # differs per machine). This script writes it to the gitignored .claude/settings.local.json, | |
| # so each machine points at its own checkout while the facts stay version-controlled. | |
| # | |
| # Run once per machine after cloning. Idempotent. Takes effect next session, after | |
| # you accept the workspace-trust dialog for this folder (same gate as hooks). | |
| set -euo pipefail | |
| command -v jq >/dev/null || { echo "error: jq is required" >&2; exit 1; } | |
| repo_root="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)" | |
| dest="$repo_root/.claude/memory" | |
| settings_local="$repo_root/.claude/settings.local.json" | |
| if [ ! -d "$dest" ]; then | |
| echo "error: $dest does not exist (is the repo memory committed?)" >&2 | |
| exit 1 | |
| fi | |
| tmp="$(mktemp)" | |
| if [ -f "$settings_local" ]; then | |
| jq --arg d "$dest" '. + {autoMemoryDirectory: $d}' "$settings_local" > "$tmp" | |
| else | |
| jq -n --arg d "$dest" '{autoMemoryDirectory: $d}' > "$tmp" | |
| fi | |
| mv "$tmp" "$settings_local" | |
| echo "set autoMemoryDirectory -> $dest" | |
| echo "in $settings_local" | |
| echo "Restart Claude Code and accept the workspace-trust dialog for the setting to take effect." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment