pi-obsidian-memory

Long-term memory for the pi coding agent, stored in Obsidian vaults

Packages

Package details

extensionskill

Install pi-obsidian-memory from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-obsidian-memory
Package
pi-obsidian-memory
Version
0.3.7
Published
Nov 25, 2026
Downloads
1,405/mo · 942/wk
Author
davy121
License
MIT
Types
extension, skill
Size
877.4 KB
Dependencies
5 dependencies · 2 peers
Pi manifest JSON
{
  "skills": [
    "./skills"
  ],
  "extensions": [
    "./src/pi/extension.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-obsidian-memory

Long-term memory for the pi coding agent, stored as Markdown notes in Obsidian vaults.

pi forgets everything when a session ends. With this package it keeps what matters (your preferences, the rules and decisions of each project, lessons from past mistakes) and brings it back when it helps. You can read and edit every note in Obsidian.

Contents

  1. Requirements
  2. Install
  3. Set up
  4. Coming from pi-observational-memory
  5. How it works
  6. Settings
  7. Where things are stored
  8. Privacy
  9. Troubleshooting
  10. Known limits
  11. Development

Requirements

What Why Required?
pi Runs the package. Tested with pi 1.3.0. Yes
Node 22.19 or later pi runs the package on it. Yes
A chat model configured in pi Turns the conversation into observations for compaction (observer) and finds relevant notes at session start (memory agent). Any model pi can use works; a small, cheap one is enough for the memory agent. Yes
A TypeSafe API key (TYPESAFE_API_KEY) Jev, TypeSafe's classifier, decides which notes help each message. Get a key at typesafe.ai. Price: $0.042 per million input tokens. Strongly recommended
Obsidian Reading and editing the notes. No: notes are plain Markdown

Without TYPESAFE_API_KEY: no notes are added to your messages (pi tells you once per session).

Setting the TypeSafe key

Set the environment variable before starting pi:

# macOS / Linux (add it to ~/.bashrc or ~/.zshrc to keep it)
export TYPESAFE_API_KEY=your-key
# Windows (kept for new terminals)
setx TYPESAFE_API_KEY "your-key"

The key can also be pi's stored credential for the typesafe provider. It is never written to this package's config.

Install

pi install npm:pi-obsidian-memory

Then restart pi. To try it for one run without installing: pi -e npm:pi-obsidian-memory.

pi list shows installed packages; pi update updates them.

Set up

  1. Create the global vault. Run /memory-setup in pi. It asks:

    • where the global vault goes: a new folder, or an existing folder (an Obsidian vault you already have works);
    • which chat model runs the observer and the consolidator: they turn the conversation into observations and the oldest observations into notes; the model in use is the default;
    • which chat model runs the memory agent; the list is sorted by price, cheapest first.

    It shows what each choice sends where, then writes the config and the vault.

  2. Give each project its own vault. Open pi in the project folder and run /memory-init. A folder without a project vault uses the global vault only.

  3. Use pi as usual. Say "remember that …" to save something at once. The rest is saved on its own as the session grows.

Run /memory-setup again at any time to open the settings screen. Both commands need pi's interactive mode.

Coming from pi-observational-memory

This package now observes and compacts the session the way pi-observational-memory does. Both packages compact, and pi keeps only one compaction, so uninstall pi-observational-memory:

  1. Run pi list to see its source.
  2. Run pi remove <source> with that source.
  3. Restart pi.

/memory-doctor warns while it is still loaded.

To bring what it saved into the vaults, run /memory-import in each project, after /memory-init. It reads the topic files and the journey in .memory/, saves what is durable memory as notes, and tells you how many files it read and how many changes it made. The files in .memory/ are left as they are.

How it works

Two vaults

  • Global vault: about you. How to address you, your preferences, your patterns, lessons that apply everywhere.
  • Project vault: about one project. Its rules, decisions, facts, open issues.

Each note holds one point. Its file name is the statement (for example pnpm/Use pnpm, never npm.md), the body has the detail, and the frontmatter says what kind of memory it is:

---
id: 01JABCDE7XKQ2M9V3RTN8WPZ5F
type: rule
created: 2026-10-04
updated: 2026-10-04
dontForget: true
---

Use pnpm for every install and script. In CI: `pnpm install --frozen-lockfile`.

Types: rule, procedure, constraint, fact, issue, question, decision, lesson, goal, risk, idea, reference. Notes are written in English. They are never deleted: a retired note moves to archive/. The full format is in docs/vault-format.md.

What happens during a session

  1. Session start. Every note marked dontForget: true is loaded into pi's system prompt, in full. The memory agent finds other relevant notes in the background; they arrive as a hidden message at the next user message once ready. The first message does not await the agent's completion, though vault operations share a session lease.
  2. Each message. Jev decides whether stored memory would help. If yes, memory searches the available vaults directly, reads the hits, and Jev scores notes not already loaded. The notes that help are added in a hidden message, within context.budgetChars (12,000 characters by default). A note you changed since it was loaded is sent again.
  3. Observer and compaction. After each turn, the observer reads each new stretch of the conversation (10,000 tokens by default) and writes dated observations into the pi session. When the context reaches 150,000 tokens, memory compacts the session: the older part is replaced by a block with the memory map (the names of the notes in both vaults) and the observations, and the last 20,000 tokens are kept word for word. /compact and pi's own compactions use the same block. A run that was compacted while it used tools goes on by itself. Observations are checked against your own messages, and a compaction waits for those checks to finish or fail; whatever is still unchecked is marked. A request, restriction, authorization or goal you wrote is kept as a passage of your words: a message of 400 characters or fewer is kept whole, and a longer one keeps the passages the model finds and the check accepts (it is kept whole only after three failed model attempts), so not every request is guaranteed to be kept. Text the assistant read or produced (a file, a tool result, another session's transcript) is named after its source and keeps a visible [not said by the user] mark, even once rewritten. An observation not yet checked is marked [origin unverified], and one the check could not confirm is marked [user attribution unconfirmed]. The compaction tells the assistant that, when your requirements conflict, your latest instruction governs; a later tool result, log or assistant message does not replace it.
  4. Consolidation. When the observations kept in the session pass 15,000 tokens, the consolidator turns the oldest ones into notes, in the background, until about 10,000 tokens of observations remain: it adds, updates, archives or replaces notes in the global or the project vault. It never asks you anything: what it is unsure of is not saved. Tasks, progress and history stay in the session. The compaction block opens with a short dated journey and then shows the work state: the last known facts about what exists and what was verified. Consolidated observations and your retained passages stay in the block without a size cap, but are not counted toward the next consolidation or picked again to become notes. Without a vault configuration, pi's active model runs the session cycle using the default thresholds, without reading or writing vault notes. Read material, unverified and unconfirmed observations are never saved as notes, and a batch holding unverified observations waits until they are checked. An observation found later to be read material, after it was consolidated, is passed back as a correction: the consolidator is asked to archive or update the notes that state it as your rule, never to save it as a note, and the journey and work state are corrected not to present it as your words. That review is model judgement, not a verified repair of the vaults. The cycle follows pi-observational-memory.

You change notes in Obsidian whenever you want. pi must read a note before changing it, and a note you edited since then is never overwritten.

Tools the agent uses

Tool Does
memory_search Finds notes by words and by meaning, in the global vault, the project vault or both
memory_get Reads a note, a folder's index, or anything under archive/
memory_add Saves a new note
memory_update Changes a note
memory_archive Moves a note to archive/
memory_succeed Replaces a note with a new one; both link to each other

The bundled skill obsidian-memory teaches the agent where notes go and how to use these tools.

Commands

Command Does
/memory-setup First setup; afterwards, the settings screen
/memory-init Gives the current project its own vault
/memory-doctor Checks the vaults, the config, the models and the keys, and says what is wrong
/memory-export Saves both vaults to a new .zip
/memory-import Saves what pi-observational-memory wrote in .memory/ as notes

Guards

  • Vault guard. The agent reaches the vaults only through the memory tools. pi's file tools (read, write, edit, grep, find, ls) on a vault are refused, and so are shell commands that write a vault path out. You and Obsidian are not affected.

Read-only entry

A second entry, src/pi/read-only-extension.ts, is not in the package manifest, so it is never loaded by default. Load it by path, for example pi -e <package folder>/src/pi/read-only-extension.ts, in a session that should read memory but never change it. It registers:

  • the tools memory_search and memory_get;
  • no /memory-* command;
  • the injection of memory into the prompt (session start and each message);
  • the vault guard.

It does not register the other four memory tools or the observation cycle (no observer, no memory compaction, no consolidator: pi compacts such a session on its own).

Dashboard

Each vault gets a Memory.base file: an Obsidian view of all notes, the Don't forget notes and the archive. Your edits to it are kept.

Settings

All settings are changed in the /memory-setup screen, or by asking pi. You never need to edit the file.

Setting Default What it does
Global vault chosen at setup Folder of the global vault
Projects none Each project folder and its vault, added by /memory-init
Observer model the model in use at setup Chat model that turns the conversation into observations
observer.thinking low Thinking level of the observer model
observer.chunkTokens 10,000 Tokens of conversation the observer reads at a time
observer.concurrency 4 Observers that run at the same time
compaction.atContextTokens 150,000 Context tokens at which memory compacts the session
compaction.tailTokens 20,000 Tokens of the latest conversation kept word for word after a compaction
compaction.mapTokens 2,000 Tokens of the memory map in the compaction block
Consolidator model the observer model at setup Chat model that turns the oldest observations into notes
consolidator.thinking medium Thinking level of the consolidator model
consolidator.atPoolTokens 15,000 Tokens of observations in the session at which the consolidator runs
consolidator.poolTargetTokens 10,000 Tokens of observations left in the session after it runs
consolidator.journeyTokens 1,000 Size of the journey; older parts are shortened past this
Memory agent model chosen at setup Chat model that searches and reads notes at session start
context.budgetChars 12,000 Characters of relevant notes added at session start and to each message (Don't forget notes do not count)
limits.maxStatementChars 100 Longest note name
limits.maxBodyChars 1,000 Longest note body
Embeddings local Model for search by meaning: local (no key), OpenAI (OPENAI_API_KEY) or Google (GEMINI_API_KEY)
Decision model Jev Jev (TypeSafe, cutoffs 0.5/0.5) or Laya (local server, you set the cutoffs)

Every field, the file format and running Laya locally are in docs/config.md.

Where things are stored

What Where
Notes The vault folders you chose
Settings pi-obsidian-memory/config.json in pi's agent folder (~/.pi/agent by default)
Search index pi-obsidian-memory/index/ in pi's agent folder; rebuilt from the notes when needed
Local search model pi-obsidian-memory/models/ in pi's agent folder; downloaded once, about 135 MB

The vaults hold only notes, their index.md files, _templates/ and Memory.base, so they can live in any synced folder (OneDrive, iCloud, Dropbox).

Privacy

  • The observer, the consolidator and the memory agent send conversation and note content to the chat models you choose.
  • Observations and the journey are kept in the pi session file, like the conversation.
  • Jev sends your messages and candidate notes to TypeSafe.
  • Search by meaning runs on your machine by default; OpenAI or Google receive note content and queries only if you choose them.
  • /memory-setup shows each of these before it saves.
  • Notes are saved as written, without masking. The config file never holds a key.

Troubleshooting

Run /memory-doctor first: it checks the vaults, the config, the models and the keys, and says what is wrong. The only thing it offers to change is a blank note, after asking you.

You see Do
"Memory is off" or "Run /memory-setup first" Run /memory-setup
"No chat model is available" during setup Connect a model in pi (/login), then run /memory-setup again
No relevant notes are ever added Check that TYPESAFE_API_KEY is set, then run /memory-doctor
"Memory observer failed: …" The text after the colon names the cause, for example a model without a key. It tries again a minute later; /memory-doctor checks the observer model
"Memory consolidation failed: …" The text after the colon names the cause. It tries again a minute later; /memory-doctor checks the consolidator model
"Memory could not check the origin of observations: …" The text after the colon names the cause. It tries again in a minute; after three failed attempts they stay unconfirmed and are not saved as notes.
"… so pi compacted it on its own" The observer had not covered the start of the session yet. Nothing to do: it catches up, and the next compaction uses its observations
"Memory could not compact the session: …" The text after the colon names the cause, for example "Nothing to compact (session too small)". Nothing was compacted, and a run the compaction interrupted goes on. Nothing to do: memory tries again once the conversation has grown
No API key found for "<provider>" in /memory-doctor Log in to that provider in pi (/login) or set its key

Known limits

  • Paths are compared ignoring case on Windows and macOS and with case on Linux, whatever the volume.
  • The vault guard does not see a vault path the shell builds indirectly (variables, globs, scripts), tools of other extensions, or foreground subagents.
  • How well the consolidator judges what to save is checked only by end-to-end scenarios: a stated rule is saved, a task is not, and a rule and a secret stated in Portuguese become English notes that keep the secret as written.
  • Consolidation starts at the end of a turn. Observations made after the last turn wait for the next one.
  • With pi-observational-memory also installed, only one of the two compactions is kept (see Coming from pi-observational-memory).
  • Index lock. The search index is shared by every pi session of the same agent folder. Opening, reading and writing it wait for a lock while another live process holds it. The wait is synchronous and Esc does not stop it. It ends when the other process releases the lock; to end a wait that does not finish, close the pi session that holds the lock or end its process. The system then releases the lock: a process that dies never leaves it held, and a reused process ID blocks nobody.
  • Process without the lock. A process that runs the memory without the lock does not see it. A collision with it still returns "unavailable" at once instead of waiting.
  • Index corrupted again. If the index becomes corrupt again while one process keeps a connection to it open and another process recovers it, the recovery can fail or be lost. On Windows the swap fails with EPERM, and the second process's operation returns without that vault. On Linux and macOS the swap succeeds, and the first process writes to the old file, already unnamed, and loses those writes until it opens the index again (POSIX rename semantics, not measured here). The index is rebuilt from the notes, so no note is lost.
  • Attribution checks use this session only. Each observation is checked against the messages of its own range and the most recent earlier messages of the same session that fit in about one observer chunk of text (observer.chunkTokens). Nothing in the check searches other sessions or the vaults, and the check is model judgement, not guaranteed to settle every case.
  • Observations from before the update. They are checked on the next turns of the same session, or while a compaction waits for them. Until they are settled they are marked [origin unverified], and a batch holding them waits for consolidation.
  • Passages you wrote after consolidation. They stay in later compactions with no new size cap, so the compaction block grows with them. A kept instruction that was already carried out is history: it shows what you asked, and it is not new permission to repeat the work. For a message over 400 characters, the passages kept are chosen by the model and checked against the message, so not every request is guaranteed to be kept.
  • Compactions already saved are not rewritten. A compaction in a session file keeps its text, so an instruction it dropped stays dropped there. Only compactions built after the update keep your passages after consolidation.
  • No guaranteed repair of existing notes. Notes saved from an observation later found to be read material are only passed to the consolidator for review, which may or may not change them.

Development

npm install
npm run lint
npm run typecheck
npm test              # offline: pure tests and tests on a real temporary disk
npm run test:e2e      # the real pi over RPC, through OmniRoute
npm run test:model    # live tests: real models and network
pi -e ./src/pi/extension.ts

npm run test:e2e runs one test per feature with the real cc/claude-haiku-5-5 through OmniRoute (pi-omniroute-sync) and the real Jev. It reads OMNIROUTE_URL, OMNIROUTE_API_KEY and TYPESAFE_API_KEY from the environment. CI runs it on Windows, and lint, typecheck and npm test on Windows, macOS and Linux.

Releases are automatic: a push to main with a feat or fix commit bumps the version, rewrites CHANGELOG.md, publishes to npm and creates the GitHub release.

More: vision, roadmap, note format, settings.

License

MIT