CLI guide

August 26, 2026 · View on GitHub

Documentation · Agents · CLI · MCP · Pipeline · Architecture · Server · Embedding · Roadmap

The zg command is the human and shell interface to the same local search layer used by agents. This page groups the main commands and options; use the installed CLI for version-specific help:

zg help
zg help query
zg help models
zg help file-types
zg help environment
zg <command> --help

Command overview

CommandPurpose
querySearch an index or run managed ripgrep
indexBuild, update, rebuild, or drop a Workspace index
statusInspect Workspace and index state
install / uninstallManage agent integrations
configConfigure provider credentials and model defaults
authManage Remote Embedding authorization
serverManage the shared MCP server
help / versionShow help or the installed version

zg query

zg query <query> [options]
zg query --hybrid <query> --fts <query> --vector <query> [--fuse]
zg query --rg [rg-options] <pattern> [path...]

Search routes:

OptionMeaning
positional queryHybrid lexical and vector retrieval
--hybrid <query>Add an explicit hybrid query group
--fts <query>Add a ranked lexical query group
--vector <query>Add a semantic-only query group
--fuseCombine all groups into one ranked plan
--rgRun exhaustive managed ripgrep without an index

Result controls:

OptionMeaning
--limit <n>Maximum returned items per group
--humanTerminal-oriented output with full previews by default
--preview none|short|fullIndexed source preview size
--refresh background|wait|offIndex refresh policy
--mode direct|server|autoExecution transport
--debugPrint diagnostics to stderr
--traceAdd per-hit indexed search trace
--prefer-symbolPrefer an exact indexed symbol
--symbol-type <type>Restrict results to a symbol type
--modified-after <time>Search files modified after a time
--modified-before <time>Search files modified before a time

Indexed CLI results are separated by query group and preserve the rank assigned inside that group. The CLI does not apply the MCP response's cross-group coverage/global-fill presentation. A result recalled by several groups appears under each of those groups. --limit continues to bound each group.

Valid symbol types are module, class, interface, function, value, and alias.

Common scope options for indexed search are -g/--glob, --iglob, -t/--type, and -T/--type-not. Managed rg additionally supports common ripgrep matching, context, discovery, encoding, and regex-engine flags.

Examples:

zg query "theme preference persistence on startup"
zg query --fts "loadTheme" -g "src/**" -t ts
zg query --vector "where user preferences are restored" --limit 5
zg query --human "plugin lifecycle" --preview full
zg query --rg -i -C 2 -g "*.ts" "dark mode" src

See Retrieval pipeline for route selection and freshness behavior.

zg index

zg index [root] [options]
zg index [root] --rebuild [options]
zg index [root] --drop [--yes]

Core options:

OptionMeaning
--embedding <model>Model for a new or rebuilt index
--rebuildRecreate an existing index
--dropPermanently remove the Workspace index
--yesConfirm --drop without a prompt
--reset-pathsReplace stored file-selection settings
--mode direct|server|autoExecution transport
--api-key <key>One-command provider credential
--endpoint <url>Remote provider endpoint
--model-cache <path>Local model cache directory
--device <device>auto, cpu, metal, vulkan, or cuda
--embedding-concurrency <n>Concurrent Embedding tasks
--allow-remoteAuthorize Remote Embedding for this command

Local Potion embedding tasks run on worker threads. They default to two workers; --embedding-concurrency can override that value for larger machines.

File discovery accepts -g/--glob, --iglob, -t/--type, -T/--type-not, --hidden, --no-ignore, --ignore-file, --max-depth, --max-filesize, and -L/--follow.

Examples:

zg index --embedding local/potion-code-16m-v2
zg index
zg index --rebuild --embedding local/jina-embeddings-v2-base-code
zg index --drop --yes

zg status

zg status [root] [--mode direct|server|auto] [--check-ready]

Status includes the selected root, index policy, stored schema and paths, file counts, refresh state, and a suggested next action. --check-ready preserves normal output and exits non-zero unless the index is ready, which is useful in scripts.

