Skip to content

First plugin

A minimal plugin registers work during load and cleans it up during unload.

module.exports = class ExamplePlugin {
constructor(app, manifest) {
this.app = app;
this.manifest = manifest;
}
async onload() {
this.app.commands.register({
id: "example-plugin:hello",
name: "Say hello",
callback: () => this.app.notices.show("Hello from a plugin"),
});
}
async onunload() {
// Dispose subscriptions, views, timers, and resources here.
}
};

Put manifest.json and main.js in .obsidian/plugins/example-plugin/, then enable the plugin from settings.

Use documented services for commands, notices, vault access, settings, and events. Avoid reaching into DOM or workspace internals unless the API explicitly allows it.