opencode-session-save
v0.1.3
Published
OpenCode plugin that captures shared sessions into Obsidian notes.
Readme
OpenCode Session Save
OpenCode-native npm plugin that captures the current session into an Obsidian note
after /share.
Workflow:
- run
/share - run
/session-save <share-url>
The plugin captures the first user prompt and session metadata from OpenCode event
hooks, then writes or updates a note under AI Sessions/ in your Obsidian vault.
What this package installs
- npm plugin:
opencode-session-save - custom tool:
save_session_note - config command:
/session-save - permission entry:
save_session_note: allow
Environment
OPENCODE_SESSION_SAVE_VAULT_ROOT: required vault root containingAI SessionsOPENCODE_SESSION_SAVE_ROOT: optional local dev helper root- compatibility alias:
SESSION_SAVE_ROOT
/session-save fails unless OPENCODE_SESSION_SAVE_VAULT_ROOT is set.
Install
Add the plugin to your OpenCode config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-session-save"],
"permission": {
"save_session_note": "allow"
},
"command": {
"session-save": {
"description": "Save the current OpenCode session into the Obsidian AI session tracker",
"template": "Use this only after `/share` has already returned a share URL.\n\nCall the `save_session_note` tool immediately with:\n\n- `shareUrl`: `$ARGUMENTS`\n\nRules:\n\n- do not generate the note in-model\n- do not summarize the session yourself\n- do not claim success unless the tool returns a note path\n- if `$ARGUMENTS` is missing or invalid, say so briefly"
}
}
}Use either ~/.config/opencode/opencode.json or ~/.config/opencode/opencode.jsonc.
OpenCode installs the npm plugin automatically on startup after it sees "opencode-session-save" in plugin.
Then set your vault root:
export OPENCODE_SESSION_SAVE_VAULT_ROOT="$HOME/obsidian-vault"Restart OpenCode after installing or changing plugin config.
Local development
Run a temp OpenCode config wired to this checkout:
bin/opencode-session-save-devThe launcher creates a temporary .opencode config containing:
commands/session-save.mdplugins/session-save.tslib/session-save-core.tslib/note-writer.tspackage.jsonopencode.json
This keeps local plugin development close to how OpenCode loads project plugins.
Package layout
dist/index.jspublished plugin entrypoint loaded from the package rootsrc/plugins/session-save.tsOpenCode plugin entry and tool registrationsrc/lib/session-save-core.tssession capture, validation, and cache helperssrc/lib/note-writer.tsObsidian note creation and update logiccommands/session-save.mdsource template for the installed command
Tests
bun run build
bun test