npm install @logseq/cliThis library provides a logseq CLI for DB graphs created using the database-version. By default, the CLI works offline with local graphs. This allows for running commands automatically on CI/CD platforms like Github Actions. Most CLI commands also connect to the current DB graph in a desktop app (a.k.a. in-app graph) if the HTTP API Server is turned on.
Install the logseq CLI with npm install -g @logseq/cli.
This section assumes you have installed the CLI from npm or via the dev
setup. If you haven't, substitute node cli.mjs for logseq e.g.node.cli.mjs -h.
All commands work with both local graphs and the current in-app graph except for append (in-app graph only), validate (local graph only) and export (local graph only). For a command to work with an in-app graph, the HTTP API Server must be turned on.
Now let's use the CLI!
``sh
$ logseq -h
Usage: logseq [command] [options]
Options:
-v, --version Print version
Commands:
list List local graphs
show Show DB graph(s) info
search [options] Search DB graph
query [options] Query DB graph(s)
export [options] Export DB graph as Markdown
export-edn [options] Export DB graph as EDN
import-edn [options] Import into DB graph with EDN
append [options] Appends text to current page
mcp-server [options] Run a MCP server
validate [options] Validate DB graph
help Print a command's help
$ logseq list
DB Graphs:
db-test
docs
woot
...
File Graphs:
docs
...
$ logseq show db-test
| Name | Value |
|------------------------------+----------------------------------------------------|
| Graph directory | /Users/me/logseq/graphs/db-test |
| Graph created at | Jul 12th, 2025 |
| Graph schema version | {:major 65, :minor 7} |
| Graph initial schema version | {:major 65, :minor 7} |
| Graph created by commit | https://github.com/logseq/logseq/commit/3c93fd2637 |
| Graph imported by | :cli/create-graph |
`
To run a command against the current desktop graph, set $LOGSEQ_API_SERVER_TOKEN once or set -a each time with a valid token for the desktop's HTTP API server:
`sh`Search your current graph and print highlighted results one per line like grep
$ logseq search woot -a my-token
Search found 100 results:
dev:db-export woot woot.edn && dev:db-create woot2 woot.edn
dev:db-diff woot woot2
...Can also authenticate api with $LOGSEQ_API_SERVER_TOKEN
$ export LOGSEQ_API_SERVER_TOKEN=my-token
$ logseq search woot
...
Here are more examples of all the available commands:
`shSearch a local graph
$ logseq search page -g woot
Search found 23 results:
Node page
Annotation page
...
id(s) like an integer or a :db/identAPI
This library is under the parent namespace
logseq.cli.Dev
Most of this library is also compatible with ClojureScript for use on the
frontend. This library follows the practices that the Logseq frontend
follows. Most of the same linters are used, with
configurations that are specific to this library. See this library's CI
file for linting examples.
$3
First install the following dependencies:
* Install node.js >= 22 and yarn.
* Run
yarn install to install npm dependencies.
* Install babashka.To install the CLI locally so that local changes are immediately reflected in
logseq, yarn link.$3
Testing is done with nbb-logseq and
nbb-test-runner. Some basic
usage:
`sh
Run all tests
$ yarn test
List available options
$ yarn test -H
Run tests with :focus metadata flag
$ yarn test -i focus
`$3
See standard nbb/cljs library advice in graph-parser.
$3
To build and install a local version of the CLI:
`sh
$ bb build:vendor-nbb-deps && npm pack && npm install -g ./logseq-cli-*.tgz
Run this to bring local code back to a clean state. Not running this will cause local dev issues
$ git checkout nbb.edn && rm -rf vendor logseq-cli*.tgz
``The above is useful for testing the build process and ensuring the released tarball has no issues.