agentleFS
AdrianV101AdrianV101/obsidian-pkm-plugin/CLAUDE.md

obsidian-pkm-plugin

CLAUDE.md13 starsChanged 10 months agoMITView on GitHub

This is a Claude Code plugin that provides an MCP server and supporting tools for bidirectional knowledge flow between Claude Code and an Obsidian vault. It packages 20 MCP tools, Claude Code hooks, and a setup skill under the vault-pkm plugin identity. The project consists of three parts: MCP Server: A Node.js ES module server implementing the Model Context Protocol. The main entry point is index.js (tool definitions and request routing), with pure helper functions extracted to helpers.js. It provides…

  • Reads credentials
  • Installs packages

The file

We split this CLAUDE.md into the rules it gives an agent

8 rules. About 0 are common, 2 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add annotated wikilinks to a note's section with deduplication.

    line 162
  2. Very specific:

    Read-only tools (vault_read, vault_peek, vault_links, vault_neighborhood, vault_suggest_links) support fuzzy path resolution:

    line 222
  3. Very specific:

    Use a more specific path or the folder param to disambiguate

    line 227
  4. Very specific:

    Write/destructive tools (vault_write, vault_append, vault_edit, vault_update_frontmatter, vault_trash, vault_move, vault_add_links) require …

    line 234
  5. Very specific:

    All notes use YAML frontmatter with type, status, created fields

    line 302
  6. Distinctive:

    When creating ANY note via MCP, ALWAYS include frontmatter:

    line 310
  7. Very specific:

    Document decisions, research findings, and debugging sessions as you work.

    line 329
  8. Very specific:

    Use vault-pkm:pkm-explore to research what the vault already knows about a topic before creating new content.

    line 331

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

PKM: 01-Projects/Obsidian-MCP

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

This is a Claude Code plugin that provides an MCP server and supporting tools for bidirectional knowledge flow between Claude Code and an Obsidian vault. It packages 20 MCP tools, Claude Code hooks, and a setup skill under the vault-pkm plugin identity.

Commands

# Install dependencies
npm install

# Run the MCP server (for testing)
VAULT_PATH="/path/to/your/vault" node cli.js

# Vault scaffolding wizard (templates, PARA folders)
node cli.js init

# Start the server
npm start

# Run unit tests
npm test

# Run linter
npm run lint

Architecture

The project consists of three parts:

MCP Server: A Node.js ES module server implementing the Model Context Protocol. The main entry point is index.js (tool definitions and request routing), with pure helper functions extracted to helpers.js. It provides 20 tools for vault interaction:

  • vault_read - Read note contents (supports pagination: heading, tail, tail_sections [with optional section_level param, default: 2], chunk, lines; auto-redirects to peek data for files >80k chars; force bypasses redirect)
  • vault_peek - Inspect file metadata/structure without reading full content (size, frontmatter, indented heading tree, preview)
  • vault_write - Create new notes from templates (enforces frontmatter; settable fields: status, priority, project, deciders, due, source; variables param for custom <%...%> substitution in template body)
  • vault_append - Add content to existing files, with optional positional insert (after/before heading, end of section)
  • vault_edit - Surgical string replacement (exact match, single occurrence)
  • vault_update_frontmatter - Update YAML frontmatter fields atomically (set, create, remove fields)
  • vault_search - Full-text search across markdown files
  • vault_semantic_search - Semantic similarity search using OpenAI embeddings (requires VAULT_PKM_OPENAI_KEY or OPENAI_API_KEY)
  • vault_suggest_links - Suggest relevant notes to link based on content similarity; graph_context: true for graph-semantic blending (requires VAULT_PKM_OPENAI_KEY or OPENAI_API_KEY)
  • vault_list / vault_recent - Directory listing and recent files
  • vault_links - Wikilink analysis ([[...]] syntax)
  • vault_neighborhood - Graph context exploration via BFS wikilink traversal
  • vault_query - Query notes by YAML frontmatter (type, status, tags [ALL must match], tags_any [ANY must match], dates, custom_fields for arbitrary field matching, sort_by/sort_order for result ordering)
  • vault_tags - Discover all tags with per-note counts; supports folder scoping, glob patterns, inline #tag parsing
  • vault_activity - Query/clear activity log (all tool calls with timestamps and session IDs)
  • vault_trash - Soft-delete to .trash/ (Obsidian convention), warns about broken incoming links
  • vault_move - Move/rename files with automatic wikilink updating across vault (update_links: false to skip)
  • vault_add_links - Add annotated wikilinks to a note's section with deduplication (default: ## Related)
  • vault_link_health - Graph health report: orphans, broken links, weakly connected notes, ambiguous links

The server uses VAULT_PATH environment variable (defaults to ~/Documents/PKM) and includes path security to prevent directory escaping. Optional VAULT_PKM_VAULT_NAME overrides the vault name embedded in obsidian:// links in tool output (defaults to basename(VAULT_PATH)); set this only when the on-disk folder name differs from the vault name registered in Obsidian.

vault_neighborhood (Graph Context Exploration)

Explores the graph neighborhood around a note by traversing wikilinks using BFS. Returns notes grouped by hop distance with frontmatter metadata.

  • Resolves wikilink targets to actual file paths (handles [[note]], [[folder/note]], [[note|alias]], [[note#heading]])
  • Detects ambiguous links (multiple files with same basename) and annotates them
  • Per-call indexes: basename resolution map + incoming link index (no persistent state)
  • Params: path (required), depth (default: 2), direction ("both" | "outgoing" | "incoming"), include_semantic (boolean, appends unlinked semantic results), semantic_limit (default: 5)
  • Implementation: graph.js module (link resolution, BFS traversal, formatting)

vault_semantic_search (Semantic Similarity Search)

Finds conceptually related notes even when they use different terminology. For example, searching "managing overwhelm" finds notes about "cognitive load" or "information overload".

  • Requires VAULT_PKM_OPENAI_KEY or OPENAI_API_KEY env var — tool is hidden from tool list when not set
  • Uses OpenAI text-embedding-3-large (3072 dimensions)
  • Index stored at $VAULT_PATH/.obsidian/semantic-index.db (SQLite + sqlite-vec)
  • Background fs.watch keeps index fresh; startup sync catches changes made while server was stopped
  • Chunking: whole-note for short notes, heading-based (##) splits for notes > ~2000 tokens
  • Params: query (required), limit, folder, threshold (0-1 similarity score), anchor (optional path for graph-distance weighting), graph_weight (0-1, default: 0.3)
// Graph-weighted search biased toward a specific note's neighborhood
vault_semantic_search({ query: "cache eviction strategies", anchor: "research/caching.md", graph_weight: 0.3 })

The semantic index is a regenerable cache — deleting semantic-index.db triggers a full re-embed on next startup. The DB syncs across machines via Obsidian Sync (stored in .obsidian/).

vault_write (Template-Based Note Creation)

Notes must be created from templates to ensure proper frontmatter. The tool:

  • Loads templates from 05-Templates/ at startup
  • Auto-substitutes <% tp.date.now("YYYY-MM-DD") %> and <% tp.file.title %>
  • Accepts frontmatter param for tags and other fields (status, priority, project, deciders, due, source)
  • Validates required fields: type, created, tags
  • Validates enum fields for task notes: status (pending/active/done/cancelled), priority (low/normal/high/urgent)
  • Errors if file already exists (use vault_edit or vault_append to modify)

Examples:

vault_write({
  template: "adr",
  path: "01-Projects/MyApp/development/decisions/ADR-001-database.md",
  frontmatter: { tags: ["decision", "database"], deciders: "Team" }
})

vault_write({
  template: "task",
  path: "01-Projects/MyApp/planning/task-api-refactor.md",
  frontmatter: { tags: ["task", "api"], priority: "high", project: "MyApp", due: "2026-03-01" }
})

vault_activity (Session Memory / Activity Log)

Logs all MCP tool calls with timestamps and session IDs. Enables cross-session memory — Claude can recall what was read, written, or searched in previous sessions.

  • Storage: SQLite DB at $VAULT_PATH/.obsidian/activity-log.db (separate from semantic index)
  • Session ID: generated via crypto.randomUUID() at MCP server startup (each conversation gets its own)
  • Logs every tool call except vault_activity itself
  • Supports filtering by tool name, session ID, date range, and path substring
  • Privacy: action: "clear" deletes entries (with optional filters), or delete the DB file
vault_activity()                                    // Recent 50 entries
vault_activity({ tool: "vault_write" })             // Only writes
vault_activity({ session: "abc12345" })             // Filter by session ID prefix
vault_activity({ since: "2026-02-08" })             // Today's activity
vault_activity({ path: "01-Projects/MyApp" })       // Activity on specific project
vault_activity({ action: "clear" })                 // Clear all history
vault_activity({ action: "clear", before: "2026-01-01" })  // Clear old entries

Implementation: activity.js (ActivityLog class)

vault_update_frontmatter (Atomic Frontmatter Updates)

Safely updates YAML frontmatter fields in an existing note without touching the body content. Parses existing frontmatter, applies changes, and writes back.

  • Set fields to new values, add new fields, or remove fields by setting to null
  • Protected fields (type, created, tags) cannot be removed (only updated)
  • Arrays (like tags) are replaced wholesale
  • Enum validation: task status must be one of pending, active, done, cancelled; task priority must be one of low, normal, high, urgent — non-task types are unconstrained
  • Requires exact path (no fuzzy resolution — destructive operation)
vault_update_frontmatter({
  path: "01-Projects/MyApp/planning/task-api-refactor.md",
  fields: { status: "active", priority: "urgent" }
})

// Remove a field by setting to null
vault_update_frontmatter({
  path: "01-Projects/MyApp/planning/task-api-refactor.md",
  fields: { due: null }  // removes the due field
})

Implementation: updateFrontmatter pure function in helpers.js, handler in handlers.js

vault_add_links (Atomic Link Insertion)

Add annotated wikilinks to a note's section with deduplication. Validates targets exist, skips duplicates by basename (case-insensitive). Creates the section if missing.

  • Requires exact path (no fuzzy resolution — destructive operation)
  • Deduplicates by basename: [[note]] won't be added if [[note]] or [[folder/note]] already in file
  • Section insertion point: end of section (before next same-or-higher heading, or EOF)
ParameterTypeDescription
pathstringExact vault-relative path (required)
linksarrayLinks to add: [{ target, annotation }] (required)
sectionstringTarget section heading (default: ## Related)
create_sectionbooleanCreate section if missing (default: true)
vault_add_links({
  path: "research/caching.md",
  links: [
    { target: "decisions/ADR-003-caching.md", annotation: "supersedes this earlier approach" },
    { target: "research/architecture-patterns.md", annotation: "foundational patterns referenced" }
  ]
})

vault_link_health (Graph Health Report)

Audit link quality across the vault or a specific folder. Returns categorized report of link issues.

  • orphans: Notes with zero incoming AND zero outgoing wikilinks
  • broken: Wikilinks that resolve to no existing file
  • weak: Notes with only 1 total resolved link (incoming + outgoing; broken links don't count)
  • ambiguous: Wikilinks where basename resolves to multiple files
ParameterTypeDescription
folderstringOptional: scope to folder (fuzzy resolution supported)
checksarrayWhich checks: orphans, broken, weak, ambiguous (default: all)
limitnumberMax results per category (default: 20)
vault_link_health({ folder: "01-Projects/MyApp", checks: ["orphans", "broken"] })

Implementation: handleLinkHealth in handlers.js, uses buildIncomingIndex from graph.js for O(M) performance.

vault_query (Enhanced Filtering and Sorting)

In addition to the standard filters (type, status, tags [ALL must match], tags_any [ANY must match], dates, folder), vault_query supports:

  • custom_fields — filter by arbitrary frontmatter fields (exact match); use null to match notes where a field is missing
  • sort_by — sort results by any frontmatter field; smart ordering for priority (urgent > high > normal > low), chronological for dates, alphabetical otherwise; nulls sort last
  • sort_order — "asc" (default) or "desc"
vault_query({ type: "task", custom_fields: { priority: "high" }, sort_by: "due" })
vault_query({ tags: ["task"], sort_by: "priority", sort_order: "asc" })
vault_query({ custom_fields: { project: "MyApp", due: null } })  // tasks with no due date

Fuzzy Path Resolution

Read-only tools (vault_read, vault_peek, vault_links, vault_neighborhood, vault_suggest_links) support fuzzy path resolution:

  • Exact paths still work as before (zero overhead)
  • Short names resolve by basename: "devlog" → "01-Projects/MyApp/development/devlog.md"
  • .md extension is optional: "devlog" and "devlog.md" both work
  • Ambiguous names (multiple files with same basename) return an error listing all candidates
  • Use a more specific path or the folder param to disambiguate

Folder-scoped tools (vault_list, vault_search, vault_query, vault_tags, vault_recent, vault_link_health) support fuzzy folder resolution:

  • Exact folder paths still work as before
  • Partial names match by substring: "MyApp" → "01-Projects/MyApp"
  • Ambiguous matches return an error listing candidates

Write/destructive tools (vault_write, vault_append, vault_edit, vault_update_frontmatter, vault_trash, vault_move, vault_add_links) require exact paths to prevent accidental modifications.

Implementation: helpers.js (buildBasenameMap, resolveFuzzyPath, resolveFuzzyFolder)

PKM Agents

The plugin provides 3 specialized agents (visible in /agents). Delegate to them proactively:

AgentWhen to DelegateMode
vault-explorerBefore creating notes on a topic, when researching existing knowledgeForeground
pkm-captureAfter git commits (automatic via hook), after significant work blocks, before session endsBackground
link-auditorAfter creating/modifying multiple vault notes, periodic health checksBackground

pkm-capture context: When delegating, include whether this is the first capture this session or a subsequent one (with previous entry timestamp). The agent discovers the transcript path itself. It handles both devlog entries and knowledge capture (decisions, research, tasks, bugs) in one pass. Conservative — most exchanges produce nothing worth capturing beyond the devlog entry.

Templates (templates/): Obsidian note templates for project documentation:

  • project-index.md - Project overview with YAML frontmatter
  • adr.md - Architecture Decision Record format
  • devlog.md - Development log with session entries
  • permanent-note.md - Atomic evergreen notes
  • research-note.md - Research findings and analysis
  • troubleshooting-log.md - Bug investigations and fixes
  • fleeting-note.md - Quick captures and temporary thoughts
  • literature-note.md - Notes on articles, books, talks
  • meeting-notes.md - Meeting records
  • moc.md - Maps of Content (index/hub notes)
  • daily-note.md - Daily notes
  • task.md - Structured task notes with status, priority, due date, project, and source fields
  • note.md - Minimal generic note

Sample CLAUDE.md (sample-project/CLAUDE.md): Template for code repositories to specify PKM integration paths, context loading, and documentation rules.

Claude Code Configuration

claude plugin marketplace add anthropics/claude-plugins-community
claude plugin install vault-pkm@claude-community

Then run /vault-pkm:setup in Claude Code to configure vault path, API keys, and permissions.

For vault scaffolding (templates, PARA folders): npx obsidian-pkm init

VAULT_PKM_OPENAI_KEY (or OPENAI_API_KEY) is optional — without it, all tools except vault_semantic_search and vault_suggest_links work normally. The plugin-scoped name avoids conflicts with project-level OpenAI keys. OBSIDIAN_PKM_OPENAI_KEY is still read as a deprecated fallback for users who configured it before the rename.

Vault Structure Convention

Vault/
├── 00-Inbox/
├── 01-Projects/           # Active projects
│   └── ProjectName/
│       ├── _index.md
│       ├── planning/
│       ├── research/
│       └── development/decisions/
├── 02-Areas/
├── 03-Resources/Development/  # Reusable knowledge
├── 04-Archive/
├── 05-Templates/
└── 06-System/

Key Conventions

  • ADR naming: ADR-{NNN}-{kebab-title}.md
  • Project index files: _index.md
  • All notes use YAML frontmatter with type, status, created fields
  • Paths passed to MCP tools are relative to vault root
  • Version bumps must update BOTH files: package.json AND .claude-plugin/plugin.json. The plugin system reads version from plugin.json, not package.json — forgetting plugin.json causes updates to appear stuck.

Metadata Schema

Canonical reference: 06-System/metadata-schema.md

When creating ANY note via MCP, ALWAYS include frontmatter:

---
type: <type>        # Required: see schema for allowed values
created: YYYY-MM-DD # Required
tags: [...]         # Required: at least one tag
status: <status>    # If applicable for the type
---

Common types: fleeting, research, adr, bug, planning, transcript, permanent, task

Never create notes without frontmatter — even quick research docs or ad-hoc files.

PKM Integration

  • Vault project: 01-Projects/Obsidian-MCP/
  • MCP Server: vault-pkm plugin

Document decisions, research findings, and debugging sessions as you work. The pkm-capture agent captures devlog entries and PKM-worthy content in the background (triggered automatically after git commits), or use the vault-pkm:pkm-write skill for structured notes with linking.

Use vault-pkm:pkm-explore to research what the vault already knows about a topic before creating new content.

At the end of each session, run vault-pkm:pkm-session-end to update the devlog and capture undocumented work.

Use vault-pkm:triage-tasks to surface and batch-update open task statuses (numbered list, shorthand input like "1,3 done | 2 active"). Use vault-pkm:add-task for fast task capture from the conversation. Use vault-pkm:tackle-task to work on a specific task end-to-end: reads the note, explores vault context, routes to the right workflow (trivial/standard/significant), and closes the task when done.

Referring to vault files

Whenever you mention a vault note, PKM file, or file inside 01-Projects/Obsidian-MCP/ in your response to the user — whether quoting tool output, summarizing what you read, or referring to a file by name — format it as a markdown link to its obsidian:// URI so the user can click to open it in Obsidian:

[01-Projects/Obsidian-MCP/some/note.md](obsidian://open?vault=PKM&file=01-Projects%2FObsidian-MCP%2Fsome%2Fnote)

Encoding rules: percent-encode / as %2F and spaces as %20. Strip the trailing .md from the URL file= parameter, but keep .md in the visible link text. The vault name (PKM) is also visible in any vault-pkm tool output.

The vault-pkm MCP tools already emit paths in this format. Preserve the link form when relaying; don't revert to bare paths like 01-Projects/Obsidian-MCP/... for inline mentions. Apply the same format proactively when mentioning a vault file you haven't just queried (e.g., when answering "what's in the devlog?" or "see ADR-002").

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.