zg install and zg uninstall

zg install [--target codex|claude|qwen|opencode|cursor|all|auto] [--mcp-transport stdio|http] [--mcp-toolset agent|full] [--yes] [--force]
zg uninstall [--target codex|claude|qwen|opencode|cursor|all|auto] [--yes]

--target is repeatable. zg install also accepts:

OptionMeaning
--mcp-transport <stdio|http>MCP connection mode; default stdio
--mcp-toolset <agent|full>Daemon MCP surface; default agent
--mcp-tool-timeout <seconds>Codex, Qwen Code, and OpenCode MCP timeout; default 600 seconds
--mcp-token-env <name>Environment variable containing the server token
--forceReplace a conflicting unmanaged zvec_grep entry

See Agent integrations before using --force.

zg config

zg config provider set <provider> --api-key <key>
zg config model set <model> [--endpoint <url> | --device <device>] [--default]

Examples:

zg config provider set qwen --api-key "$DASHSCOPE_API_KEY"
zg config model set qwen/text-embedding-v4 --default
zg config model set local/potion-code-16m-v2 --device metal

Global configuration is stored in ~/.zvec-grep/config.json. Existing indexes continue to use their stored model until explicitly rebuilt.

zg auth

zg auth grant [root] --capability embedding --scope workspace [--embedding <model>]
zg auth status [root]
zg auth revoke [root]

Workspace grants are stored under .zvec-grep/authorization.json and shared by the CLI and MCP server. --allow-remote is the non-persistent alternative for one query or index command. --embedding selects the Remote Embedding model to authorize; it does not run embedding. It may be omitted when the model can be resolved from the existing Workspace index, ZVEC_GREP_EMBEDDING, or the global default, in that order.

zg server

zg server on [--listen 127.0.0.1:7999] [--token-file <path>] [--mcp-toolset agent|full]
zg server off [--token-file <path>]
zg server status [--check-ready]
zg server run [--listen 127.0.0.1:7999] [--token-file <path>] [--mcp-toolset agent|full]

on starts the background daemon; run keeps it in the foreground. The server only accepts loopback listen addresses. The default public endpoint is http://127.0.0.1:7999/mcp with the agent toolset.

See Server and execution modes for mode selection, lifecycle, refresh, authentication, and logs. See MCP for the tool contract.

Environment variables

VariablePurpose
ZVEC_GREP_HOMEOverride zvec-grep state directory
ZVEC_GREP_MODEDefault direct, server, or auto transport
ZVEC_GREP_SERVER_URLOverride the MCP server URL used by clients
ZVEC_GREP_SERVER_TOKENServer/client Bearer token
ZVEC_GREP_SERVER_TOKEN_FILEFile containing the server/client token
ZVEC_GREP_MCP_TOOLSETDefault agent or full MCP surface
ZVEC_GREP_EMBEDDINGDefault model for new indexes
ZVEC_GREP_API_KEYEmbedding provider API key
ZVEC_GREP_ENDPOINTRemote Embedding endpoint
ZVEC_GREP_MODEL_CACHELocal model cache directory
ZVEC_GREP_DEVICELocal model device
DASHSCOPE_API_KEYQwen API-key fallback after ZVEC_GREP_API_KEY
QWEN_API_KEYQwen API-key fallback after DASHSCOPE_API_KEY
QWEN_HOMEQwen Code configuration directory used by zg install

Run zg help environment for advanced variables, agent integration paths, scope, and detailed precedence. A new index selects its model in this order: explicit --embedding, ZVEC_GREP_EMBEDDING, then the global default. Existing indexes continue to use their stored model unless --embedding and --rebuild explicitly change it.

Embedding runtime values such as endpoint and device retain this order: explicit command option, Workspace snapshot, global configuration, then environment. zg index forwards its ZVEC_GREP_EMBEDDING value in server and auto modes; direct MCP calls use the environment inherited when the daemon started.