/obsidian-toolkit:obsidian-api-basicsfrom obsidian-toolkit
This skill should be used when the user asks to "create an Obsidian plugin", "plugin lifecycle", "plugin settings", "vault API", "register command", "add ribbon icon", or mentions Obsidian plugin fundamentals like onload, onunload, saveData, or loadData.
Ships in obsidian-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Provides foundational guidance for building Obsidian plugins, covering the plugin lifecycle, settings patterns, vault operations, and command registration.
Every Obsidian plugin extends the Plugin base class and implements lifecycle methods:
import { Plugin } from 'obsidian';
export default class MyPlugin extends Plugin {
async onload() {
// Plugin initialization
console.debug('Plugin loaded');
}
async onunload() {
// Cleanup
console.debug('Plugin unloaded');
}
}
Critical rules:
main.ts small - delegate functionality to separate modulesonload() for initialization, registration, and setuponunload() for cleanup (most cleanup happens automatically)Implement user-configurable settings with persistence:
interface MyPluginSettings {
serverUrl: string;
apiKey: string;
enabled: boolean;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
serverUrl: 'http://localhost:3000',
apiKey: '',
enabled: true,
};
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
async onload() {
await this.loadSettings();
this.addSettingTab(new MySettingTab(this.app, this));
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}
Pattern guidelines:
Object.assign() to merge defaults with saved dataloadSettings() in onload()saveSettings() after any settings changeRegister commands that appear in the command palette:
this.addCommand({
id: 'open-view', // Do NOT include plugin ID - Obsidian namespaces automatically
name: 'Open my view', // Use sentence case
callback: () => {
void this.activateView();
}
});
Command rules:
id fieldname, not Title CaseAdd icons to the left sidebar ribbon:
this.addRibbonIcon('dice', 'Open my plugin', () => {
void this.openView();
});
Icon options:
Access vault files and content through the App API:
// Get active file
const activeFile = this.app.workspace.getActiveFile();
if (activeFile) {
// Read file content
const content = await this.app.vault.read(activeFile);
// Modify file
await this.app.vault.modify(activeFile, newContent);
}
// Get all markdown files
const files = this.app.vault.getMarkdownFiles();
// Get file by path
const file = this.app.vault.getAbstractFileByPath('folder/note.md');
Vault API patterns:
TFile type for files, TFolder for foldersAccess parsed frontmatter and metadata without file I/O:
const file = this.app.workspace.getActiveFile();
if (file) {
const cache = this.app.metadataCache.getFileCache(file);
const frontmatter = cache?.frontmatter;
const links = cache?.links;
const headings = cache?.headings;
}
Cache considerations:
metadataCache.on('changed') for updatesRegister and auto-cleanup event listeners:
this.registerEvent(
this.app.workspace.on('active-leaf-change', () => {
// Handle active file change
})
);
this.registerInterval(
window.setInterval(() => {
// Periodic task
}, 5000)
);
Cleanup patterns:
registerEvent() for workspace eventsregisterInterval() for timersOrganize plugin code for maintainability:
src/
main.ts # Plugin entry point - lifecycle ONLY
settings.ts # Settings interface and tab
constants.ts # Constants, view type IDs
api/ # External API clients
ui/ # UI components, views
commands/ # Command implementations
types.ts # TypeScript interfaces
Organization principles:
main.ts should be <100 linesStandard esbuild setup for Obsidian plugins:
// esbuild.config.mjs
import esbuild from 'esbuild';
const production = process.argv.includes('--production');
esbuild.build({
entryPoints: ['src/main.ts'],
bundle: true,
external: ['obsidian', 'electron'],
format: 'cjs',
target: 'es2018',
outfile: 'main.js',
platform: 'node',
minify: production,
sourcemap: production ? false : 'inline',
}).catch(() => process.exit(1));
Build requirements:
main.js in plugin rootmain.js or node_modules/Required files for distribution:
main.js - Bundled plugin codemanifest.json - Plugin metadatastyles.css - Optional stylesManifest structure:
{
"id": "my-plugin",
"name": "My Plugin",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "Brief description",
"author": "Your Name",
"authorUrl": "https://yoursite.com",
"isDesktopOnly": false
}
Handle async setup in onload:
async onload() {
await this.loadSettings();
// Initialize async resources
await this.initializeServer();
// Register components
this.registerView(VIEW_TYPE, (leaf) => new MyView(leaf, this));
this.addCommand({...});
}
Handle errors gracefully:
try {
await this.performOperation();
} catch (error) {
console.error('Operation failed:', error);
new Notice('Operation failed. See console for details.');
}
Use Notice for user-facing errors, console.error for debugging.
Clean up resources in onunload:
async onunload() {
// Stop servers
await this.stopServer();
// Clear timers (if not using registerInterval)
if (this.timer) {
clearInterval(this.timer);
}
// Most cleanup is automatic via register* methods
}
For detailed information:
references/api-reference.md - Complete Obsidian API surfacereferences/workspace-api.md - Workspace and view managementreferences/vault-advanced.md - Advanced vault operationsWorking examples in examples/:
minimal-plugin.ts - Minimal viable pluginsettings-example.ts - Complete settings implementationReference the official Obsidian resources:
After mastering these basics:
obsidian-dom-helpers skillobsidian-best-practices skillobsidian-chat-ui skillobsidian-mcp-server skillWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
4 skills in this plugin
/obsidian-chat-uiThis skill should be used when the user asks to "create chat interface", "build sidebar", "ItemView", "streaming messages", "chat sidebar", "copilot UI", or mentions building chat or conversational interfaces in Obsidian plugins./obsidian-cliThis skill should be used when the user asks about "obsidian cli", "command line interface for obsidian", "automate obsidian", "script obsidian vault", "obsidian terminal commands", or wants to interact with their Obsidian vault from the command line for automation, scripting, or integration purposes./obsidian-mcp-serverThis skill should be used when the user asks to "add MCP server", "Model Context Protocol", "expose vault tools", "Streamable HTTP", "MCP tools", or mentions integrating MCP servers in Obsidian plugins to expose vault operations.npx claudepluginhub hsb3/dotfiles-agents --plugin obsidian-toolkit