CLI command workflows
The Helix CLI is the user-facing control point for creating a project, connecting it to local or Enterprise Cloud databases, running queries, diagnosing setup, and inspecting runtime state. It turns one command into the right local runtime action or authenticated Cloud request while keeping project links and instance names as the main user model. See also CLI and operations and CLI local runtime.
Command model
Command dispatch
The CLI parses one top-level command and sends it to the matching workflow. The command set groups setup, local development, Cloud access, query work, and CLI maintenance so that the same entry point can serve both a developer terminal and scripted operations. Bare help is available without project setup or network access. Command-specific help remains available through helix <command> --help. crates/…/main.rs• L44-59 crates/…/main.rs• L476-504
Global output flags shape the result of a workflow rather than its target: --quiet limits normal output and --verbose adds detail and timing. A failed workflow returns a non-zero process status and renders a user-facing error with a recovery hint when one is available. crates/…/main.rs• L48-55 crates/…/main.rs• L738-755
Project context
Most project commands start by finding helix.toml in the current directory or one of its parents. That file defines the project and its named local or Cloud instances, while .helix/ provides per-instance working state. This lets a user run commands from a nested project directory without repeating the project path. crates/…/project.rs• L6-45 crates/…/project.rs• L62-78
An instance name is the normal target for status, logs, lifecycle actions, and queries. If a query target is omitted, the CLI prefers dev, then uses the only configured instance; it stops and asks for an explicit target when more than one choice remains. crates/…/query.rs• L28-49
The main command path is therefore a short sequence from user input to project context, target selection, and either local or Cloud work.
flowchart TD
A[CLI command] --> B[Parse command and options]
B --> C[Load project context]
C --> D{Target kind}
D -->|Local instance| E[Use local runtime or gateway]
D -->|Cloud instance or database| F[Require Cloud session]
E --> G[Show result or recovery hint]
F --> G
References: crates/…/main.rs• L634-736 crates/…/project.rs• L12-45 crates/…/query.rs• L22-25
Project setup
Project initialization
helix init creates the starting project boundary. It selects a local development instance or an Enterprise Cloud link, writes the project configuration, and gives the user the next command to run. A local project also receives an example JSON request and agent guidance so the first query can follow a known path. crates/…/init.rs• L14-18 crates/…/init.rs• L63-114
In an interactive terminal, setup can ask for the project directory, instance kind, name, local port, and storage mode. In a non-interactive terminal, explicit options are used and local setup defaults to a dev instance. Skills and the docs MCP are optional tooling. They can be selected by flag or prompt and do not block project creation if their install is unavailable. crates/…/init.rs• L19-61 crates/…/prompts.rs• L174-198 crates/…/init.rs• L146-177
Instance registration
helix add extends an existing project with another local or Cloud instance. Local entries carry a name, gateway port, and storage choice. Cloud entries carry a database target or enough project and workspace information for the CLI to resolve one. The command rejects a name that is already used, which keeps instance selection stable. crates/…/add.rs• L11-23 crates/…/add.rs• L25-65 crates/…/add.rs• L100-107
The setup workflows create a durable link between a short local name and its actual target. Later commands can use that name, while Cloud commands can use cluster:<id> or tenant:<id> when a direct database reference is needed. crates/…/lib.rs• L33-75 crates/…/config.rs• L1
References: crates/…/init.rs• L39-114 crates/…/add.rs• L11-68 crates/…/prompts.rs• L159-220
Cloud access and resources
Cloud authentication
helix auth login establishes the WorkOS session used by Cloud workflows. It requires an interactive terminal, opens a browser-based sign-in flow, accepts an email check when required, and stores the resulting session for later commands. helix auth status checks the session and shows the account and workspace count. helix auth logout tries to revoke the remote session and then removes the local session. crates/…/auth.rs• L40-45 crates/…/auth.rs• L48-119 crates/…/auth.rs• L168-205
Cloud commands use the same gate before they contact Cloud. When no usable session exists, the CLI stops with a message that points to helix auth login instead of sending an unauthenticated request. crates/…/auth.rs• L199-204
Workspace and project discovery
Cloud discovery moves from broad scope to a linked project. Engineers can list or inspect workspaces, list or inspect projects in a workspace, create or delete projects, and link the current helix.toml to a project. A link records the Cloud project and workspace so later commands can infer ownership. crates/…/config.rs• L24-43 crates/…/config.rs• L44-143
Cluster discovery follows the same scope rules. The CLI can list or inspect clusters and indexes by explicit IDs or by the project link. When a workspace is not stored locally, it resolves the workspace from the remote project. crates/…/config.rs• L146-210
Database lifecycle
helix database provides the Cloud database view used by setup and query work. It can list databases in a project, inspect a database, create or delete a tenant database, and list active indexes. Database creation displays the new application key once and does not store it. Deletion needs confirmation or --yes in automation. crates/…/cloud_resources.rs• L14-139 crates/…/cloud_resources.rs• L376-388
The CLI treats a dedicated cluster and a tenant as different database references. Automatic selection is allowed only when the project resolves to exactly one usable database. If several databases match, the user must pass an explicit database reference to avoid acting on the wrong resource. crates/…/cloud_resources.rs• L246-356
Application and service credentials
Database keys give applications read-only or read-write access to one database. Service credentials give headless tools access to selected projects through project and query grants. Both workflows show a secret token once, and later list or inspect operations return metadata rather than the secret. Updates change service-credential metadata and grants without rotating its secret. crates/…/lib.rs• L321-447 crates/…/cloud_resources.rs• L142-315
The CLI checks grant relationships before sending them to Cloud. A write grant must include its matching read grant, and each project and permission can appear only once. This keeps the permission request aligned with the access model rather than leaving invalid combinations for the service to reject. crates/…/cloud_resources.rs• L391-468
References: crates/…/auth.rs• L48-205 crates/…/config.rs• L24-212 crates/…/cloud_resources.rs• L14-188 crates/…/cloud_resources.rs• L193-352
Query workflows
Query request inputs
helix query accepts one complete query request from a JSON file, an inline JSON value, a TypeScript DSL expression, or a TypeScript DSL file. The CLI converts the selected input into one request and checks that it declares a lower-case read or write request type and includes a query. Input modes are mutually exclusive. crates/…/main.rs• L167-211 crates/…/query.rs• L191-250
The --warm option is limited to local read requests. It asks the local gateway to prepare read data before returning the result. Cloud queries and writes reject this option so the command does not imply a local cache contract where none exists. crates/…/query.rs• L61-83 crates/…/query.rs• L236-250
Local and Cloud query routing
The query target decides how the request travels. A named local instance uses its configured gateway port, with optional host and port overrides. A named Cloud instance or an explicit cluster:<id> or tenant:<id> reference uses the authenticated query broker. The response is printed as formatted JSON by default or as one compact line with --compact. crates/…/query.rs• L52-125 crates/…/query.rs• L127-178
This routing keeps the request shape consistent while changing only the connection boundary.
flowchart LR
A[Request file, JSON, or TypeScript] --> B[Parse and validate request]
B --> C{Target}
C -->|Local name| D[Local v2 query gateway]
C -->|Cloud name or database reference| E[Authenticated Cloud broker]
D --> F[JSON response]
E --> F
When a local gateway cannot be reached, the error names the instance and endpoint and points to helix start and helix status. This makes a connection failure an actionable runtime state rather than a generic HTTP error. crates/…/query.rs• L85-107 crates/…/query.rs• L181-189
Interactive query shell
helix shell provides a line-oriented query session for repeated v3 JSON requests. Each non-empty line is one request, and :quit, :exit, quit, or exit ends the session. It uses the same target resolution and execution path as helix query, so local and Cloud targets follow the same access rules. crates/…/shell.rs• L5-36
The shell reports an invalid line and continues, which suits exploration. A request error is also shown at the prompt instead of ending the whole session. crates/…/shell.rs• L20-35
References: crates/…/query.rs• L11-25 crates/…/query.rs• L52-178 crates/…/shell.rs• L8-36
Runtime observation
Instance status
helix status presents the project and then reports one or all configured instances. Local status describes the gateway address, runtime state, and storage mode. Cloud status reads the linked cluster or tenant and shows the service state. With several instances, an interactive terminal can select one; otherwise the command reports all instances unless a name is supplied. crates/…/status.rs• L10-31 crates/…/status.rs• L34-103
Status is the shared check for both local and Cloud workflows. It does not start a missing local runtime or change Cloud state. It tells the user which next operation is needed. crates/…/status.rs• L48-103
Instance logs
helix logs adapts to the target kind. Local logs come from the local runtime and can be followed with --follow. Cloud logs are query-error records over a time range; the default range is the last hour and Cloud live streaming is not supported. crates/…/mod.rs• L10-71 crates/…/mod.rs• L74-113
The distinction matters during diagnosis: local logs explain runtime and container behavior, while Cloud logs show recorded query failures. A Cloud user must omit --follow and can pass RFC 3339 start and end times for a different window. crates/…/mod.rs• L19-49
Local instance lifecycle
helix start, helix stop, and helix restart control local instances only. Start runs in the background by default and can run in the foreground for attached work. Stop ends a background instance, while restart replaces its running process. These commands reject a Cloud instance because Cloud lifecycle belongs to the control plane. crates/…/start.rs• L8-65 crates/…/stop.rs• L8-23 crates/…/restart.rs• L8-19
Local storage changes the effect of stopping or pruning. In-memory data is lost when the runtime stops or restarts. On-disk data survives a stop but is removed by prune. Remote S3 data is not removed by these local cleanup actions. crates/…/start.rs• L100-125
Instance diagnosis
helix doctor is a read-only checkup for a local instance, a Cloud database, or a server URL. It combines checks that the CLI can perform itself with health and diagnostic checks from the server, then presents one report with a clear result and suggested fixes. It does not create, start, or change resources. crates/…/doctor.rs• L1-12 crates/…/doctor.rs• L118-202
The diagnosis path follows the target type. A local target checks the container runtime, container, and image before checking the running server. A URL target checks only the server. A Cloud target records that infrastructure checks are managed by Helix Cloud, while the CLI version check still applies. crates/…/doctor.rs• L118-169 crates/…/doctor.rs• L286-325
Each check has one of four outcomes: pass, warning, failure, or skipped. Warnings and skipped checks do not fail the command. Any failure makes the command return a non-zero result, while --json, normal output, quiet output, and verbose output provide different views of the same report. crates/…/doctor.rs• L31-61 crates/…/doctor.rs• L182-201 crates/…/doctor.rs• L562-646
The diagnosis flow moves from target resolution to local checks and server checks, then to a summarized report.
flowchart TD
A[Doctor target] --> B{Target type}
B -->|Local instance| C[Check runtime, container, and image]
B -->|Server URL| D[Check server]
B -->|Cloud database| E[Mark infrastructure as managed]
C --> F[Check health and diagnostics]
D --> F
E --> G[Build report]
F --> G
G --> H[Render report and exit status]
References: crates/…/doctor.rs• L118-202 crates/…/doctor.rs• L204-245 crates/…/doctor.rs• L455-559
Interactive prompts
Terminal mode
The CLI treats a session as interactive only when both standard input and standard output are terminals. Interactive mode can ask the user to choose a project directory, target kind, instance, workspace, project, or destructive action. Non-interactive mode requires enough command data to make the same choice without asking. crates/…/prompts.rs• L31-33 crates/…/prompts.rs• L35-70
This rule keeps automation predictable. For example, helix add without a target can prompt in a terminal but fails with a command hint when piped. Destructive operations such as database, project, key, and credential deletion require confirmation in a terminal or an explicit --yes in automation. crates/…/add.rs• L15-23 crates/…/cloud_resources.rs• L376-388 crates/…/config.rs• L91-110
Target selection
Prompt selection fills in an omitted target only when the choice is meaningful. A single workspace, project, cluster, or instance is selected automatically. Several choices produce a labeled selection prompt, while no choices produce a clear error. crates/…/prompts.rs• L223-329
The prompt layer is therefore a user interface over the same explicit target rules used by scripts. Supplying a name or ID skips the prompt and makes the intended resource clear. crates/…/status.rs• L34-45 crates/…/mod.rs• L74-89
References: crates/…/prompts.rs• L31-33 crates/…/prompts.rs• L72-145 crates/…/prompts.rs• L223-329 crates/…/add.rs• L11-23
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the top-level command enum, its dispatch match, and the command help groups aligned. A command can parse but remain unreachable if the dispatch arm is missing.
- Preserve the target rule shared by query, status, logs, lifecycle, and diagnosis commands. Changes to default
devselection can silently redirect work. - Keep local instance names and Cloud database references distinct. Cloud references use
cluster:<id>ortenant:<id>and must not be sent to the local gateway or local diagnosis path. - Keep the query input contract in sync with both local
/v2/queryrequests and the Cloud read/write broker. Input validation and--warmrules must agree with the selected route. - Keep one-time token behavior visible in database key and service credential flows. These commands must not imply that a later list or get operation can recover a secret.
- Keep interactive fallbacks paired with non-interactive errors. Any new required choice needs an explicit flag or a stable automation path.
- Keep destructive Cloud and local cleanup actions behind the same confirmation contract.
--yesmust remain the non-interactive escape hatch. - Keep doctor check status values and report output compatible with server diagnostics. Unknown server statuses must remain safe to display without turning a new server result into a false failure.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No helix.toml is found from the current directory upward | Commands that need a project stop before choosing an instance | Run the command inside an initialized project or pass setup inputs to helix init or helix add |
| A query omits its request input or supplies more than one input mode | No request is sent | Provide exactly one of --file, --json, -e/--ts, or --ts-file |
A query has an invalid request type or lacks query | Local or Cloud execution is rejected during preflight | Use lower-case read or write and include the query body |
| A query target is ambiguous | The CLI refuses to guess the database | Pass an instance name or cluster:<id> / tenant:<id> |
| A Cloud command has no active WorkOS session | The Cloud request is not made | Run helix auth login in an interactive terminal |
| A Cloud project resolves to zero or several databases | Setup or a database action cannot select a safe target | Pass an explicit --database or create/link the intended database |
A destructive action runs without --yes in a non-interactive session | The action fails instead of guessing consent | Add --yes only when the automation has approved the action |
helix start or helix query targets a Cloud instance with local-only options | The command rejects the incompatible operation | Use Cloud query routing or target a local instance |
| A local gateway is not listening at the selected host and port | The query fails with a connection error | Start the instance and check helix status, or pass the reachable host and port |
helix doctor cannot reach the selected server or the server returns a failing health response | The reachability check fails and the command exits non-zero | Check the URL or local instance logs, then restart the named local instance when appropriate |
| A local instance has no running container or its container is stopped | Runtime checks fail and server checks are skipped | Run helix start <instance> and run helix doctor again |
A server does not provide GET /v2/diagnostics or returns an unreadable report | Server diagnostics are skipped, so storage and query checks are unavailable | Upgrade the server image when those checks are needed, and treat the skipped result as incomplete rather than healthy |
Key files
| File | Why to read it |
|---|---|
| crates/…/main.rs | Defines the public command tree, global flags, help behavior, and dispatch boundary |
| crates/…/project.rs | Explains how commands locate a project and relate instance names to project state |
| crates/…/init.rs | Shows the user-facing project setup path and the local or Cloud starting point |
| crates/…/add.rs | Shows how a project gains more local or Cloud targets |
| crates/…/auth.rs | Defines the session workflow that gates all Cloud actions |
| crates/…/config.rs | Defines workspace, project, cluster discovery, and project linking |
| crates/…/cloud_resources.rs | Defines database, key, service credential, and generic Cloud API workflows |
| crates/…/query.rs | Defines request input, target resolution, local or Cloud routing, and result output |
| crates/…/shell.rs | Defines the repeated interactive query workflow |
| crates/…/status.rs | Defines the cross-target status view |
| crates/…/mod.rs | Defines the difference between local runtime logs and Cloud query errors |
| crates/…/doctor.rs | Defines read-only diagnosis for local runtimes, server URLs, and Cloud databases |
| crates/…/prompts.rs | Defines interactive selection and the rules that keep terminal and automation paths consistent |