The Ditto CLI is in preview. Commands, options, and output can change between releases. This page covers version 0.3.0.
movies sample dataset (see Quickstart), a query looks like this:
Requirements
- One of these platforms:
- macOS on Apple silicon (arm64)
- Linux x64 or arm64
- Windows x64 (npm only)
- One of these package managers:
Intel Macs are not supported.
Install
1
Install dittosh
- Homebrew
- npm
Homebrew installs the Node.js runtime that dittosh needs and keeps only your platform’s copy of the Ditto SDK, so dittosh takes about 150 MB on macOS and 180 MB on Linux.
brew reports Refusing to load formula getditto/tap/dittosh from untrusted tap, run brew trust getditto/tap and try again.2
Check the install
doctor checks your platform, Node.js, the data directory, the built-in license (shown as token), the Ditto SDK, and whether another process has the store open:dittosh dql doctor runs the same checks.3
Show versions
--format json for machine-readable output.Update
update checks for a newer release, works out whether you installed with Homebrew or npm, and runs the matching upgrade command. Add --check to only check. To upgrade by hand, use the package manager you installed with:
- Homebrew
- npm
brew upgrade says the tap is untrusted, run brew trust getditto/tap once and upgrade again.Uninstall
- Homebrew
- npm
brew autoremove.Quickstart
dittosh tutorial. It writes dittosh-tutorial.md, a hands-on walkthrough tailored to your install. See Tutorials and lessons.
Run DQL
dittosh dql runs DQL statements. It accepts a statement in several ways:
dittosh dql exec is the same command under an explicit name.
When you run statements from a file or stdin, dittosh stops at the first failure. Add --continue-on-error to run the rest.
Parameters
Bind:name parameters with -p, or pass them all at once as a JSON object with --args:
-p is repeatable. Its values are parsed as JSON when possible and treated as strings otherwise, so -p year=2000 binds the number 2000. To bind the string "2000", use -p 'year="2000"' or --args. --args - reads the JSON object from stdin, and --args @file reads it from a file.
Options
Rundittosh dql -h to see these options from the command line at any time.
Output formats
In a terminal, results print as a table that fits the window width; long values are shortened with…, and long results open in a pager. Use --format vertical to print one block per row with nothing shortened.
When you pipe or redirect the output, dittosh prints JSON. Query results go to stdout, and progress, warnings, and diagnostics go to stderr, so you can pipe results into tools like jq:
-o. Results written to a file include every row unless you set a limit with --max-rows. dittosh prints a one-line summary of what it wrote:
[attachment …] placeholders, because attachment data isn’t returned through DQL. JSON and CSV output include the attachment’s metadata object.
CSV output doesn’t escape values that start with
=, +, or @. Spreadsheet apps can treat these as formulas, so review CSV files from untrusted data before you open them in Excel or a similar app.Interactive shell
Rundittosh dql with no statement to open an interactive shell. End each statement with ;; a statement can span several lines. The shell keeps a history and prints how long each statement took.
Options you pass when you open the shell, such as --profile or --format vertical, apply to every statement you run in it.
System metrics
.metrics shows the Ditto SDK’s live system metrics for the session as tables. By default it shows two sections:
- Store metrics: SQLite transactions, fsync calls, WAL size, and commit and lock timings.
- Query metrics: DQL requests, selects, failures, and parse, plan, and execution times.
.metrics, so you can run a statement and then see what it cost.
Name one or more sections to see just those, for example .metrics query or .metrics store query. The sections are store, query, network, sync, transport, discovery, peer, and other. .metrics all shows every section.
Analyze queries
Add these options to adittosh dql command to see how Ditto runs a query:
-
--explainprints the plan fromEXPLAINas a tree of operators. -
--profileruns the query withPROFILEand shows a summary followed by an operator tree. Each operator shows its execution, receive, send, and storage wait times, document counts (including skipped documents), and scheduler yields by reason. Join subplans appear as nested trees, and operators that take 50% or more of the execution time are marked with▲. The summary also shows the request type, feature flags, and directives. -
--adviserunsADVISEinstead of the query and prints the indexes that would help, with ready-to-runCREATE INDEXstatements. It doesn’t print query results.Add--applyto create the suggested indexes. dittosh asks before it creates anything; add-yto skip the prompt. Without a terminal to prompt in, such as in a script,--applycreates indexes only when you also pass-y.
--explain, --profile, and --advise work with SELECT statements only. When you use --advise, dittosh ignores --explain and --profile. In a terminal, the plan and profile print with the results. When you pipe the output, they go to stderr so they don’t mix with the JSON results.
To learn how indexes affect queries, see Indexing.
Sample datasets
dittosh includes three sample datasets. Each one comes with a catalog of named queries you can run.
The data is generated on your machine when you load it.
load:--docs <n>sets the size of the dataset’s main collection, and the related collections grow with it.dataset showlists how each collection scales.--seed <n>makes the generated data reproducible (the default seed is 42). Loading again with a different seed adds more documents; runresetfirst to start over.--batch-size <n>sets how many documents are inserted at a time (default 500).run: prints the statement on stderr, then runs it. Query names are looked up across all datasets; add--dataset <name>if a name matches more than one.--setupcreates the query’s index first. Queries that write data need--yes, and clean up after themselves.runalso takes--time,--explain,--profile,-o,--format, and--max-rows, and benchmarks the query with--runsand--warmup(see Benchmark queries).reset: evicts all documents in the dataset’s collections.
Collections and indexes
system:collections and system:indexes virtual collections. Create and drop indexes with DQL:
Import your own data
dittosh dql import loads documents from a JSON file into a collection. The file can be a JSON array of objects:
- The collection is created when the first document is inserted. Collection names can contain letters, digits, and underscores, and can’t start with a digit.
_idis optional. Documents without one get a generated ID.- When a document with the same
_idalready exists, the import updates it with the fields in the file and keeps its other fields. Importing the same file again is safe when its documents have_idvalues. Documents without an_idare added again as new documents. - Large files are inserted in batches of 500 documents. Change this with
--batch-size <n>.
Benchmark queries
dittosh dql bench runs a statement many times and reports how long it took:
--runs <n>sets the number of timed runs, from 1 to 10,000. The default is 50.--warmupruns the statement first without timing it, enough times to fill about 250 ms, so cold caches and query planning don’t skew the results.--warmup <n>runs it exactlyntimes. Without--warmup, there’s no warmup.p50_msis the median.p95_msandp99_msare taken from the sorted run times, so with 20 runs or fewerp95_msis the slowest run, and with 100 runs or fewerp99_msis the slowest run. Use more runs to measure the tail.- Times are measured by dittosh, so they include the time to convert results for display. Compare results from the same machine and the same data.
Set up and clean up
Statements that change data or indexes need setup so that every run does the same work. These options run statements without timing them, and each one is repeatable:--reset is another name for --before-each.
Measure a query with an index:
--pre evict removes a document left behind by an interrupted run. dittosh warns you when an INSERT, EVICT, or DELETE benchmark runs more than once without --before-each or --after-each.
Benchmark files
To run a set of benchmarks, put them in a JSON file. Each key names a benchmark:
The file can also be a JSON array of benchmarks, each with an optional
name, or a single benchmark object with query at the top level. dittosh rejects unknown keys, and suggests the right key for common misspellings such as prequeries, so a typo can’t silently skip an index.
--example writes a sample file for movies, retail, retail-joins, or pos, with an explanation in each entry’s description. Load that dataset to run the sample as is.
Results go to stdout as a table in a terminal or JSON when piped, and -o saves them to a file. To compare a change, such as a new index, save results before and after with -o before.json and -o after.json. The command exits with code 1 if any benchmark fails, and 2 if the file is invalid.
You can also benchmark a query from a dataset’s catalog. Add --setup to create the query’s index first:
Tutorials and lessons
Interactive DQL lessons
CASE, MISSING and NULL, aggregation and grouping, joins, ANY … SATISFIES, indexes, query plans, USE IDS, and the system collections.
Lessons run in a separate practice store, so your own data is never changed, and your progress is saved between sessions.
The lessons open full screen. The lesson stays at the top, results scroll below it, and the result of your last answer (✓ or ✗) stays above the prompt.
The shell commands
.hint, .answer, .next, .back, .lessons, .level <name>, .goto <n>, .schema, .reset, .break, and .exit work too.
These options work with --interactive:
--level beginner,--level intermediate, or--level advancedstarts at that level.--plainuses a simple line-by-line shell instead of the full-screen view. dittosh also uses it when the terminal is smaller than 60 × 20.-d <path>keeps the practice store in a different directory.
dittosh walkthrough
.metrics, sample datasets, query analysis, benchmarking, joins, system collections, and agent skills.
AI agent skills
dittosh skills installs Ditto skills from the getditto/agent-skills repository into AI coding agents, so they write correct DQL and SDK code.
write-dql. Others include:
- SDKs:
swift-sdk,kotlin-sdk, andjs-sdk - JavaScript platforms:
js-node,js-web,js-react-native, andjs-expo - Concepts:
data-modeling,data-streams,ditto-mesh-networking,sync-subscriptions, andnative-app-config(Apple and Android permissions)
dittosh skills add --all to get every skill in the repository.
add skips skills that are already installed; add --force to overwrite them. Use update to move to a newer release, or update --ref <tag> to move to a specific one. list and update work on global installs unless you pass --project <path>. The skills commands accept --format table|json|csv.
Companion skills
Some skills link to files in other skills, and those links only work when both skills are installed.dittosh skills add installs the linked skills too, and lists them on stderr and as companion of <skill> in the results. With agent-skills v0.6.1:
Companions that are already installed show as
present. Add --no-deps to install only the named skill; later updates of that install don’t add companions either. update installs companions that a newer release adds, unless you pass --no-deps.
Copilot and Windsurf get one file per skill, so links between skills can’t work there, and dittosh doesn’t install companions for them.
Agents and locations
dittosh detects agents from their folders in your home directory and in the current directory. If it finds none, pass--agent.
Cursor, Copilot, and Windsurf support project installs only, so use
--project with them.
Data directory
dittosh keeps the local store in one data directory. It picks the directory in this order:- The
-d, --data-dir <path>option - The
DITTOSH_DATA_DIRenvironment variable - The default for your OS:
- macOS:
~/Library/Application Support/dittosh - Linux:
~/.local/share/dittosh - Windows:
%LOCALAPPDATA%\dittosh\Data
- macOS:
-d to keep separate stores, for example one per experiment:
4.
To delete the whole store, including all collections, indexes, and files:
Global options
These options work with every command:dittosh --version (or -V) prints the dittosh version.
Environment variables
Exit codes
Troubleshooting
Common problems
See SDK logs
--debug turns on the Ditto SDK’s debug logs and prints a stack trace when a command fails unexpectedly. Everything goes to stderr, so the results on stdout don’t change.
Report a problem
doctor checks and writes dittosh-report-<time>.tar.gz to attach to a GitHub issue. Pass a path to choose where it’s written, for example dittosh doctor --report ~/Desktop/report.tar.gz. The file contains:
report.mdandreport.json, with:- dittosh and Ditto SDK versions, how dittosh was installed, OS, CPU, memory, and terminal details
- the
doctorchecks - paths, store size, and free disk space
- dittosh settings, with credential variables shown only as set or not set
- a store summary: collection names, document counts, and indexes
- the last command that failed, as you typed it, with its exit code and error output
ditto-support-bundle.tar, the Ditto SDK support bundle with the SDK’s debug logs and the store configuration with secrets removed
report.md and report.json show your home folder as ~. --no-store leaves out the store summary, and --no-sdk-bundle leaves out the SDK support bundle.
When Ditto support asks only for the SDK support bundle, save it with:
doctor --report counts toward that limit. After that, dittosh saves the newest existing bundle and tells you so. To learn what a bundle contains, see Capturing Support Bundles.