Skip to content

Use Claude Code memory store with autoMemoryStorage - #434

Merged
ilovepixelart merged 12 commits into
ilovepixelart:mainfrom
HuliLulu46:shared-claude-memory
Nov 14, 2026
Merged

ilovepixelart merged 12 commits into
ilovepixelart:mainfrom
HuliLulu46:shared-claude-memory

Conversation

@HuliLulu46

Copy link
Copy Markdown
Contributor

Summary

Add an opt-in memory storage mode that reuses the store Claude Code already keeps for each project, so memories do not start over or drift apart when switching between Claude Code and pi.

autoMemoryDirectory override
  > autoMemoryStorage: "claude"
      <claude config>/projects/<Claude project slug>/memory
  > default
      ~/.pi/agent/memory/<pi project slug>

The Claude store is read and written in place. Project paths use Claude's observed encoding, and the store is keyed on the repository root so subdirectory sessions and worktrees share it.

Existing Claude indexes remain usable: reads and writes recognize underscore file names, preserve link titles and section headings, and replace only the matching entry. Index link targets are accepted as file names only when they are plain path segments, so a repository-supplied index cannot write outside the store.

The default pi store, explicit autoMemoryDirectory overrides, and automatic migration behavior remain unchanged. Switching modes does not move or merge existing memories.

Evidence

  • Before: tests/memory-shared.test.ts had 16 failing tests covering Claude project resolution and compatibility with Claude-written stores.
  • After: all 16 new tests pass, alongside the existing memory suites: 88 tests across four files.
  • Full gate: npm run check passes, including Biome, strict TypeScript, knip, and the full Vitest suite with coverage.
  • Coverage: 97.64% statements, 93.45% branches, 97.14% functions, 99.01% lines.

Merge Danger

Door: two-way

Blast Radius: opt-in memory storage selection, plus shared memory read/write/index handling.

The new storage location is inactive unless the user selects autoMemoryStorage: "claude". The default pi storage path is unchanged. Format-compatibility changes affect memory reads, updates, and deletions in both modes and are covered by the existing and new tests.

  • npm run check passes (Biome, strict tsc, Vitest)
  • Tests cover the change

lisilu and others added 12 commits November 14, 2026 23:37
An entry line ending in a carriage return did not match the entry
pattern, so a save appended a duplicate line and a delete left the line
behind. Lines are now split on LF or CRLF and the index is rewritten
with the line ending it already uses.

A title containing a closing bracket is matched by its link target.

An index whose first line is blank no longer receives a second
`# Memory index` heading: the first non-blank line decides.
Both describe blocks repeated the temp home, the settings writer, the
store path helper and the extension wiring. They now use one file-level
copy. The per-file HOME restore is dropped: tests/setup.ts rolls
process.env back after every test.
With build_notes.md and build-notes.md both indexed, reading
build-notes returned the dashed file, saving it overwrote the
underscored one, and deleting it removed both. A file such as
foo-bar_baz.md could not be reached at all.

All three actions now resolve the name once: an exactly named file wins,
and a file differing only in dashes and underscores is used when the
exact one does not exist. Delete removes that file and its index line
only.

safeStem is removed: a name is a slug and a match differs from it only
by underscores, so a link target with a path separator never matched. A
test now pins that an index link pointing out of the store is not
followed.
With autoMemoryStorage "claude", a save of a new memory prepended
`# Memory index` to an index that has no heading and appended the entry
in pi's `- [name](name.md): description` format. Claude Code writes its
index without a heading and separates the link from the description
with a dash.

In the claude store a new entry now uses Claude's separator and no
heading is added. In both stores an update keeps the entry's link and
whatever separator it already has (a colon or any dash) and replaces
only the description. The pi store's format is unchanged.

The test fixture now has the shape Claude Code writes: no top heading
and dashed file names, with one underscored name kept for the fallback.
stampModified removed every `modified:` line, including the one nested
under `metadata:`, and appended a top-level field. A file whose
metadata held only `modified` was left with an empty `metadata:` key.

An existing field is now replaced in place with its indentation. A file
with a `metadata:` block and no timestamp gets it inside that block,
where Claude Code writes it; a file without the block gets a top-level
field as before. CRLF frontmatter keeps its line ending.
A memory saved by pi into Claude Code's store had no frontmatter unless
the content carried its own. Claude Code reads `name` and `description`
from it and flags a file without a description as unreliable for
recall.

In the claude store a save now adds `name` (the memory name) and
`description` (the description the save already takes) when the content
lacks them, and moves a top-level `type:` under `metadata:`, where
Claude keeps it. Fields the content already has are kept. The pi store
is unchanged.
claudeProjectSlug returned the dashed path at any length. Claude Code
cuts a name longer than 200 characters there and appends a base-36
32-bit hash of the path, so a deep project resolved to a directory
Claude never uses. The cap and the hash are ported, and the project
path and the resulting store path are normalised to NFC as Claude does.

Two environment variables Claude Code reads are honoured:
CLAUDE_CODE_REMOTE_MEMORY_DIR replaces the config directory as the root
of the store, and CLAUDE_CODE_PROJECT_DIR_NAME replaces the slug when
CLAUDE_CONFIG_DIR is set and the value is one plain segment of at most
64 characters that is not a Windows device name. Both are added to the
test environment quarantine.
Adds tests for behaviour that had none: a linked worktree resolves to
the main checkout's Claude store, CLAUDE_CONFIG_DIR moves both the
setting and the store, an unrecognised autoMemoryStorage value keeps
the pi store, and a CRLF index is updated and trimmed through the tool
with its line ending kept.
The paragraph said the setting is read from any settings scope; project
settings count only once the project is approved. It also restated the
index format rules. It now names the scopes, points at claudeMemoryDir
for the location rules, states what a pi save writes into Claude's
store, and lists the known differences from Claude Code.

A dash pair in a memory.ts comment is replaced with commas.
@ilovepixelart
ilovepixelart merged commit 22e72f4 into ilovepixelart:main Nov 14, 2026
12 checks passed
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.

2 participants