OpenCode is an open-source AI coding and terminal agent. It supports autonomous development and multi-agent workflows. When you configure NoteBrain as a dedicated OpenCode agent (notebrain-chat), you make your Obsidian vault an interactive semantic knowledge base for your AI pair programming sessions.
Obsidian vaults have thousands of interlinked notes, design documents, code snippets, and meeting records. Traditional AI agents cannot process these vaults correctly because:
- Context window flooding: The agents run
grepor read full markdown files. This puts thousands of irrelevant lines into the context and increases token consumption. - Missing semantic context: Keyword search (
grep) does not find synonyms, conceptual bridges, or structural graph hops (wikilinks).
NoteBrain avoids these problems because it queries a local ChromaDB HNSW vector index. When you use the permission system of OpenCode, you can sandbox the agent. Then the agent uses only high-precision semantic queries (notebrain search, hidden, connections, backlinks).
In OpenCode, agent configurations are Markdown files. They are in .opencode/agents/ (for project-specific agents) or ~/.config/opencode/agents/ (for global agents). The example agent file is Notebrain-Chat in this repository. Copy it to .opencode/agents/notebrain-chat.md (project-specific) or ~/.config/opencode/agents/notebrain-chat.md (global). The file name becomes the agent name.
An OpenCode agent file has two parts:
- YAML Frontmatter: This part gives agent metadata (
name,description,mode,temperature,model) and the strictpermissionsandbox. - Markdown System Instructions: This part gives the role of the agent, its operating rules, its tiered retrieval strategy, and the required response formatting.
When the configuration is complete, you can interact with your notebrain-chat agent in two ways:
-
Explicit Mode Selection (
primarymode): The example agent file setsmode: all. Because of this,notebrain-chatworks as a primary agent and as a subagent. You can selectnotebrain-chatas your active primary agent in the OpenCode CLI session. Alternatively, you can use the/notebrain-chatcommand. The agent answers all prompts with data from your Obsidian vault. -
Automatic Router Delegation (
subagentmode): If you changemode: alltomode: subagent, the routing engine reads thedescriptionfrontmatter:"Use NoteBrain to search, summarize, and explore an Obsidian vault. Invoke this agent whenever the user asks about their notes, knowledge base..."
When you ask a question like "What architectural decisions did I write down about Redis Streams in my vault?", OpenCode spawns
notebrain-chatin the background automatically. The agent executes the semantic query withnotebrain searchand sends citations back to your coding context.