Obsidian Plugin Development
How to develop Obsidian Community Plugins
Summary Concepts
Mental model
- Plugin = TypeScript/JS bundle (
main.js) +manifest.json(+ optionalstyles.css), loaded into Obsidian’s Electron renderer (desktop) or WebView (mobile). - Runs in-process with full access to the app. No sandbox, so you own the performance and safety.
- Entry point: a class extending
Pluginwithonload()/onunload().
Toolchain
- Start from
obsidianmd/obsidian-sample-plugin: TypeScript, esbuild, npm. - Dev loop: clone into
<vault>/.obsidian/plugins/<id>/, runnpm run dev(watch build), then reload with the Hot Reload plugin or Ctrl+R. - Use a dedicated test vault, not your real one.
- Types come from the
obsidianpackage (obsidian.d.tsis the best docs).
Core API surface
app.vault: file I/O (read,cachedRead,modify,create,process). Useprocessfor atomic read-modify-write.app.metadataCache: parsed frontmatter, tags, links, headings. Use this instead of re-parsing files yourself. Tag queries need it.app.workspace: leaves, views, active file, layout events.app.fileManager: rename/delete that keeps links intact, plusprocessFrontMatter.- UI:
addCommand,addRibbonIcon,addSettingTab,Modal,Notice,SuggestModal/FuzzySuggestModal,ItemView(custom panes),registerView. - Editor:
editorCallbackcommands; CodeMirror 6 extensions viaregisterEditorExtensionfor decorations/live preview. - Markdown:
registerMarkdownPostProcessor,registerMarkdownCodeBlockProcessorfor rendering.
Lifecycle and hygiene (where people go wrong)
- Register everything through
this.registerEvent,registerDomEvent,registerInterval. Obsidian cleans these up on unload. Raw listeners leak. - Don’t touch the vault at load time. Wait for
app.workspace.onLayoutReady(), or you getcreateevents for every existing file. - Persist settings via
loadData()/saveData()(data.json). Merge with defaults:Object.assign({}, DEFAULTS, await this.loadData()). - Debounce
metadataCache.on('changed')andvault.on('modify'). They fire a lot. - Mobile: avoid Node/Electron APIs (
fs,path) unlessisDesktopOnly: true.
Release
- GitHub release with
main.js,manifest.json,styles.css, then PR toobsidianmd/obsidian-releases. - Follow the plugin guidelines: no telemetry without consent, no
innerHTMLwith user content, and clean up on unload.
### Architecture advice (given my background)
- Keep Obsidian-coupled code thin. Put pure logic (e.g. tag-set algebra, filtering) in plain TS modules with no
obsidianimports, so it’s unit-testable with vitest/jest. - Treat
App/Vaultas an adapter boundary: define a small interface, inject it, and mock it in tests. The Obsidian API can’t be run headless. - Prefer immutable data and pure functions for the domain model. TS handles this well with discriminated unions and
readonly. - Build indexes once from
metadataCache, then update them incrementally from events. Don’t rescan the vault per query. - Settings are a versioned schema, so plan migrations early.
Resources
- docs.obsidian.md/Plugins (guides plus API reference)
obsidianmd/obsidian-apirepo (obsidian.d.ts)obsidianmd/obsidian-sample-plugin- Read the source of well-known plugins (Dataview, Templater) for patterns.