← Catalog

@bacnh85/pi-obsidian

Pi extension for Obsidian vault tools — read, search, create, and manage notes via the Obsidian CLI.

Extension

Install

Install with PiG

pig install npm:@bacnh85/pi-obsidian

Install with Pi

pi install npm:@bacnh85/pi-obsidian
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "skills": [
    "./skills"
  ],
  "extensions": [
    "./extensions/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.9.1 (README.md). PiG does not review it.

@bacnh85/pi-obsidian

Pi extension for Obsidian vault tools — a single unified tool that runs any Obsidian CLI command: read, write, create, search, delete, move, rename, append, prepend, tasks, properties, history, daily notes, templates, and more. Plus enhanced operations like recursive file listing, task creation, task filtering/grouping, and template-based note creation.

~6,500 fewer tokens per request vs 43 separate tools (1.6K vs 8.1K).

Fixes & Improvements

AreaDetail
Write reliabilityWrite operations (create/write/append/prepend) route through base64-encoded eval — no escaping issues with \, ", `
Propertiesproperty:set auto-normalizes spaces in array values; rejoins split tokens.
Directory handlingensureFolder() creates parent path before writing. Handles root folder / and empty folder string.
Tag operationstag-rename from=X to=Y command scans all files and renames tags across the vault.
Script executioneval file=ScriptNoteName reads JS from a vault note; bare expressions are auto-wrapped with return, and the eval body runs in a try/catch (thrown errors come back as Error: ... output).

Requirements

  • Obsidian 1.12+ with CLI enabled in Settings → General → Command line interface
  • Obsidian desktop app must be running — the CLI communicates via IPC
  • The obsidian binary must be in your PATH (the installer handles this)

Install

pi install npm:@bacnh85/pi-obsidian

Configuration

One optional env var: PI_OBSIDIAN_GUARD=off disables the vault guard entirely (see below). Otherwise just make sure obsidian is in your PATH. Vault targeting uses vault=<name> as a parameter when needed; the CLI defaults to the most recently focused vault.

Vault protection

When Pi runs from a directory inside an Obsidian vault (a .obsidian/ directory is found in the current directory or an ancestor), the extension blocks generic read, write, edit, ls, find, grep, and direct filesystem bash operations that target that vault. Use obsidian for vault files instead. If that vault is not the currently focused Obsidian vault, pass its explicit vault=<name> to prevent an operation from targeting the wrong vault. Normal shell commands and explicit paths outside the vault remain available.

Note that while the CWD is inside a vault, bash commands containing shell operators (|, ;, &, $, (, ), backtick) are blocked conservatively — the guard can't reliably tell what a chained command would touch. Workarounds: run the command from outside the vault, or use the obsidian tool for vault files.

Within a vault, the bash guard works as an allowlist, not a blocklist: a small set of recognized-safe commands (npm test/build/lint (npm/pnpm/yarn/bun), git status/diff/log/branch, node --version/python3 --version, pwd, which) always run; commands that explicitly target a vault path (e.g. cat, rm, grep -r) are redirected to the obsidian tool; and everything unrecognized (npm install, node script.js, pytest) is blocked by default. If a legitimate command gets blocked, run it from outside the vault or ask for it to be allow-listed upstream.

The focused-vault lookup is cached for the process lifetime (successful lookups are memoized and never invalidated) — switching the focused vault mid-session requires reloading the Pi session.

Cross-vault guard outside a vault

From a directory that is not inside a vault, the guard also watches for tool calls that target a known vault, which requires knowing the focused vault — a obsidian vault CLI call. That call is treated strictly as a read: the guard never runs it while the Obsidian app is closed, because the CLI would launch the app (blocking the session) instead of answering. A cheap process check decides, so git status, npm test, and other path-free commands never probe or spawn anything. While the app is down the guard passes such calls through unblocked; start Obsidian (or pass vault=<name> to the obsidian tool) to restore cross-vault blocking.

Lookup failures are retried at most once per minute rather than on every tool call, so a session started before Obsidian launches recovers on its own without a spawn storm. Protection for a CWD that is inside a vault needs no CLI call and is always active.

Set PI_OBSIDIAN_GUARD=off to disable the guard completely (no CWD checks, no vault lookup).

Usage

One tool: obsidian with a run parameter containing the full CLI command.

obsidian run="read file=Meeting Notes" vault="My Vault"

Standard CLI commands

CategoryExample
Readread file="Meeting Notes"
Createcreate path=folder/note.md overwrite=true content="# Title\n\nBody"
Create (from note)create path=note.md content_from=SourceNoteName
Appendappend path=note.md content="More text"
Prependprepend path=note.md content="# Header"
Deletedelete path=old.md permanent=true
Movemove file=Note to="01 Projects/"
Renamerename file=Note name="New Name"
Searchsearch query=roadmap limit=10
Search groupedsearch query=roadmap group=file
Tagstags counts=true sort=count format=json
Tagtag name="#type/reference" verbose
Tag renametag-rename from="#moc" to="#type/moc"
Eval (inline)eval code="app.vault.getFiles().length"
Eval (file)eval file=ScriptNoteName
Propertiesproperty:set file=Note name=status value=active
Daily notedaily:read, daily:append content="- [ ] Task"
Backlinksbacklinks file=Note format=json
Outlineoutline file=Note
Historyhistory file=Note, diff file=Note from=1 to=3
Vault infovault
Filesfiles folder="01 Projects"
Files (root)files folder="/"
Files (recursive)files folder="01 Projects" recursive

Enhanced commands

These are post-processed by the extension for richer output:

CommandExampleWhat it does
Recursive filesfiles folder="01 Projects" recursiveRecursively list all files under a folder by traversing subfolders
Tasks groupedtasks format=json group=fileLists all tasks grouped by source file
Tasks filteredtasks format=json status=openLists only open ([ ]) or done ([x]) tasks
Tasks filtered+groupedtasks format=json group=file status=doneDone tasks grouped by file
Search groupedsearch query=roadmap group=fileSearch results grouped by file with line numbers
Task creationtask-create path=note.md heading="Tasks" text="Buy milk"Adds a task line under the specified heading; creates the heading if missing
Create from templatecreate-from-template template="Project Brief" name="My Project" folder="01 Projects" title="..."Reads a template, fills {{placeholder}} values, writes a new note
Files by missing propertyfiles missing-property=createdLists markdown notes whose frontmatter lacks the given property
Frontmatter tag validationfiles validate-tags="type/,domain/"Reports notes with missing/invalid tags (defaults to type/,domain/ dimensions)
Property renameproperty:rename from=date to=createdRenames a frontmatter property across all files
Search with replacesearch query=old replace=new regex=true preview=trueReplace across files; preview=true for dry-run, omit to apply
Frontmatter wrapfrontmatter:wrapWraps leading title:/tags: lines of notes lacking frontmatter into a --- block

Syntax rules

  • Quote values with spaces: file="My Note", query="search phrase"
  • Boolean flags: permanent, overwrite, total, silent, inline, verbose, recursive
  • For JSON output: add format=json flag
  • Target a vault: add vault="Vault Name" to any command
  • Multiline content: use \n for newlines, \t for tabs

How it works

Previously this extension registered 43 separate tools (obsidian_read, obsidian_create, obsidian_search, etc.), consuming ~8,122 tokens per request. v0.3 consolidated to a single obsidian tool that parses the run string and dispatches to the Obsidian CLI. v0.4 adds post-processing for recursive file listing, task filtering/grouping, task creation, and template-based note creation — all through the same unified tool.

Known local-only disclosure (eval)

Write/eval commands pass note content (base64 chunks) as process argv to obsidian-cli. argv is visible to other local processes via ps/Get-Process for the call's lifetime. Content is never secrets-shaped by design — still, on shared hosts, prefer eval file= (vault note) or create-from-template over inline eval code= with sensitive content. Upstream stdin/file transport would remove this entirely (tracked in issue #20 L2).

Changelog

See CHANGELOG.md for release history.

License

MIT