A command-line interface for LogSeq operations via its HTTP API.
Zero dependencies — uses only Bun built-in APIs and native TypeScript.
- Bun runtime
- LogSeq with HTTP API server enabled
- API token from LogSeq
| Variable | Required | Default | Description |
|---|---|---|---|
LOGSEQ_API_TOKEN |
Yes | - | Your LogSeq API token |
LOGSEQ_HOST |
No | 127.0.0.1 |
LogSeq server host |
LOGSEQ_PORT |
No | 12315 |
LogSeq server port |
LOGSEQ_PROTOCOL |
No | http |
Protocol (http/https) |
# Clone the repository
git clone <repository-url>
cd tools_for_logseq
# Install dependencies
bun install
# Set up environment variables
cp .env.template .env
# Edit .env and set LOGSEQ_API_TOKEN to your token- Open Logseq
- Go to Settings > Features
- Enable "HTTP APIs Server"
- Set your token in "Authorization tokens"
- Copy that token to your
.envfile asLOGSEQ_API_TOKEN
tools_for_logseq/
├── logseq.ts # CLI entry point
├── cli/
│ ├── arg_parser.ts # Argument parsing utilities
│ ├── arg_parser.test.ts # Tests for argument parsing
│ ├── commands.ts # Command implementations
│ └── help.ts # Help text and documentation
├── logseq/
│ └── http_client.ts # LogSeq HTTP API client library
├── package.json
└── README.md
bun run logseq <command> [options]List all pages in the graph.
# List pages (excluding journals)
bun run logseq list-pages
# Include journal pages
bun run logseq list-pages --include-journals
# Output as JSON
bun run logseq list-pages --format jsonGet content of a specific page with metadata and blocks.
# Get page content
bun run logseq get-page "My Page"
# Output as JSON
bun run logseq get-page "My Page" --format json
# Alternative: use --name flag instead of positional argument
bun run logseq get-page --name "My Page"Create a new page.
# Create empty page
bun run logseq create-page "New Page"
# Create page with initial content
bun run logseq create-page "New Page" --content "Initial content here"
# Alternative: use --title flag instead of positional argument
bun run logseq create-page --title "New Page" --content "Initial content here"Update an existing page with new content and/or properties.
# Append content to a page
bun run logseq update-page "My Page" --content "Additional content"
# Update page properties
bun run logseq update-page "My Page" --properties '{"status": "done", "priority": "high"}'
# Update both content and properties
bun run logseq update-page "My Page" --content "More text" --properties '{"updated": true}'
# Alternative: use --name flag instead of positional argument
bun run logseq update-page --name "My Page" --content "Additional content"Delete a page (requires confirmation).
# Delete a page (requires --force flag)
bun run logseq delete-page "Old Page" --force
# Alternative: use --name flag instead of positional argument
bun run logseq delete-page --name "Old Page" --forceSearch for content across the graph.
# Basic search
bun run logseq search "keyword"
# Limit results
bun run logseq search "keyword" --limit 50
# Exclude block content from results
bun run logseq search "keyword" --no-blocks
# Exclude page name matches
bun run logseq search "keyword" --no-pages
# Include file name matches
bun run logseq search "keyword" --include-files
# Output as JSON
bun run logseq search "keyword" --format json
# Combined options
bun run logseq search "keyword" --limit 100 --include-files --format json
# Alternative: use --query flag instead of positional argument
bun run logseq search --query "keyword" --limit 50Create a new block.
# Insert block into a page (as page-level block)
bun run logseq insert-block "Block content" --parent "My Page" --page-block
# Insert block as child of another block (by UUID)
bun run logseq insert-block "Child content" --parent "block-uuid-here"
# Insert block before the parent
bun run logseq insert-block "Content" --parent "block-uuid" --before
# Insert block with custom UUID
bun run logseq insert-block "Content" --parent "My Page" --page-block --uuid "custom-uuid-v4"
# Output as JSON (includes new block's UUID)
bun run logseq insert-block "Content" --parent "My Page" --page-block --format json
# Alternative: use --content flag instead of positional argument
bun run logseq insert-block --content "Block content" --parent "My Page" --page-blockEnter block editing mode in LogSeq.
# Edit a block by UUID
bun run logseq edit-block "block-uuid-here"
# Edit with cursor at specific position
bun run logseq edit-block "block-uuid-here" --pos 10
# Alternative: use --uuid flag instead of positional argument
bun run logseq edit-block --uuid "block-uuid-here" --pos 10Exit editing mode in LogSeq.
# Exit editing mode
bun run logseq exit-editing
# Exit but keep block selected
bun run logseq exit-editing --selectGet the block tree for a specific page.
# Get blocks as formatted text
bun run logseq get-page-blocks "My Page"
# Get blocks as JSON (includes UUIDs)
bun run logseq get-page-blocks "My Page" --format json
# Alternative: use --page flag instead of positional argument
bun run logseq get-page-blocks --page "My Page" --format jsonList all pages (with optional repository filter).
# Get all pages
bun run logseq get-all-pages
# Get pages from specific repository
bun run logseq get-all-pages --repo "my-repo"
# Output as JSON
bun run logseq get-all-pages --format jsonGet the currently active page or block in LogSeq.
# Get current page/block
bun run logseq get-current-page
# Output as JSON
bun run logseq get-current-page --format jsonGet the block tree of the currently active page.
# Get current page blocks
bun run logseq get-current-blocks
# Output as JSON
bun run logseq get-current-blocks --format jsonGet the content of the block currently being edited.
# Get editing block content
bun run logseq get-editing-content
# Output as JSON
bun run logseq get-editing-content --format jsonShow help information.
# Show general help
bun run logseq help
# Show help for specific command
bun run logseq help insert-block
bun run logseq help search
# Alternative help flags
bun run logseq --help
bun run logseq -h# Create a new page
bun run logseq create-page "Project Notes"
# Add blocks to it
bun run logseq insert-block "First item" --parent "Project Notes" --page-block
bun run logseq insert-block "Second item" --parent "Project Notes" --page-block# Get blocks with UUIDs
bun run logseq get-page-blocks "My Page" --format json
# Use a UUID to add a child block
bun run logseq insert-block "Child content" --parent "returned-block-uuid"# Search for content
bun run logseq search "meeting notes" --format json
# Get full content of a matching page
bun run logseq get-page "Weekly Meeting Notes"# Get current context
bun run logseq get-current-page
# Get blocks on current page
bun run logseq get-current-blocks --format json
# Edit a specific block
bun run logseq edit-block "block-uuid"
# Check what's being edited
bun run logseq get-editing-content
# Exit editing mode
bun run logseq exit-editingBun can compile this CLI to a standalone executable that doesn't require Bun to be installed.
bun build --compile logseq.ts --outfile logseqbun build --compile --minify logseq.ts --outfile logseq# Linux x64
bun build --compile --target=bun-linux-x64 logseq.ts --outfile logseq-linux
# macOS ARM (Apple Silicon)
bun build --compile --target=bun-darwin-arm64 logseq.ts --outfile logseq-mac-arm
# macOS x64 (Intel)
bun build --compile --target=bun-darwin-x64 logseq.ts --outfile logseq-mac-x64
# Windows x64
bun build --compile --target=bun-windows-x64 logseq.ts --outfile logseq.exe# Make executable (if needed)
chmod +x logseq
# Run commands
./logseq help
./logseq list-pages
./logseq get-page "My Page"# Compile
bun build --compile --minify logseq.ts --outfile logseq
# Move to a directory in your PATH
sudo mv logseq /usr/local/bin/
# Now use from anywhere
logseq help
logseq list-pagesMost commands support --format option:
text(default): Human-readable formatted outputjson: Machine-readable JSON output, useful for scripting and piping to tools likejq
Run the test suite with:
bun testThe CLI will exit with code 1 and display an error message when:
- Required arguments are missing
- Required environment variables are not set
- The LogSeq API returns an error
- A referenced page or block doesn't exist
Contributions are welcome! Please see CONTRIBUTING.md for guidelines, including information about:
- Development workflow
- Testing practices
- AI-assisted development
- Guidelines for AI coding assistants
MIT