CLI Reference
Complete command-line interface documentation
The libragen CLI provides commands for building, querying, and managing RAG libraries.
Global Options
These options work with all commands:
| Option | Description |
|---|---|
--help, -h | Show help for a command |
--cli-version, -V | Show CLI version number |
Commands
build
Create a new library from source files.
libragen build <source> [options]Arguments
| Argument | Description |
|---|---|
source | Directory or file to process |
Options
| Option | Type | Default | Description |
|---|---|---|---|
--name, -n | string | Required | Library name (creates <name>-<version>.libragen) |
--output, -o | string | Current dir | Output directory |
--description, -d | string | — | Library description |
--content-version | string | — | Version tag for the content |
--include, -i | string[] | — | Glob patterns to include |
--exclude, -e | string[] | — | Glob patterns to exclude (added to defaults) |
--no-default-excludes | boolean | false | Disable default exclusions |
--chunk-size | number | 1000 | Target chunk size in characters |
--chunk-overlap | number | 100 | Overlap between chunks |
--no-ast-chunking | boolean | false | Disable AST-aware chunking for code files |
--context-mode | string | full | Context mode for AST chunking: none, minimal, or full |
--license | string[] | Auto-detected | SPDX license identifier(s) for the source |
--git-ref | string | — | Git branch, tag, or commit (git sources only) |
--git-repo-auth-token | string | — | Auth token for private repos |
Examples
# Basic buildlibragen build ./docs --name my-docs
# With version and descriptionlibragen build ./docs \ --name my-api \ --description "API documentation" \ --content-version 2.1.0
# Custom chunk settingslibragen build ./docs \ --name my-docs \ --chunk-size 1024 \ --chunk-overlap 100
# Exclude patternslibragen build ./docs \ --name my-docs \ --exclude "**/node_modules/**" \ --exclude "**/test/**"
# Build from git repositorylibragen build https://github.com/user/repo --name repo-docs
# Build with explicit licenselibragen build ./docs --name my-docs --license MIT
# Build with multiple licenses (dual licensing)libragen build ./docs --name my-docs --license MIT Apache-2.0
# Disable AST chunking (use text-based chunking only)libragen build ./src --name my-code --no-ast-chunking
# Use minimal context for AST chunking (smaller chunks)libragen build ./src --name my-code --context-mode minimalLicense Detection
When building from git repositories, licenses are automatically detected from LICENSE files (LICENSE, LICENSE.md, LICENSE.txt, COPYING).
- Git sources: Auto-detected if not explicitly provided
- Local sources: Use
--licenseto specify - Explicit
--license: Always takes precedence
Supported licenses: MIT, Apache-2.0, GPL-3.0, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause, BSD-2-Clause, ISC, Unlicense, MPL-2.0, CC0-1.0, AGPL-3.0
AST-Aware Code Chunking
By default, libragen uses AST-aware chunking for supported code files. This produces higher-quality embeddings by:
- Respecting language boundaries — Chunks align with functions, classes, and methods instead of arbitrary character positions
- Including semantic context — Each chunk includes scope chain, imports, and sibling entities
- Contextualizing for embeddings — A special
contextualizedTextis generated that includes file path, scope, and signatures
Supported languages: TypeScript, JavaScript, Python, Rust, Go, Java
Context modes:
full(default) — Include all available context (scope chain, imports, siblings, signatures)minimal— Include only essential context (scope chain, entity signatures)none— No additional context (raw code only)
Non-code files (Markdown, JSON, text, etc.) always use text-based chunking.
query
Search a library with natural language.
libragen query [options] <query>Arguments
| Argument | Description |
|---|---|
query | Natural language search query |
Options
| Option | Type | Default | Description |
|---|---|---|---|
--library, -l | string | Required | Library name or path to .libragen file |
--path, -p | string[] | auto-detect + global | Project directory (will search |
--top-k, -k | number | 10 | Number of results to return |
--content-version | string | — | Filter by content version |
--format, -f | string | text | Output format (text, json) |
The -l option accepts either:
- A library name (e.g.,
my-lib) — resolved using the library discovery algorithm - A file path (e.g.,
./my-lib.libragen) — used directly
When using a library name, the resolution algorithm searches:
- Project-local directories (
.libragen/libraries/in cwd) - Global library directory (
~/.libragen/libraries/) - Any paths specified with
-p
Examples
# Query by library name (uses resolution algorithm)libragen query --library my-docs "How do I authenticate?"
# Query by explicit file pathlibragen query -l ./my-docs.libragen "How do I authenticate?"
# Query with custom project directorylibragen query -l my-docs -p ./my-project "error handling"
# Get more results as JSONlibragen query -l my-docs -k 20 -f json "error handling"
# Query specific versionlibragen query -l my-api --content-version 2.0.0 "rate limits"Output Format
Text output (default):
[1] authentication.md (score: 0.89) To authenticate, pass your API key in the Authorization header...
[2] getting-started.md (score: 0.82) First, obtain an API key from the dashboard...JSON output (--format json):
{ "results": [ { "rank": 1, "score": 0.89, "source": "authentication.md", "content": "To authenticate, pass your API key..." } ]}list
List installed libraries.
Aliases: l, ls
libragen list [options]Options
| Option | Type | Default | Description |
|---|---|---|---|
-p, --path | string[] | — | Project directory (will search |
-v, --verbose | boolean | false | Show detailed information (path, chunks, size, keywords) |
--show-path | boolean | false | Show the file path for each library |
--json | boolean | false | Output as JSON (includes path and location) |
--libraries | boolean | false | Show only libraries |
--collections | boolean | false | Show only collections |
Output
Each library displays:
- Name and version
- Location badge:
[project]or[global]indicating where the library was found - Path (with
--show-pathor-v): full file path to the.libragenfile
The location badge helps identify which libraries come from project-local directories vs the global directory.
Library Discovery
By default, libragen discovers libraries from:
- Project directory — If
.libragen/libraries/exists in the current directory, it’s searched first - Global directory —
$LIBRAGEN_HOME/libraries(always included)
When -p is specified, the path is transformed to <path>/.libragen/libraries and only that path is searched—no global directory, no auto-detection.
Examples
# List all libraries (auto-detected + global)libragen list
# List with file paths shownlibragen list --show-path
# List only project-local librarieslibragen list -p ./my-project
# List from multiple specific pathslibragen list -p ./libs -p ./vendor/libs
# JSON output for scripting (includes path and location)libragen list --jsonExample output:
📚 Installed Libraries (2)
my-docs v1.0.0 [project] react-docs v19.0.0 [global]With --show-path:
📚 Installed Libraries (2)
my-docs v1.0.0 [project] /path/to/project/.libragen/libraries/my-docs-1.0.0.libragen
react-docs v19.0.0 [global] /Users/you/.libragen/libraries/react-docs-19.0.0.librageninspect
Inspect the contents of a library (.libragen) or packed collection (.libragen-collection) file.
libragen inspect <source> [options]Arguments
| Argument | Description |
|---|---|
source | Library file, packed collection, or URL |
Options
| Option | Type | Default | Description |
|---|---|---|---|
--json | boolean | false | Output as JSON |
Examples
# Inspect a library filelibragen inspect my-lib.libragen
# Inspect a packed collectionlibragen inspect my-collection.libragen-collection
# Inspect from URLlibragen inspect https://example.com/my-lib.libragen
# JSON output for scriptinglibragen inspect my-lib.libragen --jsonOutput (library)
📚 Library Contents
File: /path/to/my-lib.libragen Size: 1.23 MB
Metadata: Name: my-lib Version: 1.0.0 Description: My library description Content: v2.0.0 (semver) Schema: v3 Created: 2024-01-15T10:30:00.000Z
Stats: Chunks: 1,234 Sources: 42 files
Embedding: Model: Xenova/bge-small-en-v1.5 Dimensions: 384
Source: Type: git URL: https://github.com/user/repo Ref: main Commit: abc12345
License(s): • MITOutput (packed collection)
📦 Collection Contents
File: /path/to/my-collection.libragen-collection Size: 5.67 MB
Metadata: Name: my-collection Version: 1.0.0 Desc: My collection description
Libraries (3): • api-docs.libragen (1.2 MB) • guides.libragen (2.3 MB) • tutorials.libragen (2.17 MB)
Install with: libragen install /path/to/my-collection.libragen-collectioninstall
Install a library from a collection or URL.
libragen install <source> [options]Options
| Option | Type | Default | Description |
|---|---|---|---|
-p, --path | string[] | — | Project directory (will install to |
-f, --force | boolean | false | Overwrite existing library |
-c, --collection | string | — | Collection URL to use |
--content-version | string | — | Install specific content version |
-a, --all | boolean | false | Install all libraries including optional (for collections) |
Examples
# Install from file (defaults to $LIBRAGEN_HOME/libraries)libragen install ./my-lib.libragen
# Install to a project directory (creates ./my-project/.libragen/libraries)libragen install ./my-lib.libragen -p ./my-project
# Install to multiple project directories (first path is used for install)libragen install ./my-lib.libragen -p ./project-a -p ./project-b
# Install from URLlibragen install https://example.com/my-lib-1.0.0.libragenuninstall
Remove an installed library.
libragen uninstall <name> [options]Options
| Option | Type | Default | Description |
|---|---|---|---|
-p, --path | string[] | — | Project directory (will search |
-c, --collection | boolean | false | Uninstall a collection (and unreferenced libraries) |
Examples
# Uninstall from auto-detected pathslibragen uninstall my-docs
# Uninstall from specific project onlylibragen uninstall my-docs -p ./my-projectupdate
Update installed libraries to newer versions from their collections.
libragen update [name] [options]Arguments
| Argument | Description |
|---|---|
name | Optional library name to update (updates all if omitted) |
Options
| Option | Type | Default | Description |
|---|---|---|---|
-p, --path | string[] | — | Project directory (will search |
-n, --dry-run | boolean | false | Show what would be updated without making changes |
-f, --force | boolean | false | Force update even if versions match |
Examples
# Update all librarieslibragen update
# Update specific librarylibragen update react-docs
# Preview updates without applyinglibragen update --dry-run
# Update only project-local librarieslibragen update -p ./my-projectconfig
Display current libragen configuration and paths.
libragen config [options]Options
| Option | Type | Default | Description |
|---|---|---|---|
--json | boolean | false | Output as JSON |
Example
libragen config⚙️ Libragen Configuration
Version: 0.1.0
Paths: Home: ~/Library/Application Support/libragen Libraries: ~/Library/Application Support/libragen/libraries Models: ~/Library/Application Support/libragen/models
Active Library Paths (in priority order): 🌐 ~/Library/Application Support/libragen/libraries (global) (no project-local .libragen/libraries found in cwd)
Environment Variables: (none set, using defaults)With a project-local .libragen/libraries directory:
cd /my/projectlibragen config⚙️ Libragen Configuration
Version: 0.1.0
Paths: Home: ~/Library/Application Support/libragen Libraries: ~/Library/Application Support/libragen/libraries Models: ~/Library/Application Support/libragen/models
Active Library Paths (in priority order): 📁 /my/project/.libragen/libraries (project-local) 🌐 ~/Library/Application Support/libragen/libraries (global)
Environment Variables: (none set, using defaults)With environment variable overrides:
LIBRAGEN_HOME=/custom/path libragen config⚙️ Libragen Configuration
Version: 0.1.0
Paths: Home: /custom/path (from LIBRAGEN_HOME) Libraries: /custom/path/libraries Models: /custom/path/models
Active Library Paths (in priority order): 🌐 /custom/path/libraries (global) (no project-local .libragen/libraries found in cwd)
Environment Variables: LIBRAGEN_HOME=/custom/pathEnvironment Variables
| Variable | Description |
|---|---|
LIBRAGEN_HOME | Override base directory for all libragen data |
LIBRAGEN_MODEL_CACHE | Override model cache directory |
Use libragen config to see current values and which environment variables are active.
autocomplete
Set up shell completions for bash, zsh, and fish.
libragen autocomplete [SHELL]Arguments
| Argument | Description |
|---|---|
SHELL | Shell type: bash, zsh, or fish (optional) |
Examples
# Display autocomplete installation instructionslibragen autocomplete
# Set up for specific shelllibragen autocomplete bashlibragen autocomplete zshlibragen autocomplete fishFeatures
Shell completions provide:
- Command completion - Tab-complete all libragen commands
- Option completion - Tab-complete command options
- Typo suggestions - Get suggestions when you mistype a command
cli-update
Update the libragen CLI to the latest version.
libragen cli-update [options]Options
| Option | Description |
|---|---|
--check, -c | Check for updates without installing |
Examples
# Update to latest versionlibragen cli-update
# Check if updates are availablelibragen cli-update --checkExit Codes
| Code | Description |
|---|---|
0 | Success |
1 | General error |
2 | Invalid arguments |