pi-claude-memory-index
Pi extension that exposes Claude Code's per-project auto-memory index (MEMORY.md) to Pi, read-only
Package details
Install pi-claude-memory-index from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-claude-memory-index- Package
pi-claude-memory-index- Version
0.1.0- Published
- Nov 1, 2026
- Downloads
- 355/mo · 355/wk
- Author
- yanyaoer
- License
- MIT
- Types
- extension
- Size
- 20.1 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./extensions/claude-memory.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-claude-memory-index
A Pi extension that gives Pi read-only access to the auto memory Claude Code keeps for the current project.
Before each run it adds one prompt section, claude_memory_index, holding the
project's MEMORY.md index (one line per memory, each linking to a file). It does
not inject the memory bodies. The model opens one with the read tool when an
entry looks relevant. The section tells the model to treat entries as leads that
may be out of date, to let the user and the repository take precedence, and to
leave the memory directory untouched.
What it reads
<projects root>/<project slug>/memory/MEMORY.md
- Projects roots, searched in order:
$CLAUDE_CONFIG_DIR/projects(when set), then~/.claude/projects. Profiles that symlinkprojectsto a shared directory all resolve to the same real path. - Project slug: Claude Code's rule, where every character other than
[A-Za-z0-9]becomes-, so/Users/me/src/appbecomes-Users-me-src-app. Paths whose slug is over 200 characters match Claude's<first 200 chars>-<hash>directory by prefix. - Project directory: the repository's main checkout. Linked git worktrees
(
git worktree add,.claude/worktrees/*, orchestrator worktrees under/tmp, and so on) are resolved through.git→gitdir→commondir, the same way Claude Code does, so every worktree of a repo sees the main checkout's memory. The extension reads these files directly and never runsgit. If the main checkout has no memory directory, it tries the worktree path and then the current directory.
When nothing is found, the file is empty, or the file is not valid UTF-8, the extension adds nothing and removes the section if an earlier run added it.
Install
As a Pi package from npm (adds an entry to ~/.pi/agent/settings.json):
pi install npm:pi-claude-memory-index
Or from git:
pi install git:github.com/yanyaoer/pi-claude-memory-index
Or as a plain user extension. The checkout itself is the extension, because Pi
loads the index.ts at its root:
git clone https://github.com/yanyaoer/pi-claude-memory-index ~/.pi/agent/extensions/claude-memory-index
To try it without installing anything:
pi -e /path/to/pi-claude-memory-index
Orchestrators that start plain pi (orch-cli, for example) pick up any of the
installs above. They do not see an extension that is only passed with -e.
To remove it, run pi remove npm:pi-claude-memory-index (or the git: source you
installed), or delete the cloned directory. To switch it off for one process, set
PI_CLAUDE_MEMORY=0.
Configuration
| Variable | Default | Meaning |
|---|---|---|
PI_CLAUDE_MEMORY |
on | 0, false, off or no turns the extension off |
PI_CLAUDE_MEMORY_DIR |
unset | Use this memory directory (the one that contains MEMORY.md) and skip path mapping |
PI_CLAUDE_MEMORY_PROJECTS_DIRS |
$CLAUDE_CONFIG_DIR/projects:~/.claude/projects |
Projects roots to search, separated by : (; on Windows) |
PI_CLAUDE_MEMORY_MAX_BYTES |
25000 |
Largest share of the index to inject, in bytes |
PI_CLAUDE_MEMORY_MAX_LINES |
200 |
Largest number of index lines to inject |
The defaults are the limits Claude Code applies when it loads MEMORY.md. The
extension reads only that many bytes and cuts at a line boundary. When the index is
cut short, the section says so.
If you moved Claude's memory with the autoMemoryDirectory setting, point
PI_CLAUDE_MEMORY_DIR at the new directory. The extension does not read Claude's
settings files.
Behaviour and costs
- Read-only. The extension never writes to Claude Code's directories, never changes Claude Code's configuration, and never writes memories itself.
- No double loading in Claude Code. Everything lives in Pi's extension
directory. Claude Code keeps loading
MEMORY.mdnatively, exactly once, as before. The extension adds noCLAUDE.mdimport and no symlink, and it gives Claude Code nothing more to load. If Pi already loads the same file as a context file (for example through a symlinkedAGENTS.md), the extension skips its own section. - Stable prompt. The section text stays the same until
MEMORY.mdchanges, so Pi sends no prompt delta and the provider's prompt cache stays valid. Each run checks the file's size, mtime and inode and re-reads the file only after one of them changes. - Size. The whole index goes into the system prompt of every run, up to the limits above, which is roughly 3k tokens for a 10 KB index.
Privacy
The index is sent to whichever model provider Pi is using, on every run in that
project. That includes the memory titles and one-line descriptions, plus any memory
file the model chooses to read. Don't use the extension with providers you would not
show your Claude memory to. Use PI_CLAUDE_MEMORY=0 for those runs, or keep
sensitive facts out of MEMORY.md lines. The extension logs nothing and does not
print memory contents.
Compared with pi-claude-memory
pi-claude-memory by elecnix
(npm pi-claude-memory, compared at 0.1.2) uses the same Claude Code memory
directory, but lets Pi read and write it. This package is the read-only
counterpart.
pi-claude-memory (elecnix) |
pi-claude-memory-index (this package) |
|
|---|---|---|
| Access | Read and write. Adds memory_read, memory_write and memory_list, and the prompt asks the model to record facts with memory_write |
Read-only. Adds no tools; memory bodies are opened with Pi's own read tool |
| Prompt injection | Returns systemPrompt from the first before_agent_start of a session only |
Sets a structured claude_memory_index section on every run |
| Later prompts in a session | The index is gone: a returned systemPrompt applies to one run |
The index stays, and its text is identical while MEMORY.md is unchanged |
| Linked git worktrees | Slug of the worktree path, so a worktree finds no memory | Resolves the main checkout (.git → gitdir → commondir), as Claude Code does |
| Slug rule | Replaces / and . |
Replaces every character outside [A-Za-z0-9], and handles Claude's truncated long slugs |
| Projects root | ~/.claude/projects |
$CLAUDE_CONFIG_DIR/projects, then ~/.claude/projects, or set explicitly |
| Size | Reads the whole index. If the index is empty, it lists every memory file instead | First 200 lines or 25,000 bytes, Claude Code's own load limit |
| Invalid UTF-8, off switch | Not handled | Skipped; PI_CLAUDE_MEMORY=0 |
The two "later prompts" and "worktree" rows were observed with Pi 1.4.0. One Pi RPC process received two prompts in a row, and a probe extension checked each provider request. With elecnix's package, the first request contained the index and the second did not. With this package, both did. From a linked worktree, elecnix's package injected nothing.
Choose pi-claude-memory if you want Pi to save memories that Claude Code then
loads. Choose this package if Claude Code should remain the only writer and Pi
should only read the index Claude Code maintains. Don't install both: Pi would
then get two copies of the index.
Development
npm test # node --test; needs Node >= 22.18 (built-in TypeScript stripping)
npm run typecheck # tsc against the locally installed Pi (links it into node_modules)
The tests build real git repos with worktrees under .claude/worktrees/,
.orch-worktrees/ and a path outside the repo. They also cover missing
memory, invalid UTF-8, multi-megabyte and single-line indexes, cache invalidation,
switching the extension off, and loading it twice.
License
MIT