Skip to main content
The Ditto CLI is in preview. Commands, options, and output can change between releases. This page covers version 0.3.0.
dittosh is the Ditto command-line tool. It runs DQL statements against a local Ditto store on your machine, so you can try queries, check query plans, and measure performance from a terminal without writing an app. It also loads sample datasets, teaches DQL with interactive lessons, and installs Ditto skills into AI coding agents. After you load the movies sample dataset (see Quickstart), a query looks like this:
dittosh runs entirely on your machine. It ships with a built-in offline license, so you don’t need a Ditto account or credentials, and it never syncs: it doesn’t connect to the Ditto Server or to other peers. All your data stays in one local folder (see Data directory). dittosh uses the Ditto Node.js SDK 5.2.0, so queries behave the same way they do in an app on that SDK version.

Requirements

  • One of these platforms:
    • macOS on Apple silicon (arm64)
    • Linux x64 or arm64
    • Windows x64 (npm only)
  • One of these package managers:
    • Homebrew on macOS or Linux
    • npm with Node.js 22 or later
Intel Macs are not supported.

Install

1

Install dittosh

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.
Newer Homebrew versions only load formulas from trusted taps. If 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

This prints the dittosh and Ditto SDK versions, how dittosh was installed, when the built-in license expires, and where your data lives. Add --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:
If brew upgrade says the tap is untrusted, run brew trust getditto/tap once and upgrade again.

Uninstall

To also remove the Node.js runtime that Homebrew installed for dittosh, run brew autoremove.
Uninstalling leaves your data directory and config directory in place. To delete your local store first, see Data directory.

Quickstart

To learn dittosh by doing, run 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

Run dittosh 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:
You can feed one query’s results into another query’s parameters:
To save results, use -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:
In table, vertical, Markdown, and HTML output, attachments appear as [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

Run dittosh 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.
The Total, Count, Avg, and Peak columns cover the whole session. The Change, New, p50 through p99, and Max columns cover the time since you last ran .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 a dittosh dql command to see how Ditto runs a query:
  • --explain prints the plan from EXPLAIN as a tree of operators.
  • --profile runs the query with PROFILE and 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.
  • --advise runs ADVISE instead of the query and prints the indexes that would help, with ready-to-run CREATE INDEX statements. It doesn’t print query results.
    Add --apply to create the suggested indexes. dittosh asks before it creates anything; add -y to skip the prompt. Without a terminal to prompt in, such as in a script, --apply creates 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 show lists 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; run reset first 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. --setup creates the query’s index first. Queries that write data need --yes, and clean up after themselves. run also takes --time, --explain, --profile, -o, --format, and --max-rows, and benchmarks the query with --runs and --warmup (see Benchmark queries).
  • reset: evicts all documents in the dataset’s collections.

Collections and indexes

These read the 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:
Or NDJSON, with one object per line. dittosh detects the format from the first character of the file.
  • 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.
  • _id is optional. Documents without one get a generated ID.
  • When a document with the same _id already 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 _id values. Documents without an _id are 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.
  • --warmup runs 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 exactly n times. Without --warmup, there’s no warmup.
  • p50_ms is the median. p95_ms and p99_ms are taken from the sorted run times, so with 20 runs or fewer p95_ms is the slowest run, and with 100 runs or fewer p99_ms is 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:
Measure an insert, undoing it after each run:
The --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

The interactive tutorial teaches DQL in 27 lessons across beginner, intermediate, and advanced levels. Each lesson explains a concept, shows the syntax, gives you a task, and checks your answer. Most lessons include a note for readers who know SQL. Topics include projection, filtering, sorting, writes, functions, 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 advanced starts at that level.
  • --plain uses 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

The walkthrough is a Markdown file of commands to try, tailored to your install: your dittosh and SDK versions, your platform, and the upgrade command for your install. It covers importing, querying, and exporting data, the interactive shell and .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.
The default skill is write-dql. Others include:
  • SDKs: swift-sdk, kotlin-sdk, and js-sdk
  • JavaScript platforms: js-node, js-web, js-react-native, and js-expo
  • Concepts: data-modeling, data-streams, ditto-mesh-networking, sync-subscriptions, and native-app-config (Apple and Android permissions)
Run 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:
  1. The -d, --data-dir <path> option
  2. The DITTOSH_DATA_DIR environment variable
  3. The default for your OS:
    • macOS: ~/Library/Application Support/dittosh
    • Linux: ~/.local/share/dittosh
    • Windows: %LOCALAPPDATA%\dittosh\Data
Use -d to keep separate stores, for example one per experiment:
Only one dittosh process can use a data directory at a time. A second process exits with code 4. To delete the whole store, including all collections, indexes, and files:
delete-store permanently deletes the data directory and can’t be undone. It requires --yes, and it refuses to run while another process has the store open. To remove only a sample dataset’s documents, use dittosh dql dataset reset <name> --yes.

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

This runs the 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.md and report.json, with:
    • dittosh and Ditto SDK versions, how dittosh was installed, OS, CPU, memory, and terminal details
    • the doctor checks
    • 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
The report never includes the license token. The store summary doesn’t include document contents, but the last failed command is saved as typed, so values in that statement appear in the report. 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.
dittosh includes the SDK support bundle as Ditto creates it. Its logs and configuration contain the database ID, full file paths, and peer keys. Extract the report and review it before you post it publicly, or use --no-sdk-bundle.
When Ditto support asks only for the SDK support bundle, save it with:
The SDK creates at most 3 bundles per store every 10 minutes, and 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.