# Add a Custom Sidebar View to an Obsidian Plugin

Yes. An agent adds an ItemView class, registers it, opens it in the right sidebar from a ribbon icon and a command, styles it in styles.css, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-custom-view/obsidian-plugin/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the plugin's shape before it adds a view. In a plugin built from obsidianmd/obsidian-sample-plugin, `package.json` is `type: module` with `dev`, `build` (`tsc -noEmit -skipLibCheck && node esbuild.config.mjs production`), `version` and `lint` scripts, and dev dependencies `esbuild` 0.25.5, `typescript` `^5.8.3`, `eslint` `^9.39.4` with `eslint-plugin-obsidianmd` `^0.4.0`, `typescript-eslint` and `obsidian` at `latest`. `esbuild.config.mjs` bundles `src/main.ts` to `main.js` as CommonJS for `es2021` with `obsidian`, `electron` and the CodeMirror packages external. `manifest.json` is `sample-plugin` with `minAppVersion` `1.0.0` and `isDesktopOnly: false`. `src/main.ts` has `MyPlugin.onload` adding a `dice` ribbon icon that shows a `Notice`, a status bar item, three commands (`open-modal-simple`, `replace-selected`, `open-modal-complex`), the settings tab from `src/settings.ts`, a `registerDomEvent` on click and a `registerInterval`; `SampleModal` is the only UI. `AGENTS.md` asks for code split into `src/commands`, `src/ui` and `src/utils` with `main.ts` kept to lifecycle, `tsconfig.json` is `strict` with `noUncheckedIndexedAccess`, `.github/workflows/lint.yml` runs `npm ci`, `npm run build` and `npm run lint` on Node 20, 22 and 24, and `release.yml` attaches `main.js`, `manifest.json` and `styles.css` to a draft release on a tag. `styles.css` is an empty placeholder and `main.js` is gitignored.

The agent adds `src/ui/sample-view.ts` following the layout `AGENTS.md` asks for: `export const VIEW_TYPE_SAMPLE = 'sample-view'` and `class SampleView extends ItemView` with `getViewType()` returning that constant, `getDisplayText()` returning `Sample view`, `getIcon()` returning `dice`, an `onOpen()` that builds the pane with `contentEl.createEl('h4', { text: … })` and `createDiv({ cls: 'sample-view' })` rather than `innerHTML`, and an `onClose()` that empties `contentEl`. The view takes the plugin in its constructor so it can read `this.plugin.settings.mySetting` and gets a `refresh()` the settings tab calls after `saveSettings()`, so a changed setting shows without reopening the pane.

In `src/main.ts`, `onload` calls `this.registerView(VIEW_TYPE_SAMPLE, (leaf) => new SampleView(leaf, this))` and gains an `activateView()` method: it looks for an open instance with `workspace.getLeavesOfType(VIEW_TYPE_SAMPLE)`, otherwise takes `workspace.getRightLeaf(false)` and awaits `leaf.setViewState({ type: VIEW_TYPE_SAMPLE, active: true })`, then `workspace.revealLeaf(leaf)`. The `dice` ribbon icon now opens the view instead of a `Notice`, and a new command `open-sample-view` named `Open sample view` does the same from the command palette. `onunload` stays empty: the agent does not call `detachLeavesOfType` there, because the current plugin guidelines say to leave open leaves for Obsidian to restore, and it writes that reasoning in the pull request. A `showViewOnStartup` boolean is added to `MyPluginSettings` and `DEFAULT_SETTINGS` with an `addToggle` row in `SampleSettingTab`, and `onload` registers an `onLayoutReady` callback that calls `activateView()` when it is on, so nothing opens before the workspace exists. The `.sample-view` rules go in `styles.css`, which the release workflow already ships.

