Agent Context
unlistedby xuezhaojun
Export workspace state so AI agents can understand your current editing context.
Agent Context — Obsidian Plugin
Export workspace state so AI agents can understand your current Obsidian context.
Desktop only.
Why
When you use external AI agents (such as Claude Code, Cursor, OpenCode, or custom agents), they have no way of knowing what you're currently looking at in Obsidian — which files are open, which note is active, or what text you've selected.
This plugin continuously writes that workspace state to .obsidian/context.json. Any agent running outside Obsidian can read this file and gain awareness of your current editing context, enabling more relevant and accurate assistance.
How It Works
Obsidian workspace events
| (active-leaf-change, file-open, file-close, layout-change, editor-selection-change)
v
ContextManager (debounced)
|
v
WorkspaceContext.gatherState() -> { ts, active, tabs[], selection }
|
v
.obsidian/context.json
Installation
From Community Plugins
- Open Obsidian Settings > Community Plugins
- Search for "Agent Context"
- Click Install, then Enable
Manual Installation
- Download
main.js,manifest.json, andstyles.cssfrom the latest release - Create a folder
.obsidian/plugins/agent-context/in your vault - Copy the downloaded files into that folder
- Restart Obsidian and enable "Agent Context" in Settings > Community Plugins
Build from Source
- Clone this repository and build:
git clone https://github.com/xuezhaojun/obsidian-agent-context.git cd obsidian-agent-context npm install && npm run build - Copy
main.js,manifest.json, andstyles.cssto your vault's.obsidian/plugins/agent-context/ - Restart Obsidian and enable "Agent Context" in Settings > Community Plugins
Settings
| Setting | Description | Default |
|---|---|---|
| Inject workspace context | Enable/disable writing context.json | On |
| Max notes in context | Limit how many open tabs are included | 20 |
| Max selection length | Truncate selected text beyond this length | 2000 |
State File Format
{
"ts": 1714400000000,
"active": { "path": "notes/example.md", "name": "example.md" },
"tabs": [
{ "path": "notes/example.md", "name": "example.md", "isActive": true },
{ "path": "notes/other.md", "name": "other.md", "isActive": false }
],
"selection": {
"text": "selected text content",
"sourcePath": "notes/example.md"
}
}
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.