Skip to main content

CLI reference

GRAIL's CLI is a wrapper over the Python SDK. Each subcommand performs one concrete operation and returns results with standard exit codes.

All commands take a project directory as the first positional argument.

Master table

CommandWhat for
grail initCreate a new project
grail indexFull indexing pipeline (KB mode)
grail queryQuery an indexed project
grail appendAdd files to an existing KB
grail editReplace a KB file's content
grail deleteRemove files from a KB
grail create-entitiesDiscover entity types from a corpus sample
grail consolidateGenerate memory proposals (memory mode)
grail proposals list/applyReview and apply proposals
grail chatInteractive terminal chat
grail uiWeb chat (FastAPI + React)
grail vizHTML visualisation of the graph
grail exploreBrowse project artefacts
grail export-neo4jExport the graph to Neo4j
grail statusArtefact status
grail config showResolved project configuration
grail prompt list/showInspect the prompt registry

grail init

Creates a new project. Default: knowledge_base mode. With --memory, memory mode.

grail init <project_dir> [options]
FlagTypeDescription
--name NAMEstringProject name. Default: directory name.
--memoryboolCreate a memory-mode project (memories/ folder).
--template NAMEstringPre-configured template (low_cost_setup, etc.). Excludes --memory.
--templates-dir DIRpathExtra directory for your own templates.
--list-templatesboolList available templates and exit.
--overwriteboolOverwrite an existing scaffold.
--git / --no-gitboolInitialise git repo. Default: on for memory, off for KB.

Examples:

# KB with low-cost template (recommended starter)
grail init ./my-kb --name my-kb --template low_cost_setup

# Memory with git auto-initialised
grail init ./my-mem --memory

# List available templates
grail init --list-templates

grail index

Runs the full indexing pipeline: chunking → extraction → communities → reports.

grail index <project_dir> [options]
FlagTypeDescription
--discover-entities / --no-discover-entitiesboolLLM proposes entity types from the corpus before extraction.
--vectorstore NAME, --vsstringVector store: lancedb (default) | faiss | chromadb.

Examples:

grail index ./my-kb
grail index ./my-kb --discover-entities --vs faiss

grail query

Answers a question against an indexed project.

grail query <project_dir> "<question>" [options]
FlagTypeDescription
--mode MODE, -mstringlocal (default) · cascade · global · document · agent · recall
--document NAME, -dstringRequired for --mode document. File name/path/doc-id.
--rerank / --no-rerankboolOverride reranker config for this query.
--trace DIR, -tpathDump prompts, responses, and context to JSON.
--output FMT, -ostringtext (rich panel) or json.
--vectorstore NAMEstringOverride vector store for this query.

Recall filters (combinable with any mode):

