Claude-skill-registry logseq
Provide commands for interacting with a local Logseq instance through its Plugin API. Use for creating pages, inserting blocks, querying the graph database, managing tasks, retrieving content, or automating workflows in Logseq. Only works with a locally running instance with the API enabled; default port or set path expected for [$API accessible skill].
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/logseq" ~/.claude/skills/majiayu000-claude-skill-registry-logseq && rm -rf "$T"
skills/data/logseq/SKILL.mdLogseq Plugin API
Interact with your local Logseq instance through its JavaScript Plugin API. This skill enables reading, writing, querying, and automating workflows in your Logseq graph.
Prerequisites
Logseq must be running locally with a plugin that exposes the API. The standard way is:
- Install a bridge plugin that exposes
API via HTTP (e.g., via a custom plugin or localhost endpoint)logseq - Alternative: Use Node.js with
package to script against the running Logseq instance@logseq/libs
The API is primarily designed for in-browser plugins, so accessing it from external scripts requires a bridge/proxy.
Core API Namespaces
The Logseq Plugin API is organized into these main proxies:
logseq.App
logseq.AppApplication-level operations: getting app info, user configs, current graph, commands, UI state, external links.
Key methods:
- Get app version and infogetInfo()
- Get user preferences (theme, format, language, etc.)getUserConfigs()
- Get current graph info (name, path, URL)getCurrentGraph()
- Register custom commandsregisterCommand(type, opts, action)
- Navigate to routespushState(route, params, query)
logseq.Editor
logseq.EditorBlock and page editing operations: creating, updating, moving, querying content.
Key methods:
- Get block by UUIDgetBlock(uuid)
- Get current page entitygetCurrentPage()
- Get all blocks on current pagegetCurrentPageBlocksTree()
- Get all blocks for a specific pagegetPageBlocksTree(page)
- Insert a new blockinsertBlock(target, content, opts)
- Update block contentupdateBlock(uuid, content)
- Create a new pagecreatePage(pageName, properties, opts)
- Delete a pagedeletePage(pageName)
- Get backlinks to a pagegetPageLinkedReferences(page)
- Add custom slash commandsregisterSlashCommand(tag, action)
logseq.DB
logseq.DBDatabase queries using Datalog.
Key methods:
- Run Datalog queryq(query, ...inputs)
- Direct Datascript querydatascriptQuery(query, ...inputs)
logseq.UI
logseq.UIUI operations: messages, dialogs, main UI visibility.
Key methods:
- Show toast notificationshowMsg(content, status)
- Query DOM elementsqueryElementById(id)
logseq.Git
logseq.GitGit operations for the current graph.
Key methods:
- Execute git commandexecCommand(args)
logseq.Assets
logseq.AssetsAsset management.
Key methods:
- List files in graphlistFilesOfCurrentGraph(path)
Common Workflows
Read Content
// Get current page const page = await logseq.Editor.getCurrentPage(); // Get all blocks on a page const blocks = await logseq.Editor.getPageBlocksTree('Daily Notes'); // Get a specific block const block = await logseq.Editor.getBlock('block-uuid-here'); // Query with Datalog const results = await logseq.DB.q(` [:find (pull ?b [*]) :where [?b :block/marker "TODO"]] `);
Write Content
// Create a new page await logseq.Editor.createPage('Project Notes', { tags: 'project', status: 'active' }, { redirect: false }); // Insert a block const block = await logseq.Editor.insertBlock( 'target-block-uuid', '- New task item', { before: false, sibling: true } ); // Update a block await logseq.Editor.updateBlock('block-uuid', 'Updated content'); // Batch insert multiple blocks const blocks = [ { content: 'First item' }, { content: 'Second item', children: [ { content: 'Nested item' } ]} ]; await logseq.Editor.insertBatchBlock('parent-uuid', blocks, { sibling: false });
Task Management
// Find all TODO items const todos = await logseq.DB.q(` [:find (pull ?b [*]) :where [?b :block/marker ?marker] [(contains? #{"TODO" "DOING"} ?marker)]] `); // Mark task as DONE await logseq.Editor.updateBlock('task-uuid', 'DONE Task content'); // Get tasks on current page const page = await logseq.Editor.getCurrentPage(); const blocks = await logseq.Editor.getPageBlocksTree(page.name); const tasks = blocks.filter(b => b.marker === 'TODO' || b.marker === 'DOING');
Navigation and UI
// Navigate to a page logseq.App.pushState('page', { name: 'Project Notes' }); // Show notification logseq.UI.showMsg('✅ Task completed!', 'success'); // Get app config const configs = await logseq.App.getUserConfigs(); console.log('Theme:', configs.preferredThemeMode); console.log('Format:', configs.preferredFormat);
Implementation Approaches
Since Logseq's Plugin API is browser-based, you have several options:
Option 1: Bridge Plugin
Create a minimal Logseq plugin that exposes API calls via HTTP:
// In Logseq plugin (index.js) logseq.ready(() => { // Expose API endpoints logseq.provideModel({ async handleAPICall({ method, args }) { return await logseq.Editor[method](...args); } }); }); // Then call from external script via HTTP POST
Option 2: Node.js Script with @logseq/libs
For automation scripts, use the
@logseq/libs package:
npm install @logseq/libs
Note: This requires a running Logseq instance and proper connection setup.
Option 3: Direct Plugin Development
Develop a full Logseq plugin following the plugin samples at: https://github.com/logseq/logseq-plugin-samples
API Reference
For complete API documentation, see:
- API Docs: https://logseq.github.io/plugins/
- Plugin Samples: https://github.com/logseq/logseq-plugin-samples
- Type Definitions:
(extracted fromreferences/api-types.md
)@logseq/libs
Key Data Structures
BlockEntity
{ id: number, // Entity ID uuid: string, // Block UUID content: string, // Block content format: 'markdown' | 'org', page: { id: number }, // Parent page parent: { id: number }, // Parent block left: { id: number }, // Previous sibling properties: {}, // Block properties marker?: string, // TODO/DOING/DONE children?: [] // Child blocks }
PageEntity
{ id: number, uuid: string, name: string, // Page name (lowercase) originalName: string, // Original case 'journal?': boolean, properties: {}, journalDay?: number, // YYYYMMDD for journals }
Tips & Best Practices
- Always check for null: API methods may return
if entity doesn't existnull - Use UUIDs over IDs: Block UUIDs are stable, entity IDs can change
- Batch operations: Use
for multiple insertsinsertBatchBlock - Query efficiently: Datalog queries are powerful but can be slow on large graphs
- Properties are objects: Access with
block.properties.propertyName - Format matters: Respect user's preferred format (markdown vs org-mode)
- Async all the way: All API calls return Promises
Common Gotchas
- Page names are lowercase: When querying, use lowercase page names
- Journal pages: Use
format (YYYYMMDD) not date stringsjournalDay - Block hierarchy: Respect parent/child relationships when inserting
- Format differences: Markdown uses
for bullets, Org uses-* - Properties syntax: Different between markdown (
) and org (prop::
):PROPERTIES: