Obsidian Hello World
Overview
Build a minimal working Obsidian plugin demonstrating the five core building blocks: commands (palette + editor + checkCallback), settings tab with typed config, ribbon icons, modals, and status bar. Every snippet uses real Obsidian API.
Prerequisites
- Completed
obsidian-install-auth setup (symlinked dev vault, npm run dev working)
- Build pipeline producing
main.js from src/main.ts
Instructions
Step 1: Define Typed Settings
// src/main.ts — top of file
import {
App, Editor, MarkdownView, Modal, Notice,
Plugin, PluginSettingTab, Setting, TFile
} from 'obsidian';
interface MyPluginSettings {
greeting: string;
showRibbon: boolean;
dateFormat: string;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
greeting: 'Hello, Obsidian!',
showRibbon: true,
dateFormat: 'YYYY-MM-DD',
};
Step 2: Create the Plugin Class with Commands
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
async onload() {
await this.loadSettings();
// Ribbon icon — shows greeting as Notice
if (this.settings.showRibbon) {
this.addRibbonIcon('sparkles', 'My Plugin: Greet', () => {
new Notice(this.settings.greeting);
});
}
// Command: show greeting (available everywhere)
this.addCommand({
id: 'show-greeting',
name: 'Show greeting',
callback: () => new Notice(this.settings.greeting),
});
// Command: insert greeting at cursor (editor-only — greyed out when no editor is active)
this.addCommand({
id: 'insert-greeting',
name: 'Insert greeting at cursor',
editorCallback: (editor: Editor, view: MarkdownView) => {
editor.replaceSelection(this.settings.greeting);
},
});
// Command: word count with checkCallback (conditionally available)
this.addCommand({
id: 'count-words',
name: 'Count words in current note',
checkCallback: (checking: boolean) => {
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (view) {
if (!checking) {
const text = view.editor.getValue();
const count = text.split(/\s+/).filter(Boolean).length;
new Notice(`Word count: ${count}`);
}
return true; // command is available
}
return false; // hide from palette when no editor
},
});
// Command: open modal dialog
this.addCommand({
id: 'show-greeting-modal',
name: 'Show greeting modal',
callback: () => new GreetingModal(this.app, this.settings.greeting).open(),
});
// Command: insert today's date
this.addCommand({
id: 'insert-date',
name: 'Insert today's date',
editorCallback: (editor: Editor) => {
const today = new Date().toISOString().slice(0, 10);
editor.replaceSelection(today);
},
});
// Status bar — persistent widget at bottom
const statusEl = this.addStatusBarItem();
statusEl.setText('Plugin loaded');
// Update status bar when active file changes
this.registerEvent(
this.app.workspace.on('active-leaf-change', () => {
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (view) {
const count = view.editor.getValue().split(/\s+/).filter(Boolean).length;
statusEl.setText(`Words: ${count}`);
} else {
statusEl.setText('No editor');
}
})
);
// Settings tab
this.addSettingTab(new MySettingTab(this.app, this));
console.log(`[${this.manifest.id}] loaded`);
}
onunload() {
console.log(`[${this.manifest.id}] unloaded`);
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}
Step 3: Create Settings Tab
class MySettingTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName('Greeting message')
.setDesc('Text shown by the greet command and ribbon icon.')
.addText(text => text
.setPlaceholder('Hello, Obsidian!')
.setValue(this.plugin.settings.greeting)
.onChange(async (value) => {
this.plugin.settings.greeting = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Show ribbon icon')
.setDesc('Toggle the sparkles icon in the left ribbon. Reload plugin to apply.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.showRibbon)
.onChange(async (value) => {
this.plugin.settings.showRibbon = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Date format')
.setDesc('Format for the Insert Date command.')
.addDropdown(dropdown => dropdown
.addOption('YYYY-MM-DD', '2026-03-22')
.addOption('MM/DD/YYYY', '03/22/2026')
.addOption('DD.MM.YYYY', '22.03.2026')
.setValue(this.plugin.settings.dateFormat)
.onChange(async (value) => {
this.plugin.settings.dateFormat = value;
await this.plugin.saveSettings();
}));
}
}
Step 4: Create a Modal
class GreetingModal extends Modal {
message: string;
constructor(app: App, message: string) {
super(app);
this.message = message;
}
onOpen() {
const { contentEl } = this;
contentEl.createEl('h2', { text: this.message });
contentEl.createEl('p', { text: 'This is a modal dialog from your plugin.' });
// Add a button that does something
const btn = contentEl.createEl('button', { text: 'Count vault files' });
btn.addEventListener('click', () => {
const count = this.app.vault.getMarkdownFiles().length;
contentEl.createEl('p', { text: `Your vault has ${count} markdown files.` });
});
}
onClose() {
this.contentEl.empty();
}
}
Step 5: Build and Test
set -euo pipefail
npm run build
# In Obsidian:
# 1. Settings > Community plugins > Enable your plugin
# 2. Click the sparkles icon in the ribbon
# 3. Ctrl+P > "Show greeting"
# 4. Ctrl+P > "Count words in current note" (open a .md file first)
# 5. Ctrl+P > "Show greeting modal"
# 6. Settings > My Plugin > change the greeting
# 7. Check the status bar at bottom for word count
Step 6: Listen to Vault Events
// Add to onload() — react to file changes
this.registerEvent(
this.app.workspace.on('file-open', (file: TFile | null) => {
if (file) {
console.log(`[${this.manifest.id}] Opened: ${file.path}`);
}
})
);
// Track file modifications (debounce for production — see obsidian-rate-limits)
this.registerEvent(
this.app.vault.on('create', (file) => {
if (file instanceof TFile) {
new Notice(`New file: ${file.basename}`);
}
})
);
Output
- Working plugin with:
- Three command types:
callback, editorCallback, checkCallback
- Settings tab with text, toggle, and dropdown controls
- Ribbon icon with click handler
- Modal dialog with interactive button
- Status bar widget with live word count
- Event listeners for file-open and file-create
Error Handling
| Error |
Cause |
Solution |
| Plugin not loading |
Build errors or bad manifest |
Check console (Ctrl+Shift+I) for red errors |
| Settings not saving |
Missing await on saveData |
Always await this.saveSettings() in onChange |
| Command greyed out |
editorCallback needs active editor |
Open a markdown note, or use callback instead |
| Ribbon icon missing |
Invalid icon name |
Use Lucide icon names: sparkles, file-text, search |
| Status bar not updating |
Event not registered |
Wrap in this.registerEvent() for auto-cleanup |
| Settings reset on restart |
Forgot saveData call |
loadData returns null on first run — Object.assign handles this |
Examples
Available Lucide Icon Names
Obsidian uses Lucide icons. Common examples:
file-text, folder, search, settings, star
heart, bookmark, tag, link, external-link
edit, trash-2, copy, clipboard, check
dice, bot, sparkles, wand, calendar
bar-chart-2, globe, download, upload
Command Types Summary
| Type |
When Available |
Use Case |
callback |
Always |
Non-editor commands (open modal, toggle feature) |
editorCallback |
When editor is active |
Insert text, transform selection |
checkCallback |
Conditionally |
Show/hide based on context |
Register a Hotkey-Ready Command
// Users assign hotkeys in Settings > Hotkeys
this.addCommand({
id: 'toggle-feature',
name: 'Toggle my feature',
callback: () => this.toggleFeature(),
});
Resources
Next Steps
- Set up hot-reload development:
obsidian-local-dev-loop
- Build advanced UI (views, fuzzy search, context menus):
obsidian-core-workflow-b
- Apply production patterns:
obsidian-sdk-patterns
Source: jeremylongshore/claude-code-plugins-plus-skills → plugins/saas-packs/obsidian-pack/skills/obsidian-hello-world/SKILL.md
1---2name: obsidian-hello-world3description: "'Create a minimal working Obsidian plugin with commands, settings, modals, and ribbon icons. Use when building your first plugin feature, testing your setup, or learning basic Obsidian plugin patterns. Trigger with phrases like \"obsidian hello world\", \"first obsidian plugin\", \"obsidian quick start\", \"simple obsidian plugin\". '"4allowed-tools: "Read, Write, Edit, Bash(npm:*), Glob"5category: docs-and-knowledge-mgmt6source_repo: jeremylongshore/claude-code-plugins-plus-skills7source_path: "plugins/saas-packs/obsidian-pack/skills/obsidian-hello-world/SKILL.md"8source_url: https://github.com/jeremylongshore/claude-code-plugins-plus-skills/blob/HEAD/plugins/saas-packs/obsidian-pack/skills/obsidian-hello-world/SKILL.md9---1011# Obsidian Hello World1213## Overview1415Build a minimal working Obsidian plugin demonstrating the five core building blocks: commands (palette + editor + checkCallback), settings tab with typed config, ribbon icons, modals, and status bar. Every snippet uses real Obsidian API.1617## Prerequisites1819- Completed `obsidian-install-auth` setup (symlinked dev vault, `npm run dev` working)20- Build pipeline producing `main.js` from `src/main.ts`2122## Instructions2324### Step 1: Define Typed Settings2526```typescript27// src/main.ts — top of file28import {29 App, Editor, MarkdownView, Modal, Notice,30 Plugin, PluginSettingTab, Setting, TFile31} from 'obsidian';3233interface MyPluginSettings {34 greeting: string;35 showRibbon: boolean;36 dateFormat: string;37}3839const DEFAULT_SETTINGS: MyPluginSettings = {40 greeting: 'Hello, Obsidian!',41 showRibbon: true,42 dateFormat: 'YYYY-MM-DD',43};44```4546### Step 2: Create the Plugin Class with Commands4748```typescript49export default class MyPlugin extends Plugin {50 settings: MyPluginSettings;5152 async onload() {53 await this.loadSettings();5455 // Ribbon icon — shows greeting as Notice56 if (this.settings.showRibbon) {57 this.addRibbonIcon('sparkles', 'My Plugin: Greet', () => {58 new Notice(this.settings.greeting);59 });60 }6162 // Command: show greeting (available everywhere)63 this.addCommand({64 id: 'show-greeting',65 name: 'Show greeting',66 callback: () => new Notice(this.settings.greeting),67 });6869 // Command: insert greeting at cursor (editor-only — greyed out when no editor is active)70 this.addCommand({71 id: 'insert-greeting',72 name: 'Insert greeting at cursor',73 editorCallback: (editor: Editor, view: MarkdownView) => {74 editor.replaceSelection(this.settings.greeting);75 },76 });7778 // Command: word count with checkCallback (conditionally available)79 this.addCommand({80 id: 'count-words',81 name: 'Count words in current note',82 checkCallback: (checking: boolean) => {83 const view = this.app.workspace.getActiveViewOfType(MarkdownView);84 if (view) {85 if (!checking) {86 const text = view.editor.getValue();87 const count = text.split(/\s+/).filter(Boolean).length;88 new Notice(`Word count: ${count}`);89 }90 return true; // command is available91 }92 return false; // hide from palette when no editor93 },94 });9596 // Command: open modal dialog97 this.addCommand({98 id: 'show-greeting-modal',99 name: 'Show greeting modal',100 callback: () => new GreetingModal(this.app, this.settings.greeting).open(),101 });102103 // Command: insert today's date104 this.addCommand({105 id: 'insert-date',106 name: 'Insert today's date',107 editorCallback: (editor: Editor) => {108 const today = new Date().toISOString().slice(0, 10);109 editor.replaceSelection(today);110 },111 });112113 // Status bar — persistent widget at bottom114 const statusEl = this.addStatusBarItem();115 statusEl.setText('Plugin loaded');116117 // Update status bar when active file changes118 this.registerEvent(119 this.app.workspace.on('active-leaf-change', () => {120 const view = this.app.workspace.getActiveViewOfType(MarkdownView);121 if (view) {122 const count = view.editor.getValue().split(/\s+/).filter(Boolean).length;123 statusEl.setText(`Words: ${count}`);124 } else {125 statusEl.setText('No editor');126 }127 })128 );129130 // Settings tab131 this.addSettingTab(new MySettingTab(this.app, this));132 console.log(`[${this.manifest.id}] loaded`);133 }134135 onunload() {136 console.log(`[${this.manifest.id}] unloaded`);137 }138139 async loadSettings() {140 this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());141 }142143 async saveSettings() {144 await this.saveData(this.settings);145 }146}147```148149### Step 3: Create Settings Tab150151```typescript152class MySettingTab extends PluginSettingTab {153 plugin: MyPlugin;154155 constructor(app: App, plugin: MyPlugin) {156 super(app, plugin);157 this.plugin = plugin;158 }159160 display(): void {161 const { containerEl } = this;162 containerEl.empty();163164 new Setting(containerEl)165 .setName('Greeting message')166 .setDesc('Text shown by the greet command and ribbon icon.')167 .addText(text => text168 .setPlaceholder('Hello, Obsidian!')169 .setValue(this.plugin.settings.greeting)170 .onChange(async (value) => {171 this.plugin.settings.greeting = value;172 await this.plugin.saveSettings();173 }));174175 new Setting(containerEl)176 .setName('Show ribbon icon')177 .setDesc('Toggle the sparkles icon in the left ribbon. Reload plugin to apply.')178 .addToggle(toggle => toggle179 .setValue(this.plugin.settings.showRibbon)180 .onChange(async (value) => {181 this.plugin.settings.showRibbon = value;182 await this.plugin.saveSettings();183 }));184185 new Setting(containerEl)186 .setName('Date format')187 .setDesc('Format for the Insert Date command.')188 .addDropdown(dropdown => dropdown189 .addOption('YYYY-MM-DD', '2026-03-22')190 .addOption('MM/DD/YYYY', '03/22/2026')191 .addOption('DD.MM.YYYY', '22.03.2026')192 .setValue(this.plugin.settings.dateFormat)193 .onChange(async (value) => {194 this.plugin.settings.dateFormat = value;195 await this.plugin.saveSettings();196 }));197 }198}199```200201### Step 4: Create a Modal202203```typescript204class GreetingModal extends Modal {205 message: string;206207 constructor(app: App, message: string) {208 super(app);209 this.message = message;210 }211212 onOpen() {213 const { contentEl } = this;214 contentEl.createEl('h2', { text: this.message });215 contentEl.createEl('p', { text: 'This is a modal dialog from your plugin.' });216217 // Add a button that does something218 const btn = contentEl.createEl('button', { text: 'Count vault files' });219 btn.addEventListener('click', () => {220 const count = this.app.vault.getMarkdownFiles().length;221 contentEl.createEl('p', { text: `Your vault has ${count} markdown files.` });222 });223 }224225 onClose() {226 this.contentEl.empty();227 }228}229```230231### Step 5: Build and Test232233```bash234set -euo pipefail235npm run build236237# In Obsidian:238# 1. Settings > Community plugins > Enable your plugin239# 2. Click the sparkles icon in the ribbon240# 3. Ctrl+P > "Show greeting"241# 4. Ctrl+P > "Count words in current note" (open a .md file first)242# 5. Ctrl+P > "Show greeting modal"243# 6. Settings > My Plugin > change the greeting244# 7. Check the status bar at bottom for word count245```246247### Step 6: Listen to Vault Events248249```typescript250// Add to onload() — react to file changes251this.registerEvent(252 this.app.workspace.on('file-open', (file: TFile | null) => {253 if (file) {254 console.log(`[${this.manifest.id}] Opened: ${file.path}`);255 }256 })257);258259// Track file modifications (debounce for production — see obsidian-rate-limits)260this.registerEvent(261 this.app.vault.on('create', (file) => {262 if (file instanceof TFile) {263 new Notice(`New file: ${file.basename}`);264 }265 })266);267```268269## Output270271- Working plugin with:272 - Three command types: `callback`, `editorCallback`, `checkCallback`273 - Settings tab with text, toggle, and dropdown controls274 - Ribbon icon with click handler275 - Modal dialog with interactive button276 - Status bar widget with live word count277 - Event listeners for file-open and file-create278279## Error Handling280281| Error | Cause | Solution |282|-------|-------|----------|283| Plugin not loading | Build errors or bad manifest | Check console (Ctrl+Shift+I) for red errors |284| Settings not saving | Missing `await` on `saveData` | Always `await this.saveSettings()` in `onChange` |285| Command greyed out | `editorCallback` needs active editor | Open a markdown note, or use `callback` instead |286| Ribbon icon missing | Invalid icon name | Use Lucide icon names: `sparkles`, `file-text`, `search` |287| Status bar not updating | Event not registered | Wrap in `this.registerEvent()` for auto-cleanup |288| Settings reset on restart | Forgot `saveData` call | `loadData` returns null on first run — `Object.assign` handles this |289290## Examples291292### Available Lucide Icon Names293294Obsidian uses [Lucide icons](https://lucide.dev/icons/). Common examples:295296- `file-text`, `folder`, `search`, `settings`, `star`297- `heart`, `bookmark`, `tag`, `link`, `external-link`298- `edit`, `trash-2`, `copy`, `clipboard`, `check`299- `dice`, `bot`, `sparkles`, `wand`, `calendar`300- `bar-chart-2`, `globe`, `download`, `upload`301302### Command Types Summary303304| Type | When Available | Use Case |305|------|---------------|----------|306| `callback` | Always | Non-editor commands (open modal, toggle feature) |307| `editorCallback` | When editor is active | Insert text, transform selection |308| `checkCallback` | Conditionally | Show/hide based on context |309310### Register a Hotkey-Ready Command311312```typescript313// Users assign hotkeys in Settings > Hotkeys314this.addCommand({315 id: 'toggle-feature',316 name: 'Toggle my feature',317 callback: () => this.toggleFeature(),318});319```320321## Resources322323- [Obsidian Plugin API](https://docs.obsidian.md/Reference/TypeScript+API)324- [Plugin Development Workflow](https://docs.obsidian.md/Plugins/Getting+started/Development+workflow)325- [Lucide Icons](https://lucide.dev/icons/) — icon names for `addRibbonIcon`326- [Obsidian Hub](https://publish.obsidian.md/hub/) — community knowledge base327328## Next Steps329330- Set up hot-reload development: `obsidian-local-dev-loop`331- Build advanced UI (views, fuzzy search, context menus): `obsidian-core-workflow-b`332- Apply production patterns: `obsidian-sdk-patterns`333334---335336**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `plugins/saas-packs/obsidian-pack/skills/obsidian-hello-world/SKILL.md`