FlagTypeDescription
--since DELTAstringISO-8601 (2026-05-01) or relative (1h, 7d, 2w).
--before DELTAstringSame as --since but upper bound.
--category GLOBstringFolder glob (work/clients/**).
--tag TAGstringTag filter (repeat for "any of these").
--entity-name NAMEstringRestrict to observations mentioning this entity.
--type TYPEstringRestrict to entities of this type (PERSON, ORGANIZATION, ...).
--min-confidence FLOATfloatMinimum confidence.

Examples:

# Classic cascade
grail query ./my-kb "How much does FONASA cover?" --mode cascade

# Agent with trace
grail query ./my-kb "Compare X and Y" --mode agent --trace ./traces

# Pure recall (no LLM)
grail query ./my-mem --mode recall --since 7d --tag decision

# Cascade scoped to recent memory
grail query ./my-mem "Why did Acme pick Postgres?" \
--mode cascade --since 30d --category "work/clients/acme/**"

# JSON output for scripts
grail query ./my-kb "..." --mode cascade --output json

grail append / grail edit / grail delete

Incremental updates to the KB. Only re-extract affected chunks.

grail append <project_dir> file1 [file2 ...]
grail edit <project_dir> --name NAME --src LOCAL_PATH
grail delete <project_dir> name1 [name2 ...]

Examples:

grail append ./my-kb papers/2026-new.pdf docs/spec.md
grail edit ./my-kb --name spec.md --src /tmp/spec-updated.md
grail delete ./my-kb obsolete.txt draft.md

grail create-entities

LLM proposes entity types reading a corpus sample. Useful for specialised domains (legal, medical, technical).

grail create-entities <project_dir> [--write]
FlagTypeDescription
--writeboolPersist proposed types into grail.yaml.

Without --write, only prints types to stdout.


grail consolidate (memory mode)

Runs proposal analyses: Leiden + edge density + alias detection + folder split.

grail consolidate <project_dir> [--output text|json]

Key behaviour: nothing mutates. Only generates a file output/proposals/<timestamp>.json with proposals for review.


grail proposals list / grail proposals apply

Inspect and apply proposals generated by consolidate.

grail proposals list <project_dir> [--status pending|accepted|rejected]
grail proposals apply <project_dir> [--accept ID] [--reject ID]

Examples:

grail proposals list ./my-mem
# 5 pending proposals:
# abc123: merge_aliases (confidence 0.92)
# def456: discover_community (confidence 0.78)
# ...

grail proposals apply ./my-mem --accept abc123
grail proposals apply ./my-mem --reject def456

grail chat (TUI)

Terminal chat with SQLite-persisted sessions. Streaming, slash commands, markdown render.

grail chat <project_dir> [options]
FlagTypeDescription
--mode MODE, -mstringInitial mode: agent (default) | local | cascade | global | document.
--session ID, -sstringResume existing session (by ID prefix).
--db PATHpathOverride SQLite (default: <project>/.grail/chat.db).

Inside the chat, use /help to see available slash commands.


grail ui (web chat)

Web chat with FastAPI backend and React frontend.

grail ui <project_dir> [options]
FlagTypeDescription
--host HOST, -hstringBind address. Default: 127.0.0.1.
--port PORT, -pintPort. Default: 8765.
--devboolEnables CORS for Vite dev server on :5173.
--debugboolPrints every LLM prompt and response with colours.

grail viz

Renders the entity+relationship graph to an interactive HTML.

grail viz <project_dir> [options]
FlagTypeDescription
--output FILE.htmlpathOutput HTML path. Default: <project>/graph.html
--open-browserboolOpen the HTML after generating.
--layout-seed NintLayout seed (for reproducibility).
--layout-iterations NintForce-directed layout iterations.

grail explore

Interactive browser of project artefacts (documents, entities, relationships, communities).

grail explore <project_dir> [--output text|json]

grail export-neo4j

Pushes the graph to a Neo4j database.

grail export-neo4j <project_dir> [options]
FlagTypeDescription
--uri URIstringBolt URI. Default: bolt://localhost:7687.
--username USERstringDefault: neo4j.
--password PWstringPassword.
--database DBstringDatabase name. Default: neo4j.
--clearboolClear the database before loading.
--no-apocboolDon't use APOC procedures (compatibility).
--batch-size NintUNWIND batch size. Default: 1000.

grail status

Shows which artefacts exist, their size and date.

grail status <project_dir>

grail config show

Prints the resolved configuration (after defaults, env vars, and merges).

grail config show <project_dir>

Useful for debugging: see exactly which config GRAIL will use.


grail prompt list / grail prompt show

Inspects the prompt registry (built-in + custom).

grail prompt list [<project_dir>]
grail prompt show <prompt_name> [<project_dir>]

Example:

grail prompt list # list available prompts
grail prompt show entity_relation # see the full extraction prompt

Global environment variables

VariablePurpose
GRAIL_LOG_LEVELLog level for the grail.* logger. Default: WARNING.
OPENAI_API_KEYAPI key for openai endpoint.
DEEPINFRA_API_KEYAPI key for deepinfra endpoint.
ANTHROPIC_API_KEYAPI key for anthropic endpoint.
TOGETHER_API_KEYAPI key for together endpoint.
GROQ_API_KEYAPI key for groq endpoint.
OPENROUTER_API_KEYAPI key for openrouter endpoint.

API keys are also read from the project's .env file if it exists.


Exit codes

CodeMeaning
0OK
1User error (invalid argument, missing file)
2Configuration or API error (LLM unavailable, missing key)

Next step