6.5 KiB
Logseq CLI (Node)
The Logseq CLI is a Node.js program compiled from ClojureScript that connects to a db-worker-node server managed by the CLI. When installed, the CLI binary name is logseq.
Build the CLI
LOGSEQ_BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
LOGSEQ_REVISION=$(git rev-parse --short HEAD) \
clojure -M:cljs compile logseq-cli
If LOGSEQ_BUILD_TIME or LOGSEQ_REVISION are not provided, the CLI prints defaults in --version output.
db-worker-node lifecycle
logseq manages db-worker-node automatically. You should not start the server manually. The server binds to localhost on a random port and records that port in the repo lock file.
Run the CLI
node ./dist/logseq.js graph list
If installed globally, run:
logseq graph list
Configuration
Optional configuration file: ~/.logseq/cli.edn
Supported keys include:
:repo:data-dir:timeout-ms:output-format(use:jsonor:ednfor scripting)
CLI flags take precedence over environment variables, which take precedence over the config file.
Commands
Graph commands:
graph list- list all db graphsgraph create --repo <name>- create a new db graph and switch to itgraph switch --repo <name>- switch current graphgraph remove --repo <name>- remove a graphgraph validate --repo <name>- validate graph datagraph info [--repo <name>]- show graph metadata (defaults to current graph)graph export --type edn|sqlite --output <path> [--repo <name>]- export a graph to EDN or SQLitegraph import --type edn|sqlite --input <path> --repo <name>- import a graph from EDN or SQLite (new graph only)
For any command that requires --repo, if the target graph does not exist, the CLI returns graph not exists (except for graph create). graph import fails if the target graph already exists.
Server commands:
server list- list running db-worker-node serversserver status --repo <name>- show server status for a graphserver start --repo <name>- start db-worker-node for a graphserver stop --repo <name>- stop db-worker-node for a graphserver restart --repo <name>- restart db-worker-node for a graph
Inspect and edit commands:
list page [--expand] [--limit <n>] [--offset <n>] [--sort <field>] [--order asc|desc]- list pageslist tag [--expand] [--limit <n>] [--offset <n>] [--sort <field>] [--order asc|desc]- list tagslist property [--expand] [--limit <n>] [--offset <n>] [--sort <field>] [--order asc|desc]- list propertiesadd block --content <text> [--target-page-name <name>|--target-id <id>|--target-uuid <uuid>] [--pos first-child|last-child|sibling]- add blocks; defaults to today’s journal page if no target is givenadd block --blocks <edn> [--target-page-name <name>|--target-id <id>|--target-uuid <uuid>] [--pos first-child|last-child|sibling]- insert blocks via EDN vectoradd block --blocks-file <path> [--target-page-name <name>|--target-id <id>|--target-uuid <uuid>] [--pos first-child|last-child|sibling]- insert blocks from an EDN fileadd page --page <name>- create a pagemove --id <id>|--uuid <uuid> --target-id <id>|--target-uuid <uuid>|--target-page <name> [--pos first-child|last-child|sibling]- move a block and its children (defaults to first-child)remove --id <id>|--uuid <uuid>|--page <name>- remove blocks (by db/id or UUID) or pagessearch <query> [--type page|block|tag|property|all] [--tag <name>] [--case-sensitive] [--sort updated-at|created-at] [--order asc|desc]- search across pages, blocks, tags, and properties (query is positional)query --query <edn> [--inputs <edn-vector>]- run a Datascript query against the graphshow --page <name> [--level <n>]- show page treeshow --uuid <uuid> [--level <n>]- show block treeshow --id <id> [--level <n>]- show block tree by db/id
Help output:
Subcommands:
list page [options] List pages
list tag [options] List tags
list property [options] List properties
add block [options] Add blocks
add page [options] Create page
move [options] Move block
remove [options] Remove block or page
search <query> [options] Search graph
show [options] Show tree
Options grouping:
- Help output separates Global options (apply to all commands) and Command options (command-specific flags).
Version output:
logseq --versionprints:
Build time: <timestamp>
Revision: <commit>
Output formats:
- Global
--output <human|json|edn>applies to all commands - For
graph export,--outputrefers to the destination file path. Output formatting is controlled via:output-formatin config orLOGSEQ_CLI_OUTPUT. - Human output is plain text. List/search commands render tables with a final
Count: Nline. For list and search subcommands, the ID column uses:db/id(not UUID). If:db/identexists, anIDENTcolumn is included. Search table columns areIDandTITLE. Block titles can include multiple lines; multi-line rows align additional lines under theTITLEcolumn. Times such as listUPDATED-AT/CREATED-ATandgraph infoCreated atare shown in human-friendly relative form. Errors include error codes and may include aHint:line. Use--output json|ednfor structured output. queryhuman output returns a plain string (the query result rendered viapr-str), which is convenient for pipelines likelogseq query ... | xargs logseq show --id.- Show and search outputs resolve block reference UUIDs inside text, replacing
[[<uuid>]]with the referenced block content. Nested references are resolved recursively up to 10 levels to avoid excessive expansion. For example:[[<uuid1>]]→[[some text [[<uuid2>]]]]and then<uuid2>is also replaced. showhuman output prints the:db/idas the first column followed by a tree:
id1 block1
id2 ├── b2
id3 │ └── b3
id4 ├── b4
id5 │ ├── b5
id6 │ │ └── b6
id7 │ └── b7
id8 └── b8
Examples:
node ./dist/logseq.js graph create --repo demo
node ./dist/logseq.js graph export --type edn --output /tmp/demo.edn --repo demo
node ./dist/logseq.js graph import --type edn --input /tmp/demo.edn --repo demo-import
node ./dist/logseq.js add block --target-page-name TestPage --content "hello world"
node ./dist/logseq.js move --uuid <uuid> --target-page TargetPage
node ./dist/logseq.js search "hello"
node ./dist/logseq.js show --page TestPage --output json
node ./dist/logseq.js server list