There is no test runner in the repository and no Obsidian in the sandbox, so the proof is the toolchain: the agent runs `npm ci`, `npm run build` (the `tsc -noEmit` pass under `strict` and the production bundle) and `npm run lint`, fixes anything `eslint-plugin-obsidianmd` reports, such as command names that are not sentence case or DOM built with `innerHTML`, and keeps the output. It does not install the plugin into a vault and says so. `manifest.json` and `versions.json` are untouched, because `ItemView`, `registerView` and `revealLeaf` are within `minAppVersion` `1.0.0`; `README.md` gets a short section on the view, the command and the toggle.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a custom sidebar view to this Obsidian plugin. Read package.json, manifest.json, esbuild.config.mjs, AGENTS.md, src/main.ts, src/settings.ts and the workflows first. Add an ItemView subclass in src/ui with a view type constant, display text, an icon and DOM built with createEl and createDiv, register it in onload, and add an activateView method that reuses an open leaf or opens one in the right sidebar and reveals it. Make the existing ribbon icon and a new sentence-case command open it. Do not detach leaves in onunload; say why in the PR. Add a boolean setting with a toggle that opens the view on layout ready, let the view re-render when settings change, and put styles in styles.css. Run npm ci, npm run build and npm run lint, fix what the obsidianmd lint rules report, and include the output. Do not change manifest.json or versions.json. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds `src/ui/sample-view.ts` and changes `src/main.ts` (the registration, `activateView`, the ribbon callback, the command and the `onLayoutReady` hook), `src/settings.ts` (the new setting and toggle), `styles.css` and `README.md`. `manifest.json`, `versions.json`, `esbuild.config.mjs` and both workflows are unchanged.

The description lists the view type, the command id and name, the setting, quotes the `tsc` and `esbuild` lines from `npm run build` and the `npm run lint` result, and states that the plugin was not loaded into a vault because the sandbox has no Obsidian. The commands and full output are in the transcript at `GET /o/{org}/sessions/{id}/messages`.

Before merging, a reviewer copies `main.js`, `manifest.json` and `styles.css` into a test vault's `.obsidian/plugins/sample-plugin/` once, opens the view from the ribbon and the palette, toggles the setting and reloads. A follow-up message to the same session can make the view react to the active file with `workspace.on('file-open')`, or add a second leaf in the left sidebar.

## Run it on every Obsidian plugin repository that needs a pane

A developer with several plugins starts one run per repository with one `POST /o/{org}/sessions` each, the repository in `resources` and this prompt as `input`. Each run reads its own `main.ts` and settings, so a plugin that already registers a view gets a second one beside it with a distinct type, and a plugin bundled with Rollup instead of esbuild keeps its bundler.

Send a `request_id`, a UUID v5 of the repository's full name, so a retried call returns the run it already started. The key's `webhook_url` reports when each run the key starts finishes, with the run's final answer in `result`.

## Why run it on Rush?

A view touches four places at once: the class, the registration, the leaf management and the settings, and the plugin guidelines keep changing what is allowed in `onunload` and in the DOM. The agent reads the sample's own `AGENTS.md`, builds under the repository's `strict` TypeScript and the `obsidianmd` lint rules in a sandbox of its own, and keeps the output of both.

The pull request shows the view, the wiring and the passing build and lint together, so review is a diff and one manual open in a vault rather than an afternoon with the API docs. Several plugins can be done at once, each in its own sandbox with its own pull request.

## Frequently asked questions

### Why not detach the leaves in onunload?

Current Obsidian plugin guidelines say not to: Obsidian restores open leaves and handles a view whose plugin is disabled. The agent leaves `onunload` empty, keeps cleanup in the view's `onClose`, and explains this in the pull request so the reviewer does not add it back.

### Will it work on mobile?

The manifest says `isDesktopOnly: false` and nothing in the view uses Electron or Node APIs, so yes. The right sidebar exists on mobile as a drawer and `revealLeaf` opens it; the status bar item the sample already adds is the only desktop-only piece, and it is unchanged.

### Does the view update when settings change?

Yes. The settings tab calls the view's `refresh()` after `saveSettings()`, found through `getLeavesOfType`, so the pane re-renders without being closed and reopened.

### Can the agent test it in Obsidian?

No; there is no Obsidian in the sandbox and the repository has no test runner. The proof is the `strict` type check, the production bundle and the `obsidianmd` lint pass. The pull request gives the three files to copy into a vault for a manual check.

## More Obsidian plugin jobs

- [Add Dependabot to an Obsidian Plugin](https://getrush.ai/run/add-dependabot/obsidian-plugin/)
- [Add a CodeMirror Editor Extension to an Obsidian Plugin](https://getrush.ai/run/add-editor-extension/obsidian-plugin/)
- [Add Autocomplete Suggestions to an Obsidian Plugin](https://getrush.ai/run/add-editor-suggest/obsidian-plugin/)

## More jobs like this: Hand off a long task

- [Add a Custom Workflow Builder Step to a Slack Bolt App](https://getrush.ai/run/add-custom-workflow-step/slack-bolt/)
- [Add DAG and Task Documentation to Airflow DAGs](https://getrush.ai/run/add-dag-docs/airflow/)
- [Add Params to Airflow DAGs](https://getrush.ai/run/add-dag-params/airflow/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
