with one click
brain-surgery
// Externalize Claude's auto-memory into your project directory so it's git-committable and survives across machines
// Externalize Claude's auto-memory into your project directory so it's git-committable and survives across machines
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | brain-surgery |
| description | Externalize Claude's auto-memory into your project directory so it's git-committable and survives across machines |
Externalizes Claude's auto-memory into .context/memory/ in the project root, replacing the auto-memory directory with a symlink. This makes Claude's memory git-trackable, portable, and collaboratively editable.
/brain-surgery — Set up the symlink (safe, non-destructive)/brain-surgery --undo — Restore the default auto-memory directoryUse $PWD as the project root.
Safety check: If $PWD is $HOME, /home, /tmp, /, or any path with fewer than 3 components, STOP and warn the user:
"This doesn't look like a project directory. Run this from inside a project root."
Claude's auto-memory lives at:
~/.claude/projects/<encoded-path>/memory/
The encoded path replaces all / with -, including the leading slash. So /home/jocel/projects/foo becomes -home-jocel-projects-foo.
Compute it:
encoded="$(echo "$PWD" | tr '/' '-')"
auto_memory="$HOME/.claude/projects/${encoded}/memory"
Check if the user passed --undo. If so, skip to the Undo section below.
ls -la "$auto_memory" 2>/dev/null
.context/memory/ → Tell the user "Already set up!" and show the symlink. Done.This is the delicate part. Existing memory files must be preserved.
Back up first:
backup="/tmp/claude-memory-backup-$(date +%s)"
cp -a "$auto_memory" "$backup"
Create .context/memory/ if needed:
mkdir -p .context/memory
Copy files (no-clobber — don't overwrite existing .context/memory/ files):
cp -n "$auto_memory"/* .context/memory/ 2>/dev/null
Verify the merge:
src_count=$(ls -1 "$auto_memory" 2>/dev/null | wc -l)
dst_count=$(ls -1 .context/memory 2>/dev/null | wc -l)
The destination count should be >= the source count. If dst_count < src_count, ABORT and tell the user:
"Merge verification failed. Your backup is at: $backup"
Remove the original directory:
rm -rf "$auto_memory"
Tell the user how many files were merged and that the backup is at $backup.
mkdir -p "$(dirname "$auto_memory")"
mkdir -p .context/memory
ln -s "$PWD/.context/memory" "$auto_memory"
Verify it worked:
readlink "$auto_memory"
Only if .context/memory/MEMORY.md doesn't already exist:
# Project Memory
> Auto-memory externalized by claude-brain-surgery.
> This file is loaded into Claude's system prompt at the start of every session.
> Keep it under 200 lines — overflow gets truncated.
Tell the user:
$auto_memory → .context/memory/)git add .context/memory/ to start tracking it.context/ is a good place for other project context files tooWhen --undo is passed:
readlink "$auto_memory"
target="$(readlink "$auto_memory")"
rm "$auto_memory"
mkdir -p "$auto_memory"
cp -a "$target"/* "$auto_memory/" 2>/dev/null
Tell the user:
$auto_memory.context/memory/ was left intact (they can delete it manually if they want)