Skip to content

Repository files navigation

OpenCode Chat for Obsidian

Integrate the opencode agent into Obsidian with a native chat panel. The plugin spawns a local opencode serve instance with your vault as the working directory and talks to it over HTTP + SSE, so the agent can read notes, write files, and run commands — all rendered with Obsidian's own Markdown renderer.

Requirements

  • opencode CLI (opencode must be on PATH)
  • Obsidian 1.5.0+ on desktop

Features

Chat

  • Chat panel in the right sidebar, rendered with Obsidian's MarkdownRenderer (markdown-rendered), so code blocks, tables, quotes and links follow the active theme automatically
  • Streaming responses via the opencode server event stream, with a typing cursor
  • Collapsible Thinking block for reasoning, with a streaming animation while the model is thinking
  • Selectable/copyable output, code blocks with a hover copy button
  • Images in responses open in a preview window when clicked

Model & agent control (TUI style)

  • Footer shows the current model, reasoning effort and agent as clickable pills
  • /model, /agent and /effort open searchable picker dialogs (models are grouped by provider); Enter resolves a typed query directly
  • The last used model / effort / agent are persisted across restarts

Slash commands

  • Type / for a Codex/Copilot-style command popup with prefix matching and arrow-key navigation
  • Native commands: model, agent, effort, session, new
  • Server commands (init, review, and anything in your opencode.json command section) are merged into the same popup
  • Unknown /anything falls back to a normal message

Files

  • Type @ (at a word boundary) to pick a vault file from a searchable, folder-grouped dialog; attachments show as chips above the input
  • Paste images directly into the input — they are attached as image parts and can be previewed by clicking the thumbnail
  • Attachments are cleared after sending

Sessions

  • Lazy session creation: a real session is only created when you send your first message, so no empty sessions pile up
  • Session picker modal (/session or the header pill) with a "New session" entry
  • new conversation / /new / the + button reset the panel to an unsaved state

Agent permissions

  • Permission requests are shown inline with Allow once / Always / Reject
  • Optional auto-approve setting

Tool calls

  • Collapsible tool cards showing tool name, state, input and output

Usage

  1. Install the plugin from Community Plugins, or build from source (below).
  2. Enable the plugin — it starts a local opencode serve on port 4096 (configurable in settings) with your vault as the working directory.
  3. Click the robot ribbon icon or run OpenCode: Open chat panel.
  4. Type a message and press Enter. Use / for commands, @ to attach a vault file, or paste an image.

The agent works on the vault directory: it can read notes, write files, and run commands with your permission.

Settings

  • Server port — port for the local opencode server (default 4096)
  • Start server automatically — launch opencode serve when Obsidian starts
  • Auto-approve permissions — respond "always" to every permission request
  • Allowed origins (CORS) — browser origins allowed to call the server (Obsidian's app://obsidian.md by default; add origins for other clients)

Commands

  • OpenCode: Open chat panel
  • OpenCode: New conversation
  • OpenCode: Start opencode server
  • OpenCode: Stop opencode server

Development

Requirements: Node.js 20+, pnpm.

pnpm install
pnpm dev          # watch mode, writes main.js on changes
pnpm build        # typecheck + production build
pnpm install:vault  # link the plugin into your vault (.obsidian/plugins/)

pnpm install:vault auto-detects your vault from Obsidian's config, or you can pass a path: pnpm install:vault "D:\path\to\vault". It creates a directory junction so pnpm dev writes straight into the running vault — just reload Obsidian to pick up changes.

Planned: Obsidian tool gateway

The desktop plugin currently gives a local opencode process direct access to the vault directory. That does not work when opencode runs on another machine: the remote process cannot see a vault stored on a phone, tablet, or laptop.

The planned solution is for this plugin to act as an Obsidian Tool Gateway. It will expose selected Obsidian APIs as opencode custom tools or standard MCP tools while keeping the vault on the device:

opencode -> MCP / tool relay -> WebSocket -> Obsidian plugin -> Obsidian API

The Obsidian plugin will initiate the authenticated connection to the relay, receive tool calls, execute them with Vault, MetadataCache, Workspace, or Editor, and return only the requested result. The relay routes requests; it does not mount or upload the complete vault. This reverse connection also works when the device is behind NAT and avoids opening a local port on a phone.

Initial read-only tools may include:

  • obsidian_get_active_note
  • obsidian_read_note
  • obsidian_search_notes
  • obsidian_list_files
  • obsidian_get_backlinks
  • obsidian_get_properties
  • obsidian_get_selection

Later write tools may include obsidian_create_note, obsidian_move_note, and obsidian_apply_patch. Writes should use patches rather than replacing whole files, detect conflicts with a content hash, show a local diff, and require user approval before changing the vault.

The gateway will use a separate token for each device/vault, restrict every path to that vault, limit request and response sizes, and avoid exposing arbitrary JavaScript or unrestricted Obsidian command execution. On mobile, tools are available only while Obsidian is running because the operating system may suspend the app in the background.

Presenting the bridge as MCP also makes the same Obsidian tools reusable by other MCP-capable backends, such as Codex or Claude Code, without duplicating the vault integration.

Roadmap

  • Read-only Obsidian Tool Gateway MVP (active note, read, search, backlinks)
  • Patch-based write tools with conflict detection, local diff, and approval
  • Authenticated relay and reverse WebSocket transport for remote/mobile agents
  • Pluggable MCP-capable backends, including Codex and Claude Code
  • Drag-and-drop file attachments
  • Session diff view

License

MIT

About

Integrate the opencode agent into Obsidian with a native chat panel

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages