Add MemoryManager CLI for smart project memory management#1032
Open
umutkeltek wants to merge 3 commits intodanielmiessler:mainfrom
Open
Add MemoryManager CLI for smart project memory management#1032umutkeltek wants to merge 3 commits intodanielmiessler:mainfrom
umutkeltek wants to merge 3 commits intodanielmiessler:mainfrom
Conversation
Detects orphaned project memory directories, enables migration when projects are moved/renamed, and provides cleanup for stale worktree and empty memory directories. Uses git remote URL fingerprinting to match moved projects to their previous memory. Companion hook files (MemoryDetect.hook.ts, memory-registry.ts) are deployed to ~/.claude/ and auto-register projects at session start. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Detects orphaned project memory directories, enables migration when projects are moved/renamed, and provides cleanup for stale worktree and empty memory directories. Uses git remote URL fingerprinting to match moved projects to their previous memory. Companion hook files (MemoryDetect.hook.ts, memory-registry.ts) are deployed to ~/.claude/ and auto-register projects at session start. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `setup` subcommand that auto-deploys hook files and configures settings.json — one command, works for any user. Generate hook source programmatically to avoid template literal escaping issues. Remove all hardcoded user paths, derive everything from homedir(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Self-contained memory management tool for PAI. One file, one setup command — works for any user.
Problem
Claude Code stores project memory at
~/.claude/projects/{encoded-path}/memory/. When a project folder is moved or renamed, a new encoded directory is created and the old memory becomes orphaned — accumulated learnings, feedback, and references are silently lost with no recovery path or cleanup mechanism.Solution
Self-bootstrapping:
bun Tools/MemoryManager.ts setupdeploys the SessionStart hook and registry library to~/.claude/hooks/, updatessettings.json, and creates required directories. No manual file copying.Git remote fingerprinting: Every project opened gets registered with its normalized git remote URL (SSH/HTTPS variants match). When a project with no memory is opened, the hook searches the registry for a matching remote and auto-copies memory from the old location.
CLI subcommands:
setupscanstatusorphansworktreesmigrate <old> <new>adopt <encoded-dir>cleanup [--worktrees] [--empty] [--dry-run]normalize-paths <dir>registryDesign decisions:
homedir()— no hardcoded user pathsTest plan
bun Tools/MemoryManager.ts setup— verify hooks deployed and settings updatedbun Tools/MemoryManager.ts status— verify dashboard shows correct countsbun Tools/MemoryManager.ts scan— verify all dirs listed with correct statusbun Tools/MemoryManager.ts cleanup --worktrees --dry-run— verify safe dry-run~/.claude/MEMORY/STATE/project-registry.json🤖 Generated with Claude Code