Skip to content

Add MemoryManager CLI for smart project memory management#1032

Open
umutkeltek wants to merge 3 commits intodanielmiessler:mainfrom
umutkeltek:feature/memory-manager
Open

Add MemoryManager CLI for smart project memory management#1032
umutkeltek wants to merge 3 commits intodanielmiessler:mainfrom
umutkeltek:feature/memory-manager

Conversation

@umutkeltek
Copy link
Copy Markdown

@umutkeltek umutkeltek commented Apr 4, 2026

Summary

Self-contained memory management tool for PAI. One file, one setup command — works for any user.

bun Tools/MemoryManager.ts setup    # deploys hooks, configures settings
bun Tools/MemoryManager.ts status   # see what you've got

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 setup deploys the SessionStart hook and registry library to ~/.claude/hooks/, updates settings.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:

Command Description
setup Deploy hooks and configure settings (run once)
scan List all project memory dirs with status
status Summary dashboard with counts and disk usage
orphans List orphaned directories with recovery info
worktrees List stale worktree memory directories
migrate <old> <new> Manually migrate memory between paths
adopt <encoded-dir> Adopt orphaned memory for current project
cleanup [--worktrees] [--empty] [--dry-run] Safe removal of stale dirs
normalize-paths <dir> Replace hardcoded absolute paths in memory files
registry Show fingerprint registry contents

Design decisions:

  • Copy, never move during migration (old memory preserved as backup)
  • Git remote URL is primary fingerprint; name-only matches suggest but don't auto-migrate
  • All paths derived dynamically from homedir() — no hardcoded user paths
  • Registry corruption is non-fatal — hook continues without migration
  • Setup is idempotent — safe to run multiple times

Test plan

  • Run bun Tools/MemoryManager.ts setup — verify hooks deployed and settings updated
  • Run bun Tools/MemoryManager.ts status — verify dashboard shows correct counts
  • Run bun Tools/MemoryManager.ts scan — verify all dirs listed with correct status
  • Run bun Tools/MemoryManager.ts cleanup --worktrees --dry-run — verify safe dry-run
  • Open a project → verify registry populated at ~/.claude/MEMORY/STATE/project-registry.json

🤖 Generated with Claude Code

umutkeltek and others added 3 commits April 4, 2026 04:56
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant